# from world space to object space with quaternions

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

## Recommended Posts

I have to objects with position(x,y,z) and orientation(a quaternion)and now i want to get the position of object 2 in objectspace of object 1. Some time ago i already made it with matrices, but i don't know what to do with quaternions. Berion

##### Share on other sites
why don't you stick with a matrix?

##### Share on other sites
The location of a point local to object 1 in world space is: P = T1Q1P1Q1-1. Thus, P1 = Q1-1T1-1PQ1
Since the location of a point local to object 2 in world space is: P = T2Q2P2Q2-1, the location of a point local to object 2 in object 1's space is: P1 = Q1-1T1-1T2Q2P2Q2-1Q1.

The multiplications above are a mix of matrix and quaternion multiplications. I'll leave it to you to sort it out. Also, I might have Q-1 and Q reversed, I can never remember.

##### Share on other sites
Quote:
 Original post by JohnBoltonThe location of a point local to object 1 in world space is: P = T1Q1P1Q1-1. Thus, P1 = Q1-1T1-1PQ1Since the location of a point local to object 2 in world space is: P = T2Q2P2Q2-1, the location of a point local to object 2 in object 1's space is: P1 = Q1-1T1-1T2Q2P2Q2-1Q1.I might have Q-1 and Q reversed, I can never remember.

wow.... you're being serious aren't you?

##### Share on other sites
Quote:
Original post by Alpha_ProgDes
Quote:
 Original post by JohnBoltonThe location of a point local to object 1 in world space is: P = T1Q1P1Q1-1. Thus, P1 = Q1-1T1-1PQ1Since the location of a point local to object 2 in world space is: P = T2Q2P2Q2-1, the location of a point local to object 2 in object 1's space is: P1 = Q1-1T1-1T2Q2P2Q2-1Q1.I might have Q-1 and Q reversed, I can never remember.

wow.... you're being serious aren't you?

Come on. The math might look complicated but it is trivial.

##### Share on other sites
Well if you are like me, you will try to simplify the process.
This is what I would do:
A point common to both bodies can be expressed as:

p = pl1 * R1 + T1
p = Pl2 * R2 + T2

Since it is the same point

pl1 * R1 + T1 = Pl2 * R2 + T2

now determine pl1 you get:

pl1 = (Pl2 * R2 + T2 – T1) * R1’

let T2 – T2 = T

pl1 = Pl2 * R2 * R1’ + T * R1’

Now in quaternion form

Q = Q2 * Q1’ (the product of quaternion Q2 and the conjugate of Q1)
T = (T2 – T1) * Q1’ (the product of the different of offset time the conjugate of Q1)

##### Share on other sites
thanks for the help, but i found out that my quaternion code worked. I didn't changed anything and it suddenly worked. The error was somewhere else, but I don't know where.

1. 1
2. 2
3. 3
4. 4
Rutin
21
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632936
• Total Posts
3009312
• ### Who's Online (See full list)

There are no registered users currently online

×