Search code examples
3drotationpositionmatrix-transform

Using a matrix to position objects in 3D space


When using a 3D matrix transformation, is it possible to use only a matrix for each object to both position, rotate and scale the object? Would I also need to maintain a separate set of location information in order to, for example, perform operations like "rotate around arbitrary point"?

I ask because I can't quite work out how to (specifically...) rotate around an arbitrary point, though this relates to general management of an object's spacial information.


Solution

  • You would need a 4x4 matrix. A 3x3 matrix in 3D space only describes linear transformations, which do not include positioning (translation).

    See here for more details on implementation: http://www.euclideanspace.com/maths/geometry/affine/matrix4x4/. Plenty more on Google.

    E.g. for rotation around an arbitrary point P, construct the following matrices:

    • A: translation by minus P
    • B: your rotation (Euler angles or whatever)
    • C: translation by plus P

    The final matrix you want is CBA (in that order, assuming right-multiplication with vectors)