# Thread: Rotation matrix - video tracking

1. ## Rotation matrix - video tracking

Hello,

I have been stuck on this problem for a few days now, and could do with some help!

I have 2 frames of a video, with 5 trackers on an object.
In the first frame, I know the coordinates of the 5 trackers and I have defined one tracker as being the origin A. (I have subtracted its x,y,z values to the other trackers so it can be 0,0,0).
A(x,y,z), B(x,y,z), C(x,y,z), D(x,y,z), E(x,y,z)

In the second frame, the object has moved in space, tilted, and rotated. I know the coordinates of only 4 of the 5 trackers and have defined an origin A'.
A'(x,y,z), B'(x,y,z), C'(x,y,z), D'(x,y,z), E'(x,y,z)

I am trying to find the coordinates of the 5th tracker in the second frame.
I am pretty sure that I need a rotation (and/or transformation) matrix, but I am stuck.
I tried to define a new origin by doing a cross product using two of the vectors
( Cross Product )
but I am now stuck, and can't seem to find any information that would apply specifically to my problem.

Any help would be more than welcome

Frame 1: Frame 2:

2. ## Re: Rotation matrix - video tracking

Hey yorami.

Basically as you pointed out, you need a rotation matrix. You can the rotation axis by calculating the cross product of the vectors obtained by using the new and old points and the angle is the angle formed between the vectors.

The above method assumes you are rotating about the origin. If you are not you need to subtract the point of rotation from the points, do the rotation, and then add it back.

Specifically, we have a point o (old point), n (new point) and we calculate (o x n)^ = (oxn)/[||o||*||n||] which gives the rotation axis. We then use <o,n>/[||o||*||n||] which gives us cos(theta) where theta is the angle of rotation. Take a look at this wiki entry for rotation matrices:

Rotation matrix - Wikipedia, the free encyclopedia

Do you have the translation vector or do you need to figure it out from the data? If you get it from the data you are going to have to solve a few simultaneous equations.

3. ## Re: Rotation matrix - video tracking

I don't think that I need a translation vector as I have coordinates from the cameras, and have subtracted the point that I define as the origin from the other points. The origin is now (0,0,0).

The values below are simplified, and it is possible that the trackers have moved so I cannot verify the maths accurately.
I know that, as a consequence, the final value will be approximative, but it is (I think) the best that I can do to find the value of this point.

The old points (o):

o1 = (-93, 8,156)
o2 = (-96, 4, -138)
o3 = (-162, -36, 132)
o4 = (-182, -41, -88)

The new points (n):

n1 = (-58, -86, 155)
n2 = (-62, -69, -135)
n3 = (-65, -155, 128)
n4 = ( looking for it! :-)

The cross product of the first vector is:

w(1) = o(2)*n(3) - o(3)*n(2);
w(2) = o(3)*n(1) - o(1)*n(3);
w(3) = o(1)*n(2) - o(2)*n(1);

W = [14656 5367 8462]

So the Rotation axis is:

(o x n)^ = (oxn)/[||o||*||n||]

Magnitude of the vectors:
| o | and | v | represent the magnitude of each vector, and are:
| o | = sqrt(o(1)*o(1) + o(2)*o(2) + o(3)*o(3)) = 181.7938
| v | = sqrt(v(1)*v(1) + v(2)*v(2) + v(3)*v(3)) = 186.5074

= o.n / [ |o||n| ]
= ( o(1)*n(1) + o(2)*n(2) + o(3)*n(3) ) / 181.7938 * 186.5074
(o x n)^ = 0.8519
(o x n) = sqrt(0.8519)
(o x n) = 0.9230

How can a single value define an axis?

The angle of rotation is:
<o,n>/[||o||*||n||] "which gives us cos(theta) where theta is the angle of rotation."
Unfortunately, I do not know what the bracket mean.. From this link ( 4 Ways to Find the Angle Between Two Vectors - wikiHow ) I am guessing that it means:

cosθ = ( o(1)*n(1) + o(2)*n(2) + o(3)*n(3) ) / 181.7938 * 186.5074
cosθ = 0.8519
The inverse cos of 0.8519 is :
acos (0.8519) = 0.5512
which is in Radiant, and corresponds to 48.8103 in degrees.

I cannot visualise what to do next. I am really sorry, but my maths knowledge is too limited for the wikipedia page to be of any help.

Thank you

4. ## Re: Rotation matrix - video tracking

When I say oxn I mean the cross product of o and n which is a vector. I don't mean the dot product.

5. ## Re: Rotation matrix - video tracking

Ok, I changed this.
Using o1 and n1 as examples, I now have:

o1 = [-93, 8,156]
n1 = [-58, -86, 155]

%rotation on the axis is the cross-product:

We need:
cross (o1,n1)
14656 5367 8462
And:
| o | and | v | that represent the magnitude of each vector, and are:
| o | = sqrt(o1(1)*o1(1) + o1(2)*o1(2) + o1(3)*o1(3)) = 181.7938
| n | = sqrt(v1(1)*n1(1) + n1(2)*n1(2) + n1(3)*n1(3)) = 186.5074

So:
cross(o1,n1) / (181.7938 * 186.5074)
0.4323 0.1583 0.2496
0.4323 + 0.1583 + 0.2496
According to the wikipedia link you sent me, the axis vector needs to be:
, which is not the case, as I have:
0.4323 + 0.1583 + 0.2496 = 0.8402

Therefore I tried with the original values from the camera, that I will call o2 and n2:
o2 = [-92.8114624023437, 8.4225158691406, 155.781616210938]
n2 = [58.0306701660156, -85.8821716308594, 155.3882446289068]

| o | = sqrt(o2(1)*o2(1) + o2(2)*o2(2) + o2(3)*o2(3)) = 181.5291
| n | = sqrt(n2(1)*n2(1) + n2(2)*n2(2) + n2(3)*n2(3)) = 186.7855

cross(o2,n2) / (186.7855 * 186.7855) =
0.4210 0.6725 0.2145
0.4210 + 0.6725 + 0.2145 = 1.3080

and the result is still not equal to 1, but this time superior.

According to wikipedia, the next will be to create the matrix rotation as following:

Then I will have to multiply my original point (o) by the rotation matrix to obtain the new point (n).

Am I correct? How do I get an axis vector ?

6. ## Re: Rotation matrix - video tracking

To get a vector with that property you have to normalize your vector which is why I told you to divide by ||o||*||n|| so that the vector is of unit length (i.e. equal to 1).

If you don't get a unit length of 1 then you need to check your calculations and working because dividing a vector by its length should always give a unit length vector back with no exceptions (not taking into account the zero vector which doesn't hold in this case).