Search code examples
geometryalgebra

How do I convert a coordinate in one 3d Cartesian coordinate system to another 3d Cartesian coordinate system


I start with one coordinate system and a point along the Z axis given by P1 = [0 0 h] and a point in the XY plane given by P2 = [h*tan(A), h*tan(B), 0] I then solve for the equation of a plane perpendicular to a vector which points from P2 to P1 so, Vector = P1 - P2. The Plane equation I get is the following:

X*h*tan(A)-Y*h*tan(B)+Z*h = 0.

Now I am given four points relative to this plane, from which the origin of this new plane is the same as P2 in the original plane.

The four points make a rectangle and are:

[L*tan(C), L*tan(D), 0]
[L*tan(C), -L*tan(D), 0]
[-L*tan(C), -L*tan(D), 0]
[-L*tan(C), L*tan(D), 0]

How exactly would I go about converting these points into the original coordinate system? I know that there's a translation and a rotation involved, and when I goggled my problem I could only find cases of translation and rotation separate, and none which were a combination of the two.

How exactly does the rotational transformation work? What if i already know it rotates about the X axis by A degrees and about the Y axis by B degrees? Can I then just do simple trig in that case to back track the value? Or is it not that simple and I have to rotate it about the axis it has to rotate in order to match back to the original coordinate system?

Is there a function in MATLAB to which i can insert say 3 points which define one coordinate system and another 3 points for a second coordinate system that would then give me the transformation matrices?

Please let me know if my wording is unclear, this 3-D problem is so very hard to visualize I can't seem to figure out how to write all the trig for it and wanted to try it mathematically... but If you by chance know a more simple solution which mgiht be more straight forward please suggest it!


Solution

  • Answering the pared down version of the question (see the comments):

    A point expressed in a coordinate system given by an origin point O1, with axis vectors X1, Y1 and Z1 has coordinates P=(x1, y1, z1) in that coordinate system. Similarly, in a second coordinate with origin O2 and axis vectors X2, Y2 and Z2, the same point is expressed P=(x2, y2, z2). (Note the lower case for coordinates, upper case for points and vectors).

    What this actually means is:

    P = O1 + x1 X1 + y1 Y1 + z1 Z1   and
    P = O2 + x2 X2 + y2 Y2 + z2 Z2
    

    Setting these equal to each other, and writing them in matrix form:

    [ O11 ]   [ X11  X12  X13 ][ x1 ]   [ O21 ]   [ X21  X22  X23 ][ x2 ]
    [ O12 ] + [ Y11  Y12  Y13 ][ y1 ] = [ O22 ] + [ Y21  Y22  Y23 ][ y2 ]
    [ O13 ]   [ Z11  Z12  Z13 ][ z1 ]   [ O23 ]   [ Z21  Z22  Z23 ][ z2 ]
    

    Let's call the matrices on each side M1 and M2 respectively, use the origin points as column vectors, and call the column point vectors p1 and p2. Then we can write the previous equation as:

    O1 + M1 p1 = O2 + M2 p2
    

    If your coordinate axes for each system are linearly independent, then M1 and M2 are invertible. If in addition they are orthogonal, then the inverse of each is just it's transpose! So we get:

    p1 = Transpose[M1] (O2 - O1 + M2 p2)   and similarly going the other way
    p2 = Transpose[M2] (O1 - O2 + M1 p1)
    

    You can read a more general treatment of change of basis here, but I think my strip-down treatment will get you writing code faster.