• Advertisement

Archived

This topic is now archived and is closed to further replies.

Quaternion questions

This topic is 6040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How could I transform a direction vector to a quaternion? How could I get out the x/y/z rotation from a quaternion? How could I create a smooth interpolation between two quaternion? (slow at beginning, fastest at middle and slow at the end) Questions over questions... I hope someone could help me.

Share this post


Link to post
Share on other sites
Advertisement

> How could I transform a direction vector to a quaternion?

If you mean to a rotation quaternion you can''t. A direction vector does not specify a rotation. You need more information, such as where the vector is rotated from and how the rotation takes place.

> How could I get out the x/y/z rotation from a quaternion?

There''s standard code to extract Euler angles from a rotation quaternion, see Gamedev''s articles section.

> How could I create a smooth interpolation between two
> quaternion? (slow at beginning, fastest at middle and slow
> at the end)

Use slerp with a ''smoothing'' function. E.g. if your usual slerp function is

result = slerp (q0, q1, t)

with t ranging from 0 to 1, instead use

result = slerp (q0, q1, 0.5 - 0.5 * cos(s))

where s ranges from 0 to pi. The function

t = 0.5 - 0.5 * cos(s)

is an example of a function that smooths out the motion: look at the graph of cos to see why. There are a wide range of functions that do this, or only smooth the beginning or ending.

Share this post


Link to post
Share on other sites
Thanks for your answer!!

>> If you mean to a rotation quaternion you can''t. A direction vector does not specify a rotation. You need more information, such as where the vector is rotated from and how the rotation takes place.

- Do you have any code for doing this??

Share this post


Link to post
Share on other sites
> - Do you have any code for doing this??

No. The problem is you''re problem is not precise enough, you need more information. The code depends on what extra information you have. E.g. if you have the axis about which the rotation takes place you might find the angle you must turn through, giving you the angle-axis description of the rotation, which is then easy to convert to a quaternion. But it depends on what info you have.

Share this post


Link to post
Share on other sites
>>There''s standard code to extract Euler angles from a rotation
>>quaternion, see Gamedev''s articles section.

I''ve been looking for a way to do this for a long time, if you had a specific link to the article it would be great because I can''t find it

Oh yeah and for the direction vector maybe you could find the euler angles for it and convert that to a quaternion.

-David-

Share this post


Link to post
Share on other sites
>>There''s standard code to extract Euler angles from a rotation
>>quaternion, see Gamedev''s articles section.

> I''ve been looking for a way to do this for a long time, if you
> had a specific link to the article it would be great because I
> can''t find it

Sorry, the article I was thinking of (the Gamasutra one) dosen''t have quaternion -> Euler angle conversion. It has conversion the other way, and converting to and from matrices.

The reason is there''s no need for it: the only use for Euler angles is for inputting or initialising a rotation, inside game code both quaternions or matrices are easier, quicker and more accurate to use. I''ve not yet found a problem that requires Euler angles at any stage of a calculation.

Share this post


Link to post
Share on other sites
You will be able to retrieve euler from a quat if you can retrieve euler from a matrix.

However, retrieveing euler angles from matrix is not easy, if possible, as euler to matrix is a many-to-one relationship.

Share this post


Link to post
Share on other sites
I just wanted euler cause I can easily apply it to a vector, how do I apply a quaternion to a vector? I have a game with a spaceship that rotates around using quaternions but it can''t go forward because I can''t figure out what the rotated vector is. Any help would be great.
Thanks,
-David-

Share this post


Link to post
Share on other sites

  • Advertisement