A transformation matrix is a way to map a point in one reference frame to another.
When you have pa in frame A, and want the same point, pb, in frame B.pa→pbUse transformation matrix MBAMBA∗pa=pbUse the inverse matrix MAB to map back the other wayMAB∗pb=pa
The animation below shows an example of two frames: the white set of axis (frame A), and a multicolor set of axis (frame B) which are rotated to no longer aligns with frame A. Any point in space can be expressed relative to frame A or relative to frame B. A transformation matrix is how you get from one frame to the other.
The matrix MAB can be calculated from Euler angles (yaw/psi, pitch/theta, & roll/phi) that define frame B relative to frame A. This matrix is generated by multiplying three component rotation matrices (Y, P, & R).
The order of multiplying the component matrices makes a difference. In this case the order of rotation going from frame A to B is yaw, pitch, roll.
Yaw: Rotate frame B about it’s own Z axisPitch: Rotate frame B about it’s own Y axisRoll: Rotate frame B about it’s own X axisY=⎣⎡cos(ψ),−sin(ψ),0sin(ψ),cos(ψ),00,0,1⎦⎤P=⎣⎡cos(θ),0,sin(θ)0,1,0−sin(θ),0,cos(θ)⎦⎤R=⎣⎡1,0,00,cos(ϕ),−sin(ϕ)0,sin(ϕ),cos(ϕ)⎦⎤MAB=Y∗P∗R
MAB can transform a point in frame B (we’ll call it pb) to the same point in frame A (we’ll call it pa) by multiplying MAB on the left side of pb.
So doing this:pa=MAB∗pbIs the same as doing this:pa=Y∗P∗R∗pb
To reverse the process and transform a point from frame A to B, use the inverse matrix, MBA, which conveniently is just the transpose of MAB.
The transpose of a transformation matrix automatically takes care of reversing the order and direction of the component rotations.
MBA=(MAB)−1=(MAB)T=(Y∗P∗R)T=RT∗PT∗YT=R−1∗P−1∗Y−1So doing this:pb=MBA∗paIs the same as doing this:pb=R−1∗P−1∗Y−1∗pa
A Bit About Basis Vectors
The columns of MAB (and rows of MBA) are also the basis vectors (3D axis) of frame B with respect to frame A.
Likewise the columns of MBA (and rows of MAB) are the basis vectors of frame A with respect to frame B.
xb:x-axis of frame Bwith respect to frame Ayb:y-axis of frame Bwith respect to frame Azb:z-axis of frame Bwith respect to frame AMAB=[xbT;ybT;zbT]MBA=⎣⎡xbybzb⎦⎤
So when you transform a point in frame A to frame B you are essentially taking the dot product of that point with each basic vector of frame B.
To get more intuition on how transformation matrix rows & columns are basis vectors you can transform a point along the x-axis in frame B into frame A. Note that the calculated value of pa found is the same value of the first column of MAB. This is because pb corresponds to the frame B x-axis relative to frame B, and pa corresponds to the frame B x-axis relative to frame A. They are, of course, the same point described from two different frames of reference.
The rotation direction used follows the right-hand rule convention. With your right hand point your thumb in the direction of the axis of rotation and curl your fingers. The direction of rotation your fingers are curling is the positive rotation direction about that axis.
The original uploader was Schorschi2 at German Wikipedia., Public domain, via Wikimedia Commons