Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Quaternion confusion

Started by Hedanito Sep 15, 2010 at 6:26 PM 6 replies 1.5k views
Original Post
Hedanito
Hedanito
I want to turn a normal vector into a quaternion so I can create an orientation matrix for a hemisphere to send rays through. So the angle around the vector doesn't matter. Now when looking around the interwebs it always tells me that the formula for going from an angle-axis to a quaternion is: w=cos(a/2) x=sin(a/2)*x y=sin(a/2)*y z=sin(a/2)*z. But when I enter an angle of zero I get a identity quaternion since sin(0)==0, and therefore any data from the axis just disappears. Sooooo how do I properly go from angle-axis to quaternion? Or at least from just a normal vector, since I really don't care about the angle. Or of course any other/better ways to get to an orientation matrix.
no such user
no such user
The formula for angle-axis to quaternion is for a rotation of alpha radians around the axis supplied, so a rotation of 0 degrees around any axis would produce the identity. It sounds like what you want is a rotation from some arbitrary position so that a vector in that starting position becomes aligned with your desired vector. In that case the axis you want is the normalized cross product of your starting vector and your end vector.
Hedanito
Hedanito
No you completely misread it. I stated several times that I just want to turn a normal vector into a rotation matrix. Also, why would a rotation of zero around a vector always give an identity quaternion? It's completely different when I for example have a vector along the x-axis with a rotation of zero to a vector along the z axis with a rotation of zero. The y axis of the rotation matrix should point in that same direction. But since it turn into an identity quaternion all that data just disappears.
alvaro
alvaro
Quote:
Original post by Hedanito
No you completely misread it. I stated several times that I just want to turn a normal vector into a rotation matrix. Also, why would a rotation of zero around a vector always give an identity quaternion? It's completely different when I for example have a vector along the x-axis with a rotation of zero to a vector along the z axis with a rotation of zero. The y axis of the rotation matrix should point in that same direction. But since it turn into an identity quaternion all that data just disappears.


Let me remind you that you are the one that is confused about quaternions here. If he didn't understand what you said it's not because he misread it: It's because it doesn't make sense.

You seem to think that zero-angle rotations around two different vectors are somehow different rotations, and this is just not true. They are the same rotation (the identity) and it makes sense to represent it with the same quaternion, namely 1.

If you need further explanation, you are going to have to ask nicely.
Zakwayda
Zakwayda
Quote:
Original post by Hedanito
No you completely misread it. I stated several times that I just want to turn a normal vector into a rotation matrix.
No, 'no such user' got it exactly right.
Quote:
Also, why would a rotation of zero around a vector always give an identity quaternion? It's completely different when I for example have a vector along the x-axis with a rotation of zero to a vector along the z axis with a rotation of zero. The y axis of the rotation matrix should point in that same direction. But since it turn into an identity quaternion all that data just disappears.
You are wrong about the above, and this is what's hanging you up. This is a basic (and common) misconception about axis-angle rotations. I've provided more or less this same explanation in previous posts, but here it is again:

The first thing you need to realize is that the direction of the axis of rotation does not in any direct way correspond to the direction the object is pointing. If the axis of rotation is (0, 1, 0), that doesn't mean the object is 'pointing' along the Y axis.

Here's how an axis-angle rotation works. Imagine a ball floating in space, and imagine you have a thin rod that you can pass directly through the center of the ball from any direction. Once the rod has been passed through the ball, the ball is constrained to rotate about the rod.

An axis-angle rotation consists of two steps (conceptually speaking, and using our 'ball' example):

1. Pass the rod through the center of the ball.

2. Rotate the ball around the rod.

The interesting part is that the first step does not affect the ball in any way. It is only step two that changes the orientation of the ball. If the angle of rotation is zero (which means you effectively skip step two), then the direction of the rod does not matter. That is, any axis paired with an angle of zero will give you no rotation, i.e. identity. So in fact, converting an axis-angle pair to a quaternion works exactly as it should; no data is lost, and no data 'disappears'.

The particular problem you're trying to solve is basically a 'billboarding' problem, and searching for that term will probably turn up some good references. There's actually several different ways to generate an orientation from a single direction vector. Since the mapping from direction vector to orientation is not unique, these methods generally apply some sort of additional constraint so that an orientation can be uniquely determined.

I don't know enough about the context to say which method would be most appropriate for the problem you're trying to solve, but for creating a coordinate system corresponding to a direction vector on a 'one-time' basis, I usually recommend the 'cross with cardinal basis vector corresponding to the element of least magnitude' approach, which I've described in a number of previous threads.
Hedanito
Hedanito
That was very informative, thank you.
Books should really explain angle-axis better.
At least I now know what to look for, it indeed is very similar to the billboarding problem, so I'm sure I can find a solution somewhere.

Quote:
Let me remind you that you are the one that is confused about quaternions here. If he didn't understand what you said it's not because he misread it: It's because it doesn't make sense.


That doesn't even make sense. Just because I don't know much about quaternions doesn't mean I don't know what the problem is I am trying to solve. The person after you actually understood and explained it properly. The person before you however misunderstood and started talking about start and end positions which I don't even have. So I responded that he misread it. And then you come here all pissed for some reason with an explanation that is as useful as saying 1==1. Yes, it's certainly true, but that does not explain to me why it is that way. So if you don't feel like helping someone, just don't respond. There are people who are willing to help, and more importantly, are able to do so.
alvaro
alvaro
Boy, I have to work on my tone. I seem to be perceived as angrier than I am. Anyway, I am glad jyk figured out what your misconception was.
Zakwayda
Zakwayda
Quote:
The person after you actually understood and explained it properly. The person before you however misunderstood and started talking about start and end positions which I don't even have. So I responded that he misread it.
I'm glad you've got a start on getting things sorted. To be fair though, neither no such user's nor alvaro's replies were off base. The only thing I might call into question regarding no such user's post is the use of the term 'position'; I think he was using the term in the general sense, but I can see how it might cause confusion. Other than that though, everything in his post is correct; really, all I did was elaborate on what he said in the first sentence.

But anyway, it sounds like you've got a good start on finding a solution to the problem, which is the important thing :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.