# Translating Objects in Worldspace

Given the worldspace coordinates of a collection of arbitrarily positioned objects, how do I translate them while preserving their relative placement? For instance, I have a table and a few bowls that are placed on top of it at (x1, y1, z1) and wish to moved them to (x2, y2, z2).

One popular method is to use parent-children hierarchies to store matrix transformations in relative space. If you are moving the table and everything along with it, the bowls are the children of the table as far as their location is concerned. This can be done as simply as storing and pushing matrices in an array, and multiplying them. This could also be a simple use of a scene graph (note that scene graphs are not strictly defined as a spatial hierarchy though, as they can be used for many purposes).

PushMatrix() and PopMatrix() are examples in OpenGL for stack local transformations. However, these operations are expensive if you frequently look up their world position this way. It's a better to store an extra matrix for each object for its absolute position in space. You access this matrix when the object in question is not being moved at the moment, to save performance. Multiplication of local matrices then would happen only when the object is moved, and then its world (absolute location) matrix will be updated.

This problem is called Inverse Kinematics. In Inverse Kinematics, you begin with some "desired" translation and rotation for the endpoint in a kinematic chain. The goal is to determine where all the other objects in the kinematic chain are (their rotations and translations), and joint angles (if you have any joints).

In your case, you are putting in the rotation/translation of the final object in the chain (the bowl), and asking for the required rotation/translation of the first object in the chain (the table). Unfortunately, there is no general solution to your problem, since there are an infinite number of ways to place the bowl at (x2, y2, z2) while preserving the relative transform between the bowl and the table. (because you can rotate the objects arbitrarily and preserve the local transformation).

However, all you need to do to get a single solution is to invert the transformation between the table and the bowls. For this, I am going to assume you already know about transformation matrices.

Call the relative transform matrix between the table and the bowls H_tablebowl. Call the transform from the world to the table H_table. The global transform H_bowl = H_table * H_tablebowl. Now, what you're asking is, suppose we fix H_bowl to some value H_desired. How then do we find the resulting H_table? We know:

H_desired = H_table * H_tablebowl


And therefore

H_table = H_desired * inverse(H_tablebowl)


If you have just the translation of the bowl, then you can arbitrarily fix the orientation to some value (like the identity). Then the solution simply becomes:

translation_table = translation_bowl_desired - translation_table_bowl