This isn't terribly efficient but should work. You need to compose a transformation matrix - a 3x3 or - if using homogeneous coordinates - a 4x4.

a. matrix to translate to (-x1, -y1, -z1) so that x1,y1,z1 are now all zero.

b. matrix to rotate by theta XZ so that (x2,y2,z2) is now in the YZ plane (x2 becomes zero).

You will need to remember some geometry to calculate theta XZ.

c. matrix to rotate by theta YZ so that (x2,y2,z2) is now the Z axis (x2 and y2 are zero).

You will need to remember some geometry to calculate theta YZ.

d. matrix to rotate about the Z axis (in the XY plane) by your angle of rotation.

e. apply the inverse of (c) above.

f. apply the inverse of (b) above.

g. apply the inverse of (a) above.

You can concatenate the above matrices into a single matrix and apply that to your point (x,y,z). If using a 4x4 matrix, don't forget to normalize the result.

15,969,265 members