# Converting to 'local space'?

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

## Recommended Posts

I'm having some difficulty with a certain concept. I'm ultimately trying to convert the trajectory of a rotating, translating polygon in 2D into another's local space, as I've heard it referred to - so that I can treat one of the polygons as totally static. Think about it - we treat the ground/earth as "static", because for our intents and purposes, it can be - but in reality it's rotating and revolving around the sun. Without rotation, this is easy - the relative velocity of polygon A to B is the difference between the two original velocities. But if we make polygon B rotating, then it gets a bit more complex. Theoretically, if I treat polygon B as static, then I treat everything else as orbiting around its original axis of rotation, but in the opposite direction. The world is spinning, not the polygon. So, now polygon A's linear trajectory becomes curved. The question is, mathematically, how do I define that curve? Any help is appreciated. Peace and love, dgmul

##### Share on other sites
Assuming you have a 4x4 matrix defining the current location and orientation of object A.
You have some other object B and it's 4x4 matrix defining it's current location/orientation.

BlocalToA = (inverse of matrix A) times (matrix B)

Now, if you have something more complex as an actual formula for the position of B, the concept is still the same. You just have to express all the values in matrix B as functions of time, and the same (this time longhand) multiplication of the matrices gives you the new path B would take if A were the origin. (or you can express all values in A in terms of time, or in both A and B)

##### Share on other sites
As you already wrote, a motion is always described by referring to a (reference) co-ordinate system. A co-ordinate system itself has a frame what means a construct that describes the frame also w.r.t. a(nother) co-ordinate system. Now, as long as you can find a common reference system, you can convert from the one to the other.

Although it can be expressed in a more general way, I will use matrix math in the following because it is (a) usual in CG and (b) sufficient for the asked transformations.

In your example the possible transformations are translation and rotation. Hence a co-ordinate frame has an orientation and a position. Both can be expressed by a single matrix:
M10
This matrix means "to transform an entity given in the local system 1 to the global system 0, we have to multiply the entity by the matrix." E.g. a single point in local space (say a vertex position, or in your case a time variant position) will be transformed into the global space by
p0 := M10 * p1
(if using column vectors).

When inverting the above formula, you get the transformation vice-versa
p1 := M10-1 * p0
so that the backward transformation (i.e. from the global system to the local one) is the inverse of the original:
M01 := M10-1

Now, if you have 2 local systems (1 and 2) both with a common reference frame (0)
M10
M20
you can convert from local system 1 over the reference system into the local system 2 by concatenating the both particular transformations, what (since using matrices) means to multiply them:
M12 := M02 * M10 = M20-1 * M10

EDIT: The disadvantage of long explanations are that someone else will be faster :)

##### Share on other sites
Thank you very much for your elucidation, haegarr and KulSeran. :)

I still have a couple questions, though - this is the first time I've encountered situation requiring me to use matrices. I believe I know the basics of matrix math (multiplication, inversion, etc.), but as to how to use them in code I'm a bit lost. In an object-oriented language would I define a "matrix" object, and use that?

Also I'm not sure how I would define a transformation matrix.

##### Share on other sites
How you define the matrix depends on a few factors. Once you know where you are going to use it you can decide how you want to make your matrix math library (or search the boards for one of the many posts about it)
DirectX has its own matrix class
ODE/PhsyX/Havok as far as I know all have their own matrix classes
OpenGL takes a matrix that is memory-layout the same as directX but treats the matrix slightly different.

##### Share on other sites
You may look e.g. at Euclidean Space for this topic.

As KulSeran already has stated, you must be aware of "transposed matrices." The matrix product requires that the left matrix has exactly as much columns as the right matrix has rows. Hence, if you have a matrix and a vector, you can multiply it either
M * v
where the vector is at the right of the matrix, and hence is required to be a "column" vector (as used by OpenGL), or else
v * M
where the vector is at the left of the matrix, and hence is required to be a "row" vector (as used by D3D). Now, to be exact, in the above examples the both Ms and vs are not the same, but they are related by the so-called transpose operator:
M * v == ( v * M )t == vt * Mt
This operator does nothing else than to re-order the elements to fulfil the requirement.

Most often, this relation is taken for granted, and hence is ideal to confuse people when reading different sources. So be prepared.

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×