Search code examples
python3dvectormath

Translate 3D points along arbitrary plane


I'm working with 3D PDB coordinates. I first use numpy.linalg.lstsq to solve the least squares equation, essentially giving me the coefficients of the plane (I think). I can view the plane using matplotlib, and it appears to be correct. I would like to be able to translate my 3D coordinates along the plane given by the least squares solution. For example, I would like to be able to translate points in the (X,Y) of the new plane. Would it be easier to rotate the points to be in the plane where (0,0,1) is the normal? My poor illustration of what I'm trying to accomplish


Solution

  • If I understand you question right you have a fixed point and want to move it on a plane where you have the normal vector. Lets suppose your normal vector n is (0,0,1) and your point p is (1,1,1). If we want to stay in the plane our translation vector t has to be normal to the normal vector.(n*t=0) where * is for the scalar product. You said you want to keep z constant so we set t_z = 0. Then lets say you want to move your point by t_x = 1. Now you just have to solve the equation: 0*1+0*t_y+1*0=0 for t_y wich in this case is arbitraty because the equation is already 0. So your translation vector for t_x = 1 and t_z = 0 is t = (1,t_y,0). In the general case you just fix as many coordinates of t as you need and calculate the remaining one with nt=0 equation. That should not be too hard to implement. So in one sentence: as long as the translation vector is perpendicular to your normal vector(nt=0) you remain in the same plane.