How to convert acceleration projection to angle? 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?
 A: 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:


*

*Rotate your coordinate system about its x-axis until the gravitational force has no component along the y-axis.  

*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).
A: 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 
