0
\$\begingroup\$

Right so I made a quaternion and assigned it a value but it reports back the wrong value.

Here is the relevant code...

Quaternion LeftTurnLimit = Quaternion.identity;
float test = 0.1f;

LeftTurnLimit = Quaternion.Euler(test, 0, 0);
Debug.Log(LeftTurnLimit);

Expected result: (0.1, 0, 0) / (x, y, z) Result: (0.0, 0.0, 0.0, 1.0) / (x, y, z, w)

So what am I doing wrong here?

\$\endgroup\$
2
  • 2
    \$\begingroup\$ (1) Your expected value is incorrect; and (2) you are not displaying enough decimals in your actual result, as you will need to show 4 (probably) to get sufficient precision for this test. Repeat three times: "Quaternions are NOT vectors.". Then repeat three more times "Degrees are 57 times smaller than radians." \$\endgroup\$ Apr 23 '16 at 5:10
  • \$\begingroup\$ @PieterGeerkens Perhaps I was asking for the wrong thing then. I think the majority of quaternion related problems stem from mistakenly conflating vectors with quaternions. \$\endgroup\$
    – Sie
    Apr 23 '16 at 5:20
3
\$\begingroup\$

Rounding.

If you attach the debugger and look at the values of your quaternion:

enter image description here

You'll see that the values are just too small to be displayed with one tenth precision, as the debug value is displayed.

You can confirm this by looking at:

Debug.Log(LeftTurnLimit.eulerAngles);

This will output the initial value you put in : 0.1, 0, 0

To address the differences in what you expected, vs what you got out.

Quaternions and euler angles are different, but with a similar goal. They're different ways of representing rotations in 3D space. They may have some commonly named components, but they store different information, because the process for converting the data stored into a rotation are different. If you want specifics about how each of them work, you should research the one you're interested in. You can ask specifically about anything you don't understand in a new question, after researching.

\$\endgroup\$
3
  • \$\begingroup\$ This is not a rounding error, you cannot directly compare quaternions to euler angles. They are two different things. \$\endgroup\$ Apr 23 '16 at 8:56
  • \$\begingroup\$ @S.TarıkÇetin I'm aware they're different things. Since OP gave expected answer in x,y,z, I thought they understood as well, it's been revealed since then that's not the case. \$\endgroup\$
    – House
    Apr 23 '16 at 16:28
  • \$\begingroup\$ @Byte56 What exactly is the difference? If you could include it in the answer I think the question would be more complete. \$\endgroup\$
    – Sie
    Apr 23 '16 at 16:40
0
\$\begingroup\$

Quaternions are different than Euler angles; Euler angles has 3 components (x, y, z) while Quaternions has 4 (x, y, z, w). If you want your result in Euler angles, use following code piece:

Quaternion LeftTurnLimit = Quaternion.identity;
float test = 0.1f;

LeftTurnLimit = Quaternion.Euler(test, 0, 0);
var LeftTurnLimitEuler = LeftTurnLimit.eulerAngles;
Debug.Log(LeftTurnLimitEuler);

Here is the related API page: http://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .