How can get deg from Quaternion in Y axis?

I want to get 90 in deg from this model rotation but I cant and I do not know understand why??

 Spatial b1 = assetManager.loadModel("Models/b-1-" + tex + "/Cube.003.mesh.j3o");
 b1.setLocalTranslation(x_pos, y_pos, z_pos);
  b1.rotate(0, 90* FastMath.DEG_TO_RAD, 0);
 b1.scale(scale);
  b1.addControl(new building());
   b1.setUserData("name", "b_4_1");
  B.attachChild(b1);

and this must be 90 but is not:

float r = cb.getLocalRotation().getY() * FastMath.RAD_TO_DEG;

and how can I get y rotation in deg?

The components of a quaternion are not angles. You can convert a quaternion to Euler angles using the .toAngles() method and convert to degrees using FastMath.RAD_TO_DEG . I’m not sure that’s what you want, but it’s probably closer.

1 Like

I never had success myself using the “FastMath.DEG_TO_RAD” to rotate stuff, but Ive used “FastMath.pi” multiplied by fractions and it worked. Quaternions always confuse me, so anytime I need to do any rotating with them I have to look back to slide 33 in the Math for Dummies slide and I can usually figure out how to get the rotations I need https://jmonkeyengine.github.io/wiki/tutorials/math/assets/fallback/index.html

1 Like

To expand sgold’s answer,you could use:

    float angles[]=cube.getWorldRotation().toAngles(null);
    for(float angle:angles)
        System.out.println( angle*FastMath.RAD_TO_DEG );   

This shall post all three angles in degrees.

2 Likes

But note that just because you put an angle into a quaternion does not mean that you will get it back out again.

Euler angles are ambiguous. A single orienation can be represented by an infinite combination of euler angles.

A quaternion is a concise, compact, and disambiguous form of orientation.

2 Likes

Paul, you’re correct that Euler angles introduce ambiguity in the representation of 3-dimensional orientations. But so do quaternions.

In fact, there are an infinite number of quaternions that describe any particular orientation (or rotation) in 3-D: the orientation described by a quaternion Q is equivalent to that described by kQ for any scalar k. Even if you limit your representations to normalized (unit) quaternions, there’s still ambiguity because Q and -Q represent the same rotation. Quaternions offer many advantages over angles, but complete absence of ambiguity isn’t among them.

In yn97’s case, it appears that all the rotation is around the Y axis. If so, the quaternion represents a 2-D rotation, for which it’s relatively easy disambiguate the angle. Just remember that adding multiples of TWO_PI radians (or 360 degrees) results in an equivalent orientation.

If the rotation isn’t entirely around the Y axis, then it’s a tough problem. @yn97, before calculating the Y rotation angle for a rotation around some other axis, you’ll need to carefully define what you mean by that.

2 Likes

Not really. Other then the Q = -Q “ambiguity”, a Quaternion is a unique rotation. You will never find another Quaternion (other than -Q) that points a vector in that particular direction, for example. It’s similar to a normalized angle-axis in that respect.

Even in one plane you cannot expect to get your yaw back if you put it in. That particular orientation could have been reached by rotations in the other plane or some contribution of rotations in the other planes.

For example, a yaw rotation of 90 degrees can also be a pitch and roll rotation. (In fact, yaw > 90 or < -90 will often return quaternions just like that.)

So, if you put yaw into it and want to get that same yaw -180 to 180 out again… then you have to keep the yaw separately or do some more complicated math with the direction vector.

Edit: and frankly, if you need that sort of yaw for anything other than displaying to a user, 99% of the time there was a better way to do what you are doing using the quatenion/direction vectors themselves and bypassing angles completely.

1 Like

It is true that kQ=Q and -Q=Q,where k is a scalar and Q a quaternion.
For example Q(0.5,0,0,0.5) equals Q(1,0,0,1) which equals Q(-0.5,0,0,-0.5) which all equal Pitch 90.
That indeed makes an infinite number of quaternions representing the exact same rotation.

1 Like

All of those are unnormalized.

1 Like

norm(Q)=1 implies norm(-Q)=1

1 Like

Look, guys.

The point is that a Quaternion of unit length 1 is unique. (Other than its inverse which is a known property and does not change what I’m saying.)

http://javadoc.jmonkeyengine.org/com/jme3/math/Quaternion.html#normalizeLocal--

Euler angles are not unique. For example, yaw can be the same as pitch and a roll. You can’t do that with quaternions no matter how hard you try. Since the quaternion will be unique, you are not guaranteed to get the same euler angles out again… it has made them compact and disambiguous beyond just normalizing the angles.

I automatically assume when talking about rotations that we are talking about normalized quaternions… because you end up with issues with the unnormalized ones.

1 Like

It seems your ask for help might have been derailed a bit by a Euler Mathematics throw down.

Just curious if you got the answer you needed or do you still need some guidance?

If you still need some help I’d ask what you’re planning on using this for? To me it vaguely sounds like you might want to create a compass of some sorts. Is that correct?

2 Likes