1
$\begingroup$

See a simple webpage here, for an object, if one know the acceleration in three direction $\hat x, \hat y,\hat z$, one could extracted two of the angle of the object between the plane that's normal to the gravity.

I suddenly had a hard time to picture how that was done. Could you explain to me how they calculated the expression for angle AX and AY?

$\endgroup$
  • $\begingroup$ What is AX supposed to be the angle between? $\endgroup$ – G. Smith Feb 1 at 4:01
  • $\begingroup$ two of the angle of the object between the plane that's normal to the gravity That doesn’t really make sense. $\endgroup$ – G. Smith Feb 1 at 4:01
  • $\begingroup$ @G.Smith Sorry, I meant in 3 space. The plane was uniquely determined by the nonzero vector,i.e. I meant the "sea level" of which the gravity was in direction of the normal vector. Not sure how exactly to say it.(The plane perpendicular to the gravitational acceleration?) $\endgroup$ – ShoutOutAndCalculate Feb 1 at 4:49
  • $\begingroup$ Lookup cartesian to spherical coordinate transformation. $\endgroup$ – ja72 Feb 1 at 23:39
2
$\begingroup$

Suppose there is a coordinate system (x, y, z), and you would like to work out the angle between the x-axis in your coordinate system and the ground on the Earth (reasoning will be similar for other axes).

You are given the components $f_x, f_y, f_z$ of the gravitational force along each axis (this is roughly what the accelerometer does). Adding those components, as vectors, gives you the direction and magnitude of the gravitational force in your coordinate system: $\mathbf{F_g} = f_x \hat{x} + f_y \hat{y} + f_z \hat{z}$.

On Earth, of course, the gravitational force is perpendicular to the ground and pointing down. If you now rotate your coordinate system to make the gravitational force point straight down the z-axis and record the rotation angles, then you can tell how your system was originally oriented, compared to the ground.

In particular, you can do this:

  1. Rotate your coordinate system about its x-axis until the gravitational force has no component along the y-axis.
  2. Next, rotate your coordinate system about the y-axis by some angle $-\alpha$ to get the gravitational force to be along the z-axis.

The angle $\alpha$ must have been the angle between the x axis of your coordinate system and the ground.

Relating this back to the web page you linked to...

After step 1 above, you have a vector with two components: one along the x-axis (which you will use the rotation in step 2 to eliminate), and one along the z-axis.

Since you have not changed the component parallel to the x-axis in step 1, its magnitude is still $f_x$.

The component along the z-axis must be whatever is left over, which is the combination of the $f_y$ and $f_z$ components before step 1. The magnitude of the combination is $\sqrt{f_y^2+f_z^2}$, which is just applying pythagoras.

So now you want to work out the angle to rotate. You have a right-angled triangle with one leg up the z-axis, magnitude $\sqrt{f_y^2+f_z^2}$, and one leg parallel to the x-axis, magnitude $f_x$. The angle between the z-axis and the hypotenuse is $\alpha$ (the negative of the angle you want to rotate). The tangent of the angle between the z-axis and the hypotenuse is $\frac{f_x}{\sqrt{f_y^2+f_z^2}}$. Take the inverse of the tangent ($\arctan$) to get $\alpha$.

(This would be better with pictures, but this is a bit time-consuming).

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! That helps a lot! So the fact that the generator of the rotation group do not commute does not affect the calculation? $\endgroup$ – ShoutOutAndCalculate Feb 1 at 4:52
  • 1
    $\begingroup$ @ShoutOutAndCalculate, I haven't thought deeply about that, but since you leave the x-axis unmoved when you do the first rotation I think it won't affect the calculation of the angle between the x-axis and the ground. $\endgroup$ – Tony Feb 1 at 4:56
1
$\begingroup$

The Rotation matrix of the smartphone can be defined by its roll,pitch and yaw rotation.

Roll rotation angle $\phi$

$$R_x= \left[ \begin {array}{ccc} 1&0&0\\ 0&\cos \left( \phi \right) &-\sin \left( \phi \right) \\ 0&\sin \left( \phi \right) &\cos \left( \phi \right) \end {array} \right] $$

pitch rotation angle $\theta$

$$R_y= \left[ \begin {array}{ccc} \cos \left( \theta \right) &0&\sin \left( \theta \right) \\ 0&1&0\\ -\sin \left( \theta \right) &0&\cos \left( \theta \right) \end {array} \right] $$

yaw rotation angle $\psi$

$$R_z= \left[ \begin {array}{ccc} \cos \left( \psi \right) &-\sin \left( \psi \right) &0\\ \sin \left( \psi \right) &\cos \left( \psi \right) &0\\ 0&0&1\end {array} \right] $$

The Rotation matrix $R$ of the smartphone can obtain from this multiplication

$$R_1=R_x(\phi)\,R_y(\theta)\,R_z(\psi)\tag 1$$

or $$R_2=R_y(\theta)\,R_x(\phi)\,R_z(\psi)\tag 2$$

because the matrices are not commute $R_1\ne R_2$

the acceleration vector is orientate to the z-axis

$$\vec{g}=\left[ \begin {array}{c} 0\\ 0\\ 1\end {array} \right] $$

and the components of your acceleration measurement is:

$$\vec{F}_g=\left[ \begin {array}{c} {\frac {{\it fx}}{\sqrt {{{\it fx}}^{2}+{{ \it fy}}^{2}+{{\it fz}}^{2}}}}\\ {\frac {{\it fy}}{ \sqrt {{{\it fx}}^{2}+{{\it fy}}^{2}+{{\it fz}}^{2}}}} \\{\frac {{\it fz}}{\sqrt {{{\it fx}}^{2}+{{\it fy} }^{2}+{{\it fz}}^{2}}}}\end {array} \right] $$

the solutions for the roll angle $\phi$ and the pitch angle $\theta$ are:

$$\vec{F}_g=R_1\,\vec{g}\quad \Rightarrow\quad \phi_1=-\arctan \left( {\it fy},{\it fz} \right) \quad \theta_1= \arctan \left( {\frac {{\it fx}}{\sqrt {{{\it fy}}^{2}+{{\it fz}}^{2}} }} \right) \tag 3 $$

and

$$\vec{F}_g=R_2\,\vec{g}\quad \Rightarrow\quad \phi_2=-\arctan \left( {\frac {{\it fy}}{\sqrt {{{\it fx}}^{2}+{{\it fz}}^{2} }}} \right) \quad \theta_2=\arctan \left( {\frac {{\it fx}}{{\it fz}}} \right) \tag 4 $$

thus the solutions are not unique

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.