I hope you can help me with a mathematical problem I'm trying to solve (for many days) and so far no success.
Given 2 sets P=[p_1,p_2,p_3] and Q=[q_1,q_2,q_3] of 3 infinite lines each in 3D space (each p_i and q_i (i=1,2,3) is a 3D line represented by a 3D point and a unit vector). so overall we have 6 lines.
I need to find a rotation matrix R (3x3) so that if I rotate all the lines in P by R then I get new lines P_rotate=[p_1_rotate, p_2_rotate, p_3_rotate] so that p_i_rotate and q_i (i=1,2,3) intersect each other.
I know there might not be such a rotation matrix and in some cases there might be infinite rotation matrices (for example if all the 6 lines are on the same plane and the axis of rotation is perpendicular to that plane). but the assumption here that for sure there exists such a rotation matrix and if there are more than one, then I can choose any of them.
This is what I tried to do so far:
It's actually solving 3 equations of 3 variables (the variables are the 3 angles around the axises x,y,z). but the equations were extremely complex that I couldn't solve them (and I'm not even sure they are solvable). You can calculate the rotated lines as a function of the 3 angles. meaning each rotated line will contain a new point and a new vector both as a function of the 3 angles. then I calculate for each line the distance to the relevant line in Q. and I need to find for which angles the 3 distances are zero. I assumed here that first I rotate around Z axis, then around Y axis and then around X axis. I think the order doesn't matter since whatever order I choose I may get different angles but the final rotation matrix will be the same. Anyway, the final 3 equations were extremely long and with many multiplications of the unknown variables so it was actually impossible for me to solve them.
I also tried to solve it in a different way. not using rotation matrix. but Rodrigues' rotation formula. in Rodrigues' formula I rotate around an axis line that passes through the origin by an angle theta. so I actually need to find v_x,v_y,theta where v_x, v_y are the x and y components of a unit vector of the axis line (v_z can be calculated by v_x and v_y since the vector is unit). and theta is an angle of rotation around this axis. again, I got 3 very long and complex equations that I couldn't solve.
Anyone has any idea of how to solve it? or can refer me to a link that (hopefully) explains about it? Will appreciate any help!