Advertisement

Quaternion offset

Started by May 22, 2012 08:11 AM
0 comments, last by clb 12 years, 9 months ago
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)]Hi,[/background][/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)]So I have a person (A) who's rotation is given with a quaternion (his location is given too). Now I want to figure out the location of a second person (B) that's standing in a certain position in relation to A. Like this: [/background][/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)](^ means a person that's looking in that direction)[/background][/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)]---^---[/background][/font]
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)]-----^-[/background][/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)]So the second person is standing behind the other person at a given angle (alpha) at a given distance (x). What I want to find is the location of person B. I can't for the life of me figure out how to calculate this with quaternions (or what keywords to google for ^.^), even though I realise it's relatively simple o.O. [/background][/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

[background=rgb(250, 250, 250)]Thanks![/background][/font]

You're saying you know the world transform A of the object a, and then the polar coordinates (aimed angle = alpha, distance = d) of the object b relative to a, and you want to compute the world position of b.

I assume this is 3D since you are talking about quaternions. In that context, just a single angle+distance value pair does not uniquely define the position of the object b relative to a. To fix this, I am going to assume that the object b lies in the cardinal X-Y plane in the coordinate space of object a, which will then allow using (aimed angle, distance) representation.

In that case, the world position of b is computed by the following steps:
1) Transform polar coordinates to euclidean coordinates: b's position (in a's local space) is (cos(alpha)*d, sin(alpha)*d, 0). (assuming X-Y plane)
2) To arrive to the final result, transform the position from a's local space to world space: A * (cos(alpha)*d, sin(alpha)*d, 0).

There 'A' is either a matrix that represents the transform, or if you're using quaternions, then it's the application of the quaternion on the vector, followed by translation by a's position. I.e. The world position of b = q_a * (cos(alpha)*d, sin(alpha)*d, 0) + p_a, where q_a is the orientation quaternion of a, 'quaternion * vector' refers to rotating the vector using the quaternion and p_a is the world position of a.

This topic is closed to new replies.

Advertisement