0

I'm currently working with files that I have no control over, which define 3D cubes with 5 vectors, one for the center position, one for the half-size, and 3 vectors that somehow make up the rotation. I'm struggling with figuring out how to turn these 3 vectors into 3 angles, that I can easily use in my rendering engine.

For example, I might have the following vectors:

Position
X: -655.48, Y: 477.02, Z: -3.30

Size
X: 435.57, Y: 29.79, Z: 138.53

Rotation
X: 0.91, Y: -0.41, Z: 0.00
X: 0.41, Y:  0.91, Z: 0.00
X: 0.00, Y:  0.00, Z: 1.00

With the position and the size (times two) I can easily create a cube, but the rotation is missing. Since I know what the box is supposed to look like, I know that the rotation angles of the cube are supposed to be 0°, 0°, and about -24°, 156°, or 336°, depending on how you rotate it. Unfortunately, I don't know how to turn one into the other.

Figuring out what to even search for to solve this has been challenging, since I don't know what exactly I'm look at. I assume that I have to take these values in some combination and calculate the angles for each axis, possibly using atan2? But I'm out of my depth here.

For another example, here's a cube that doesn't rotate.

X: 1.00, Y: 0.00, Z: 0.00
X: 0.00, Y: 1.00, Z: 0.00
X: 0.00, Y: 0.00, Z: 1.00

I'd appreciate any help in deciphering this.

Update: I realize my explanation about the expected angles was poorly formulated, so here's a quick addendum.

By angles, I mean 3 angles in degree, for rotations around X, Y, and Z. I'm currently testing this in the Unity engine, where I can easily create a box with a given size around a center point, and my specific example was about one such box, that would require the angles X: 0°, Y: 0°, and Z: -24°, for it to appear as I know that it should appear. These values came from me trying to simply put the cube into the rotation I need.

What these rotation values actually represent, by my current understanding, are directions on all 3 axis, which describe the directions the 8 edge points of the cube are in. You could technically create something that isn't a cube, because this format allows for slanted sides, but it's never used that way in the files I'm working with.

Mars
  • 912
  • 1
  • 10
  • 21
  • What do your angles mean? There are a dozen ways to represent the orientation of a 3D object with three angles. – Beta Jul 25 '21 at 15:05
  • @Beta You're right, that was poorly explained. I mean 3 angles in degree, for rotations around X, Y, and Z. I'm currently testing this in the Unity engine, where I can easily create a box with a given size around a center point, and my specific example was about one such box, that would require the angles X: 0°, Y: 0°, and Z: -24°, for it to appear as I know that it should appear. – Mars Jul 26 '21 at 08:16
  • 1
    my bet is: the 3 vectors are basis vectors for 3D rotation matrix and you want convert them to Euler angles ... Take a look at [Is there a way to calculate 3D rotation on X and Y axis from a 4x4 matrix](https://stackoverflow.com/a/56950130/2521214) ... so just construct 4x4 matrix using the 3 vectors and position and use the conversion from the linked answer ... – Spektre Aug 02 '21 at 08:07
  • Interesting. I'll look into that, thanks. – Mars Aug 02 '21 at 14:15

0 Answers0