# Calculate the angles between two 3D Points

Hi All,

I had an idea that I wanted to implement but I wasn’t quite sure how the math would work. My idea is to use skeleton data via a kinect to control the rotation of a 3d model. Currently my implementation is to have a skeleton and to create an imaginary z-plane in front of them. When both hands cross this zplane threshold it compares the angle between them like so :

``````

//Scaled 3D positions of each skeleton joint
ofVec3f rightHand = positions[SK::SkeletonEnum::RIGHT_HAND ] ;
ofVec3f leftHand = positions[SK::SkeletonEnum::LEFT_HAND ] ;

//ignore the z and calculate the 2D angle
handAngle = ofRadToDeg( atan2( rightHand.y - leftHand.y, rightHand.x - leftHand.x ) ) ;

``````

and rotates it on just one axis. But I wasn’t sure how to implement the same idea using 3d positions. If I could somehow get two angles I think I can combine this with the QuaternionArcballExample to get the desired effect I’m looking for. Anywho any help or resources would be super helpful ! Thanks

Some observations that may push you in the right direction…
There is no such thing as an angle between two points. You need a minimum of 3 non-collinear points (or two non-parallel lines) to have an angle between them.

Having said that, you can always use a reference line (x-axis in your case, you are essentially calculating the slope of the line represented by the two points) or a reference plane to calculate the angles.

Hence it might help to think of the z-plane as the reference plane and then calculating the angle between the line and the plane… the formula for which should be easy to google. Your line vector will be right hand - left hand (or other way round based on your axis rotation)

Regards,
Abe