Calculate the angle between a vector and a gravity pendulum

coordinate systemsmathematical physicsvectors

There is a physical device (sensor) which I can rotate. The device sends its X Y Z coordinates and a calculated acceleration vector in mg (mill mg).
For example:

X 116.0 Y 98.0 Z 151.0 MG 1031.0

X 117.0 Y 93.0 Z 152.0 MG 1042.0

X 117.0 Y 95.0 Z 151.0 MG 1044.0

This device should lay still on the table and its offset has to be 0 since the vector z is parallel to gravity pendulum and a central vector.

enter image description here

However, when I rotate the device, the central vector changes and the gravity vector stays. And what I have to calculate is this angle:

enter image description here

What I've been recommended to do so far is:

Let's take the data we receive:

X 116.0 Y 98.0 Z 151.0 MG 1031.0

X 117.0 Y 93.0 Z 152.0 MG 1042.0

X 117.0 Y 95.0 Z 151.0 MG 1044.0

  1. Calculate average vector: ((116+117+117)/3 = 116,6; 95,3; 151,3)

  2. Measure what value the device reports when lying stationary and flat. This will probably correspond to a vector along one of the axes of the sensor, whose magnitude corresponds to 1 g of acceleration.

In my case, when laying stationary and flat, the device reports (90; 90; 180), so my reference vector is (0, 0, 1).

  1. Calculate direction: averageVector * 1/Sqrt(Dot(averageVector, averageVector))

Dot product of average vectors is: 45601,3.

SQRT of the dot product is: 213,54.

1 / sqrt is: 0,0047

direction = (116,6 * 0,0047; 95,3 * 0,0047; 151,3 * 0,0047) = (0,5463; 0,4464; 0,7087)

  1. cosine = Dot(direction, referenceVector)
    cosine = 0,7087

  2. Here we're using the fact that the dot product between two unit vectors gives the cosine of the angle between them. So we can use the inverse cosine function to turn that into an angle in radians, then rescale that to change the units into degrees.

However, when I receive a degree value, it says it is 44,8729. When in fact the device was lifted up for about 5 degrees or so, not 44.

If I change the average vector to (90, 90, 180) it should give me the degree error of 0, but instead I receive 35ยบ value.

Could anyone help me understand what I am doing wrong? Thank you so much.

Best Answer

Should your reference vector be $(1,1,2)$ instead of $(0,0,1)$

Then you'll get $\cos\theta = \frac{514.667}{\sqrt{6}\times 213.54}$ and the angle is about $10.3$ degrees.