# Simple rotating question

Hey all,

I’m trying to do something pretty basic but can’t find how.
I have a Geometry g which I rotated using g.rotate(x,y,z), for example: g.rotate(1,0,0).
Now, in a different part of the code, I get that geometry, and want to know how “rotated” it is in the x,y and z axes. In the example above, I want to be able to determine g is rotated “1” at the x axis and "0 at y and z.
How do I do that?

Thanks!!!

Amir.

I think you are looking for

[java]spatial.getLocalRotation().toAngleAxis(vectorToStore);[/java]

1 Like

toAngleAxis() will give you an axis and a rotation but not around a specific axis. It will represent whatever axis+angle is the best representation of the quaternion at that time.

The real answer is that you cannot reliably do this. There are an infinite number of ways to form a specific Quaternion from three angles (Euler angles) because Euler angles are not as precise as Quaternions. So once you have a Quaternion, you are very likely not going to get three angles back from it that you recognize.

If you want to keep track of how much you have rotated then you need to keep track of that yourself… or re-examine why you want to do this and then do it a different way.

What do you need this value for? There may be a different way to solve the meta-problem.

1 Like

I’ve looked up the Quaternion concept and boy, that looks complicated for a computer science undergrad student like myself
In any event, my goal is pretty straight-forward: In the beginning of the program, I rotate a spatial to a certain rotation amount (2,0,0).
Whenever the user clicks the mouse, I want to rotate it backwards by -0.1 on the x axis. I want to rotate backwards no more, when it has reached 0.
Of course, I could keep track of the rotation I have made. However I was hoping to get the “absolute rotation”, on some level (just like I can get the dimensions of the mesh, or the LocalTranslation of the spatial), instead of having to store it myself.
For example, I am doing the exact same thing with moving the object around - I move it to move(2,0,0), then whenever the spacebar is pressed, I move it backwards. I can get the position by spatial.getLocalTranslation.getX().

I hope my question is a bit more clear…
If there’s an easy explanation for all that rotation and quaternion concepts I’d be happy to read (the API didn’t help much).

Amir,

Opt 1: Define a quaternion for your initial and target rotation. When they click slerp from initial to target by a set value. Store set value and modify it when the user clicks.
Opt 2: Store a quaternion for target rotation. Get the angle between current and target. If < some amount then they effectively the same.

I'm sure there are other options too, that was just a couple that sprang to mind.

1 Like

Option 3: keep your own angle and create the quaternion using fromAngles() whenever you need a new one.

But yeah, if you know what your target rotation should be then xarch’s options also work.

Rotation is different than translation. When you put an object at x,y,z there is only one way to represent that. An object in some orientation has an infinite number of angle sets that can be used to get there. For example, in degrees 0,180, 0 is the same as 90,0,180… and that’s only counting the angles that are clamped to +/- PI. Though for smaller angles it’s even easier to come up with multiple cases where three angles equals the same rotation.

1 Like