Using transform matrices, how do you convert a point from one object's local frame into another's when both are placed in world space?
answer
- a matrix's columns are a frame
- go through world space
- inverse undoes the destination frame
- dot products for a rigid frame
basics
~10 sGo through world space: multiply by the source frame's local-to-world matrix, then by the inverse of the destination frame's local-to-world matrix. With column vectors that is p_B = inverse(M_B) * M_A * p_A.
solid answer
~50 sWith column vectors, a local-to-world matrix is a frame written down: its first three columns are the frame's axes in world space and its last column is the frame's origin. So `M_A * p_A` builds the world point as `origin + x*axisX + y*axisY + z*axisZ`, and `inverse(M_B)` takes a world point into B's coordinates. Together, `p_B = inverse(M_B) * M_A * p_A`; precompute that product once if many points make the trip. When B is rigid (unit, perpendicular axes), its inverse needs no general inversion: each local coordinate is a dot product, `dot(w - o_B, axis)`. Directions make the same trip with `w = 0`, so the origin is never subtracted. The same idea re-expresses a whole transform: an operation `X` written in A's coordinates acts in world space as `M_A * X * inverse(M_A)`.
go deeper
Recall that a local-to-world matrix holds the frame's axes and origin, and that going the other way uses its inverse.
Explain going through world space, the dot-product shortcut for a rigid frame, and why directions skip the origin.
Handle scaled and sheared frames correctly, precompute frame-to-frame matrices for bulk work, and re-express an operation with M * X * inverse(M).
Decide which spaces systems exchange data in, so most conversions happen once at a boundary rather than per point inside hot loops.
## A matrix is a frame A **frame** (or coordinate system) is an origin plus three axis vectors. A **change of basis** re-expresses the same point, or the same operation, using a different frame's numbers. Under the **column-vector convention** (`p' = M * p`), an object's **local-to-world matrix** is that frame written down: ``` | Xx Yx Zx Ox | | Xy Yy Zy Oy | X, Y, Z = the frame's axes in world space | Xz Yz Zz Oz | O = the frame's origin in world space | 0 0 0 1 | ``` Multiplying by a local point `(x, y, z, 1)` gives `O + x*X + y*Y + z*Z`: start at the origin and walk `x` units along the first axis, `y` along the second, `z` along the third. If the object is scaled, each axis column's length equals that axis's scale factor. ## From local to world and back - **Local to world:** `p_world = M_A * p_A`. - **World to local:** `p_A = inverse(M_A) * p_world`. For a **rigid frame** — unit-length, mutually perpendicular axes — the inverse is cheap: each local coordinate is how far the point lies along that axis, measured from the origin. ``` p_A.x = dot(w - O, X) p_A.y = dot(w - O, Y) p_A.z = dot(w - O, Z) ``` If the axes are perpendicular but scaled by `s`, divide each dot product by that axis's squared length: `dot(w - O, X) / dot(X, X)`. If they are not even perpendicular (shear), use a general inverse. ## Between two frames To move a point from frame A to frame B, go through world space: ``` p_B = inverse(M_B) * M_A * p_A ``` Worked example. A planet sits at the world origin, turned 90 degrees about the vertical axis: its local x axis points along world `(0, 0, -1)`, its y axis along `(0, 1, 0)`, its z axis along `(1, 0, 0)`. A moon sits at `(10, 0, 0)` with its axes aligned to the world. A landing beacon is at `(1, 0, 0)` in the moon's frame, and a planet-relative tracking system wants it in the planet's frame. 1. Moon frame to world: `(10, 0, 0) + 1 * (1, 0, 0) = (11, 0, 0)`. 2. World to planet frame, by dot products with the planet's axes (its origin is zero): x = `dot((11,0,0), (0,0,-1)) = 0`, y = `0`, z = `dot((11,0,0), (1,0,0)) = 11`. 3. Result: `(0, 0, 11)` in the planet's frame. 4. Check: `0*X + 0*Y + 11*Z = 11 * (1, 0, 0) = (11, 0, 0)`, the same world point. ## Points versus directions | what moves between frames | w | origin used? | |---|---|---| | a position (the beacon) | 1 | yes: subtract the destination origin | | a direction (the beacon's facing) | 0 | no: only the axes matter | | a surface normal | 0 | no, and it needs the inverse-transpose if scale is non-uniform | ## Re-expressing a whole transform Sometimes the thing to convert is an operation, not a point. If `X` is a transform written in frame A's coordinates — "turn 30 degrees about A's own up axis" — then in world coordinates it is: ``` X_world = M_A * X * inverse(M_A) ``` Read right to left: take a world point into A's frame, apply `X` there, bring the result back out. For a rigid `M_A`, this is a rotation about A's up axis through A's origin. Rotating about a pivot `p` is the special case where A is a frame that is just a translation to `p`: `T(p) * R * T(-p)`. The matrices `X` and `M_A * X * inverse(M_A)` are called **similar**; they describe the same action seen from two frames. ## Pitfalls - Multiplying by `M_A` again instead of its inverse to go back to local space. - With column vectors, reading the axes out of the rows; rows hold the axes only under the row-vector convention. - Using the transpose as the inverse when the frame is scaled. - Subtracting the origin from a direction. - Recomputing `inverse(M_B) * M_A` for every point when it could be built once.
- Why can you use dot products instead of a general inverse for a rigid frame?A rigid frame's axes are unit length and mutually perpendicular, so its 3x3 part is orthonormal and its inverse is its transpose. Each row of the transpose is one axis, and multiplying by a row is a dot product. Subtracting the origin first undoes the translation.
- Frame A's axes are perpendicular but scaled by 3 along x. How do you get a world point's local x coordinate?Divide the dot product by the axis's squared length: dot(w - O, X) / dot(X, X). One local unit spans 3 world units, and the unnormalised axis X multiplies the projection by its length 3 again, so the dot product is 9 times the local coordinate.
- When would you precompute inverse(M_B) * M_A instead of transforming each point twice?Whenever many points or directions make the same trip in one frame, such as every vertex of a mesh attached to one object being tested against another object's local volume. One 4x4 product up front replaces a second matrix-vector multiply per point.
A street address and a satellite position name the same doorstep. To give directions relative to a second town, you first find the doorstep on the shared map and then describe it from that town's square.
- To go from world back to local space, multiply by the same matrix again
- With column vectors, the rows of a local-to-world matrix are the frame's axes
- Directions need the destination origin subtracted, just like points
- The transpose inverts any local-to-world matrix, scaled or not
- A point's local coordinates are just its world coordinates minus the origin