I am using a "Microsoft Kinect for Windows" to track the $x$, $y$, and $z$ positions of my Shoulder, Elbow, Wrist, and Hand. Each position is normalised to my shoulder so that my shoulder is always at $[1,1,1]$, and other points are relative.
The output of this program is a $3$ by $4$ matrix, in the form:
$$ \begin{bmatrix} Sx & Ex & Wx & Hx \\ Sy & Ey & Wy & Hy \\ Sz & Ez & Wz & Hz \\ \end{bmatrix} $$
From this I want to calculate the abduction and flexion angle between the shoulder and elbow.The abduction and flexion motions are shown below. How would I do this?
The co-ordinate system:
My Attempt So Far
To calculate the abduction angle, I used the dot product formula referenced against a unit vector pointing down, defined as zero degrees:
$$ \theta=\cos^{-1}\frac{ \begin{bmatrix} 1\\ 0 \end{bmatrix}\cdot \begin{bmatrix} Ez\\ Ey \end{bmatrix} } { |\begin{bmatrix} 1\\ 0 \end{bmatrix}| |\begin{bmatrix} Ez\\ Ey \end{bmatrix}| } $$
But this gives a value of $30$ degrees when my arm is straight down (it should be zero), and it increases to $45$ degrees when my arm is straight up (it should be 180).
What equation should I actually be using?