# How to convert relative position of child to parent into an absolute position?

I am modifying a game that stores object positions with a 3d vector { x, y, z } and rotation as a 3d vector with degree angles { x, y, z }.

I want to place an object in relation to a parent object accounting for its rotation. I do not have access to the game code, so I have to provide a position of the child as an absolute position.

For example, I would like to place a child object at a relative position { 50, 0, 100 }: 50 units along the x axis and 100 units up the z axis from the parent's position.

Assuming the parent object is currently at position { 0, 0, 0 } with rotation { 0, 0, 0 } the resulting absolute position for the child object would be simply { 50, 0, 100 }.

But, if the parent has a position of { 0, 0, 0 } and a rotation of { 0, 0, 90° }, the child's absolute position would be { 0, 50, 100 }.

What would be the transformation function that, given the absolute parent position, parent rotation, and relative child position, outputs the absolute position of the child (taking into account all three axes of rotation)?

## 1 Answer

First, construct a quaternion or rotation matrix from the parent's rotation angles.

Multiply your local position offset vector by this matrix or quaternion to get the offset in world space.

Lastly, add the parent position to get the child's absolute position in world space. (You can fold this into the previous step if you use a 4x4 homogeneous matrix with both rotation and translation combined)