Aligning a rigid body's two axes to screen axes

50 Views Asked by At

I am very new to rigid body transformations.

I would like to align a 3D rigid body such that its first axis $o1$ would align with the display's vertical axis $d1$ and its second axis $o2$ with the display's horizontal axis $d2$.

In the case at hand, a human palm: I would like to align such that the palm's forward distal direction faces up in the display, and the direction perpendicular to it across the palm faces left on the display, so that the center of the palm faces forward and its front fingers face up. From an arbitrarily oriented point cloud describing the hand, from which let us assume I can somehow derive the mentioned two axes of the hand.

I've experimented aligning the entire rigid body by a rotation matrix from one single axis to the other as per this kind of transformation, which won't immediately scale for aligning two sets of (two) axes without getting the wrong directionality half of the time.

Even when aligning by just one axis through that technique ― the alignment only works in the sense of the axes converging ― without them necessarily agreeing on the sign of their direction, and hence the rigid body will undesirably flip.

Could you point me in the right direction?

1

There are 1 best solutions below

0
On BEST ANSWER

Let me assume that in your display coordinate system, the positive $y$-axis points up, and the positive $x$-axis points to the right. This is the common orientation used in most mathematical graphing, but it is only in recent years that computer graphics applications started honoring that convention, so it is possible that your system may use some different convention. If that is the case, you will need to modify the steps below.

So you have a unit vector $u = (u_x, u_y, u_z)$ that you want to map to $\hat y = (0,1,0)$ in display-coordinates, and another unit vector $v = (v_x, v_y, v_z)$ that you want to map to $-\hat x = (-1, 0, 0)$ (which is the left direction). And what you want to find is the transformation that converts all other points to their display coordinates.

First, we need to find the unit vector $w$ to map to the $\hat z$ direction in display coordinates. Now $\hat z = \hat y \times (-\hat x)$, and the same relationship should hold between $u, v, w$. That is $$w = u \times v = (u_yv_z - u_zv_y, u_zv_x - u_xv_z, u_xv_y - u_yv_x)$$

Once you've calculated $w$, an arbitrary point $r = (r_x, r_y, r_z)$ transforms into $(-v\cdot r, u\cdot r, w\cdot r)$ in display coordinates. That is, the transformation matrix is $$\begin{bmatrix}-v_x&-v_y&-v_z\\u_x&u_y&u_z\\u_yv_z - u_zv_y&u_zv_x - u_xv_z&u_xv_y - u_yv_x\end{bmatrix}$$

Note again that this requires $u$ and $v$ to be orthogonal unit vectors. If they are not, the image will be distorted,