# quaternion woes

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

## Recommended Posts

I have two quaternions, let's call them 'a' and 'b'. I need to see if the angle of the rotation of the y axis of the orthonormal basis corresponding to the quaternion rotation of quaternion a is less than or greater than the angle of the rotation of the y axis of the orthonormal basis corresponding to the quaternion rotation of quaternion b (The end result will look like 180 > 90 or 270 < 360)

Now by angle I mean the angle the axis has been rotated from it's foward vector (I.E. (0,0,1))

This is what I got so far trying to go from quaternion to angle:

//get the cameras rotation vector        	Vector3 loc = new Vector3(_canvas.getCanvasRenderer().getCamera().getLocation());        	//put it on the XZ plane        	loc.setY(0);        	//create a quateration from the camera location        	Quaternion cam = new Quaternion().fromVectorToVector(new Vector3(0,0,-1), loc);        	        	//create a quateration from joystick's angle        	Quaternion pad = new Quaternion().fromAngleAxis((float) Math.atan2(-padX,-padY), Vector3.UNIT_Y);        	        	//add the two rotations together        	pad.multiplyLocal(cam);        	//create new for the location of the pad        	Vector3 padVec = new Vector3();        	//apply the joystick's quaternion to the zx plane and save the result in padVec        	padVec = pad.apply(new Vector3(1,0,1), padVec);        	//make sure padVec is on the ZX plane        	padVec.setY(0);        	        	//print out the y rotation angle that is equal to atan2(padVec.getX(), padVec.getZ())        	System.out.println("angle: " + new Vector3(1,0,1).dot(padVec));

Thank you for taking the time to read this, and thank you for your help.

Edit: I am trying to figure out how to get the angle of the rotation of the y axis of the orthonormal basis corresponding to the quaternion rotation of quaternion a. I am sorry if I didn't make that clear before.

[Edited by - CyanPrime on December 28, 2010 1:03:00 PM]

##### Share on other sites
What problem are you trying to solve? I am not sure I understand what you are saying, but perhaps you are not asking the right question.

##### Share on other sites
Wait, I just found this other thread. It looks like the same question, and it was already pointed out to you that it didn't seem to make sense. Why did you start this thread instead of just posting a clarification on that one?

##### Share on other sites
Quote:
 Original post by alvaroWhat problem are you trying to solve? I am not sure I understand what you are saying, but perhaps you are not asking the right question.

Thank you for your reply, good sir. I am trying to figure out how to get the angle of the rotation of the y axis of the orthonormal basis corresponding to the quaternion rotation of quaternion a. I am sorry if I didn't make that clear before.

##### Share on other sites
My attempts to help in your previous thread on this topic didn't seem to be particularly well-received; nevertheless, I'll take another shot at it (maybe things will go better this time).

This:
Quote:
 Now by angle I mean the angle the axis has been rotated from it's foward vector (I.E. (0,0,1))
Is a little confusing to me. The axis you're asking about is the local y axis, so even if no rotation has occurred, the angle would still be 90 degrees, correct? (Because (0, 1, 0) and (0, 0, 1) are 90 degrees apart.) Is that what you're looking for - the angle between an arbitrary unit-length vector and the vector (0, 0, 1)?

I looked over your code, but I'm not sure if I understand its intent. IMHO, it'd probably be easier for us to help if you were to describe the problem you're trying to solve in high-level terms - that is, what is it you're really trying to do here? (Images would probably help too, if you have any.)

##### Share on other sites
can u be a bit more clear. i m not able to get it.

##### Share on other sites
Quote:
 Original post by CyanPrime[...] I am trying to figure out how to get the angle of the rotation of the y axis of the orthonormal basis corresponding to the quaternion rotation of quaternion a. I am sorry if I didn't make that clear before.

Well, start with the vector Ey=(0,1,0), apply the quaternion rotation to it in the usual way (something like rotated_Ey=a*Ey*conj(a)) and then compute the angle it forms with the original Ey, as acos(dot_product(Ey,rotated_Ey)).

This is all quite trivial if you understand how quaternions are used to represent rotations. So perhaps there are some gaps in your understanding. Feel free to ask more questions if that's the case.

##### Share on other sites
Quote:
Original post by jyk
My attempts to help in your previous thread on this topic didn't seem to be particularly well-received; nevertheless, I'll take another shot at it (maybe things will go better this time).

This:
Quote:
 Now by angle I mean the angle the axis has been rotated from it's foward vector (I.E. (0,0,1))
Is a little confusing to me. The axis you're asking about is the local y axis, so even if no rotation has occurred, the angle would still be 90 degrees, correct? (Because (0, 1, 0) and (0, 0, 1) are 90 degrees apart.) Is that what you're looking for - the angle between an arbitrary unit-length vector and the vector (0, 0, 1)?

I looked over your code, but I'm not sure if I understand its intent. IMHO, it'd probably be easier for us to help if you were to describe the problem you're trying to solve in high-level terms - that is, what is it you're really trying to do here? (Images would probably help too, if you have any.)

I am deeply sorry about that. I had some frustrations in life and I took them out on you, who was only trying to help. Thank you very very much for giving me another chance.

My understanding of quaternions is very limited, but
Quote:
 Is that what you're looking for - the angle between an arbitrary unit-length vector and the vector (0, 0, 1)?
I believe this is what I am looking for.

##### Share on other sites
Quote:
Original post by alvaro
Quote:
 Original post by CyanPrime[...] I am trying to figure out how to get the angle of the rotation of the y axis of the orthonormal basis corresponding to the quaternion rotation of quaternion a. I am sorry if I didn't make that clear before.

Well, start with the vector Ey=(0,1,0), apply the quaternion rotation to it in the usual way (something like rotated_Ey=a*Ey*conj(a)) and then compute the angle it forms with the original Ey, as acos(dot_product(Ey,rotated_Ey)).

This is all quite trivial if you understand how quaternions are used to represent rotations. So perhaps there are some gaps in your understanding. Feel free to ask more questions if that's the case.

Thank you very much for your reply. Thank you for being so kind. I will try this when I get home and tell you if it worked or not.

##### Share on other sites
Quote:
Original post by CyanPrime
Quote:
 Is that what you're looking for - the angle between an arbitrary unit-length vector and the vector (0, 0, 1)?
I believe this is what I am looking for.
Alrighty, let's start with that then. There's a couple of ways you can compute the angle between two vectors. Here's my preferred method (untested pseudocode):
float angle = atan2(length(cross(v1, v2)), dot(v1, v2));
This method has the advantage of being fairly robust and of working with vectors of arbitrary (but not zero or near-zero) length.

Another method (that works only for unit-length vectors) is:
float angle = acos(dot(v1, v2));
Note that it's best to clamp the input to acos() to the range [-1, 1] to correct for any numerical error.

For the special case you have in mind, you should be able to reduce this to:
float angle = acos(clamp(v.z, -1, 1));
[Edit: This partly duplicates what alvaro said above.]

##### Share on other sites
Yay! That worked! Thank you both very much for helping me! ^__^

##### Share on other sites

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