Search code examples
.netcomputer-sciencecoordinatescoordinate-transformation

Transform coordinates into another coordinate system


So I have four coordinates of corners of a rectangle (blue) in a 3D coordinate system (red). I want to create some matrix to convert any given point on the rectangle in the red coordinate system into a (2D) point in the green coordinate system.

illustration

I guess this resembles a transformation from a camera in a 3D model to the screen, but I don't have coordinates and vectors of the camera. Are there articles or ideas you can recommend on this or do you even have a matrix/algorithm to share?


Solution

  • When making transitions from one coordinate system to other the principal action is to align those systems. Here what you need is to:

    • Translate the lower left corner point of the blue rectangle ( origin of the 2D coordinate system) to the origin of the 3D coordinate system (T)
    • Align the x axis of the two systems with a rotation (R1)
    • Align the other axis (y -axis) with another rotation. (R2)

    In linear algebra transformations are applied in reverse order, hence given point p in 3D space, you get the result by:

    R2 * R1 * T * p
    

    Wikipedia articles about Translation Matrix and Rotation Matrix are good resources about how to compute these matrices.

    As a final reminder, you need to use homogenous form of the coordinate, i.e.; p(x,y,z,1)