Find rotation of object based on fixed points on object

314 Views Asked by At

First of all sorry, my formal math terms are fairly rusty. But please do use formal terms and notations in your answers. I can research them myself when in doubt. I have no real idea how to even begin to solve this problem. This is also not homework, but for custom 3D navigation in a video game.

I have a cartesian coordinate system with X, Y and Z coordinates. In this coordinate system, there is an object capable of translation and rotation (= it can be anywhere, and rotated). Assuming my object is at the origin (0, 0, 0) and in a "default rotation", then I know the absolute coordinates of three reference points $a$, $b$ and $c$, which each pairwise differ in at least $1 \le n \le 3$ coordinates and do not lie on a straight line. I would like $n$ to be minimal while still achieving a unique result. I can also query each point's coordinates at any given time.

For ease of use, I would like to specify rotations in coordinate deltas. For example, if my rotation is (1, 0, 0), then if I moved forwards the global coordinates would change by $(1,0,0) \times speed$ per time step. So essentially I would like to have my rotation as a normalized "forwards vector" with length 1.

The default rotation of my object should be (0,0,1), although I am not sure whether this will play any role.

How do I calculate the current forward vector based on the reference points' original global coordinates and current global coordinates? What is the minimal number of dimensions $n$ that the reference points need to be pairwise different from each other?

Might be related to this question, but I cannot guarantee an axis-aligned normal vector of my plane.

1

There are 1 best solutions below

2
On

Let the three points on the object be $P_1, P_2, P_3$. Since the geometry of the object is known to you, then these three vectors are known in terms of the position of the object center (any reference point on the object) and a $3 \times 3$ rotation matrix. This means that

$P_1 = P_0 + R Q_1 \hspace{24pt} (1) $

$P_2 = P_0 + R Q_2 \hspace{24pt} (2) $

$P_3 = P_0 + R Q_3 \hspace{24pt} (3) $

where $Q_1, Q_2, Q_3$ are known constant vectors.

Now when the object translates/rotates, the position of these three points will change from $Q_1$, $Q_2$, $Q_3$ (at the default position/orientation where $P_0 = 0$ and $R = I$) to $P_1, P_2, P_3$. Using the three equations we can determine $R$ and $P_0$, given $P_1, P_2, P_3$. Subtract (2) from (1), you get,

$P_1 - P_2 = R (Q_1 - Q_2) \hspace{24pt} (4) $

Now, subtract (3) from (1), you get,

$P_1 - P_3 = R (Q_1 - Q_3) \hspace{24 pt} (5) $

Finally, find the cross product between the left hands side vectors of equations (4) and (5):

$(P_1 - P_2) \times (P_1 - P_3) = ( R (Q_1 - Q_2) ) \times (R (Q_1 - Q_3) ) $

From the properties of the rotation matrix, we know that,

$ ( R (Q_1 - Q_2) ) \times (R (Q_1 - Q_3) ) = R ( (Q_1 - Q_2) \times (Q_1 - Q_3) ) \hspace{24pt} $

Therefore,

$(P_1 - P_2) \times (P_1 - P_3) = R ( (Q_1 - Q_2) \times (Q_1 - Q_3) ) \hspace{24pt} (6)$

Equations (4), (5), (6) can be written compactly as:

$ P = R Q $

where

$P = \begin{bmatrix} P_1 - P_2 && P_1 - P_3 && (P_1 - P_2) \times (P_1 - P_3) \end{bmatrix} $

and

$Q = \begin{bmatrix} Q_1 - Q_2 && Q_1 - Q_3 && (Q_1 - Q_2) \times (Q_1 - Q_3) \end{bmatrix} $

Hence, the matrix $R$ is given by,

$ R = P Q^{-1} $

So now we have the rotation matrix of the object. The center $P_0$ of the object that determines its translation with respect to the absolute origin, can be found from any of equations (1) - (3) by substituting $R$ and solving for $P_0$, for example using (1),

$P_0 = P_1 - R (Q_1)$

This completes the solution.