Plotting basis vectors of a 3D local coordinate system defined by a homogenous transform

Given a 4x4 homogenous transform $$H$$ I know that the first three columns of $$H$$ (ignoring the last row) define the basis vectors of the 3D coordinate system that it moves its "parent" coordinate system into. Of course the parent is implicitly the standard basis $$I$$ unless otherwise specified. This observation comes from the fact that left multiplying each of the standard basis vectors by $$H$$ picks out each one of the columns. The last column (ignoring the last row) of $$H$$ defines the origin of this new coordinate system.

I would like to plot some kind of a 3D geometry (say, a plane) that has been transformed by $$H$$ as well as plot its local coordinate system visualized by its basis vectors.

Let's say I have some transform Hpw (plane to world) which transforms some plane from its local coordinates to the global coordinates (the world). For brevity, I will define this matrix using Matlab syntax. makeH simply concatenates a rotation matrix and translation vector and adds a row of 0 0 0 1.

Hpw = makeH(eul2rotm([pi/4 pi/4 pi/3], 'ZYX'), [0 0 0]);

Hpw =

0.5000    0.0795    0.8624         0
0.5000    0.7866   -0.3624         0
-0.7071    0.6124    0.3536         0
0         0         0    1.0000


From my understanding each column of Hpw represent the world basis vectors in plane coordinate space.

What I want are the plane basis vectors in world coordinate space since I am plotting in world coordinate space.

Therefore I plot some scaled versions of the columns of Hwp = inv(Hpw) which are just arrows that share the origin [0 0 0]. I get exactly the effect I want.

I was quite satisfied with this until I introduced translation in my Hpw.

Hpw = makeH(eye(3), [0 500 0]);

Hpw =

1     0     0     0
0     1     0   500
0     0     1     0
0     0     0     1


Of course, Hwp = inv(Hpw) has a -500 in its translation component, so the arrow origins when I'm plotting are in the wrong place.

I solved this by plotting the columns of the inverse of the rotation matrix that makes up the homogenous transform (inv(Hpw(1:3, 1:3)) in Matlab syntax) and using the original translation vector Hpw(1:3, 4) as the origin of the basis vector plot.

Question By using the columns of the inverse of the rotation matrix as directions of the basis vectors and the translation as the origin, am I correctly visualizing the local coordinate system of a 3D object such as this plane? Furthermore, what is the mathematical explanation as to why I couldn't have used the last column of inv(Hpw) as the origin of the local coordinate system? My hunch is that this has something to do with the fact that homogenous transforms are nonlinear in $$\mathbb{R}^3$$ but can't really tie that back to what I'm seeing on the plots.

EDIT:

Here's what happens if I don't use the inverse of the rotation part of Hpw.

Hpw = makeH(eul2rotm([pi/4 0 -pi/2], 'ZYX'), [0 1000 0]);

Hpw =

1.0e+03 *

0.0007   -0.0000   -0.0007         0
0.0007    0.0000    0.0007    1.0000
0   -0.0010    0.0000         0
0         0         0    0.0010


The coordinate basis vectors aren't aligned onto the plane.

However, if I invert the rotation component and keep the translation component as the origin, I get something more reasonable.

To generate the plane, I'm creating a mesh grid centered at (0, 0, 0). I then apply Hpw to every point on the plane to bring it into the "world". Here's what the grid looks like before applying Hpw.

To plot the arrows I'm using quiver3 where the arguments x, y, and z is the translation component of Hpw and u, v, w are the scaled versions of the first three columns of Hpw respectively.

• Looks like you’re restricting this to affine transformations, i.e., ones for which the last row of the matrix is $(0,0,0,1)$, and perhaps even further to rigid motions.
– amd
Commented Jun 10, 2019 at 8:12
• @amd that’s correct Commented Jun 10, 2019 at 12:23
• Without knowing exactly how you’re generating those dots that presumably represent your plane and how you’re computing the endpoints of those arrows, there’s really no way to tell if you’re applying the transformations consistently.
– amd
Commented Jun 27, 2019 at 2:46
• @amd added some more details. Commented Jun 27, 2019 at 3:04
• As long as you’re applying the same transformation to both the plane dots and the basis arrows ( and applying it correctly), how it’s composed shouldn’t make any difference. I’ll take a closer look when I get some time.
– amd
Commented Jun 28, 2019 at 0:01

The columns $$\mathbf h_i$$ of a transformation matrix $$H$$ are the images of the basis vectors expressed in coordinates relative to the “output” basis. If Hpw is an affine transformation matrix that converts from local to global coordinates, then its first three columns are the directions of the local coordinate axes expressed in global coordinates, while the last column is the global homogeneous coordinate vector of the local frame’s origin.† There’s no need to invert anything in order to plot these coordinate axes: just draw an arrow starting at $$\mathbf h_4$$ and ending at $$\mathbf h_4+k\mathbf h_i$$, where $$k$$ is the desired scale factor. Incidentally, if the linear part of $$M$$ is a rotation matrix $$R_{3\times3}$$, then since $$R_{3\times3}^{-1}=R_{3\times3}^T$$, its rows are the local (plane) coordinates of the world coordinate axis directions.
I’m at a bit of a loss as to why, if you indeed used the columns of inv(Hpw) to generate your plot, it looks approximately correct. Since the linear part of your matrix is a rotation, the columns of its inverse are its rows. The second and third rows in particular point in radically different directions than the second and third columns and would result in a rather different picture than the one you’ve got in your question:
I suspect that you didn’t actually use the columns of inv(Hpw) to produce that plot, or that there are mutually-canceling errors. Rotations and the space $$\mathbb R^3$$ have several convenient properties that can combine to produce numerically-correct results from mathematically incorrect computations.
†: Don’t ignore the last row: The $$\mathbf h_i$$ are homogeneous coordinate vectors. The zeros at the bottom of the first three columns indicate that the images of the corresponding basis vectors, which are points at infinity, are also points at infinity; the last column is a finite point, which is what one would like for the local coordinate system origin. If $$H$$ represents a projective transformation, it might not have those zeros in the last row: images of the basis points at infinity can be finite—the vanishing points of lines parallel to those coordinate axes.