First, your y axis should point towards the screen, or else you won't have a right-handed coordinate system, and that might mess up your formulas when adapting a given algorithm such as the one linked to in Solution 1.
Second, your information does not suffice to determine the roll angle: it could be any value.
Third, the algorithm, in pseudocode, looks something like this:
Moving from one point to another gives you a direction. it is definied by the vector
V
you get by subtracting the two points.
V := (v1, v2, v3) = (x2, y2, z2) - (x1, y1, z1) = (x2-x1, y2- y1, z2- z1)
The yaw angle is the angle this vector encloses with the projection VP of that same vector with the horizontal plane. You can get that vector simply by setting the z-coordinate to 0.
VP := (v1, v2, 0)
To calculate the yaw angle, take advantage of the fact that the scalar product of two vectors equates the product of their respective lengths and the cosine of the enclosed angle, in this case:
V*VP = |V|*|VP|*cos(yaw)
. Based on this, you get:
yaw := acos ( V*VP/(|V|*|VP|) )
Pitch is the angle that VP encloses with the y-z plane. You can get it in the very same manner, by first projecting
VP
into the y-z plane ...
VPP := (0, v2, 0)
... and then calculate the angle enclosed between
VPP
and
VP
:
pitch = acos( VP*VPP / (|VP|*|VPP|) )
What is left to do for you is put this into C/C++ code, and implement functions for calculating the scalar product
v1*v2
of two vectors
v1
and
v2
, and the length
|v|
of a given vector
v
.