Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Well I want to determine the position in front of, lets say 'an object'.

'An objects' has a position (pX,pY,pZ) and a quaternion rotation (qX,qY,qZ,qW) (where qW seems always to be 0 - because this is from a game I want to modify, I never saw it become 1)

Now I would like to determine the position at n units in front of the position of the object according to the quaternion rotation. How would I do that?

Extra Info:

I know the quaternion combinations produce (when starting to transform from (1,0,0,0) if that matters):

(1,0,0,0) left side facing north

(-1,0,0,0) right side facing north

(0,-1,0,0) back facing north

(0,1,0,0) front facing north

(0,0,1,0) front facing the sky

(0,0,-1,0) front facing the ground

share|cite|improve this question
You need to be a bit more clear with your question. Are each of the $X,Y,Z$ the same? What does "in front" mean? Are you determining this after the rotation? – muzzlator Feb 25 '13 at 11:54
if you mean position and quaternon, no, I edited the question to use "pX" and "qX". and as for the front, I know the quaternion combination (1,0,0,0) makes the object face it's front to the north and roof to the sky (up); (-1,0,0,0) makes the back face the north, while the object is still upwards. – user51593 Feb 25 '13 at 13:30
sorry I mistaked the rotations, edited them accordingly in the question – user51593 Feb 25 '13 at 13:43
up vote 1 down vote accepted

You can convert the quaternion into a rotation matrix, using the formula on this page.

The rows of this matrix are the vectors to which the original coordinate axes are transformed by the rotation.

So, let's suppose your "object" is a rocket, and, in its original position, its nose points along the $z$-axis. Then, after transformation by the quaternion $(w,x,y,z)$, the formula on the wikipedia page tells us that its nose points in the direction of the vector $v = (2xz -2yw, 2yz+2xw, 1 - 2x^2 - 2y^2)$. Then, a position $n$ units in front of the rocket is $p + n*v$, where $p = (pX, pY, pZ)$.

The GeometricTools site has good code for working with quaternions and rotations. Documentation is here, and code is here.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.