I have 2 points P1 = (x1, y1, z1) and P2 = (x2, y2, z2). The problem statement is some what like this.
Draw a plane at point P1 (any arbitrary point in 3D space). Rotate the plane to face point P2 (another arbitrary point in 3D space) such that the normal vector of plane at point P1 is facing point P2. Change the rotation of the plane such that it maintains it perpendicularity to point P2 as much it can while one of its X, Y or Z rotations is 0
So far, I've managed to draw the plane and make it face the point P2 using this code:
def align_plane_to_point(obj, point): normal = obj.data.polygons.normal.xyz mat_obj = obj.matrix_basis mat_scale = mathutils.Matrix.Scale(1, 4, mat_obj.to_scale()) trans = mat_obj.to_translation() mat_trans = mathutils.Matrix.Translation(trans) point_trans = point - trans q = normal.rotation_difference(point_trans) mat_rot = q.to_matrix() mat_rot.resize_4x4() mat_obj = mat_trans * mat_rot * mat_scale obj.matrix_basis = mat_obj
Calling this function with arguments obj = Plane at Point P1 and point = point P2, makes sure that the normal side is facing point P2.
Now I am not sure as to how to go about the last part of the problem. Maintaining perpendicularity to point P2 but making sure at least one of the rotations is 0.
Say for example the rotations (in degrees) are like so after executing the above function:
X: -40 Y: 60 Z: -80
Again how do I know (programmatically) which value can I set to 0, making sure plane is as much perpendicular as it can be. I don't mind changing the rest of the values as well as long as the normal is facing towards the point P2. Manually changing the values, I can see the rotation of the plane and thus decide, but using Python I don't know how to figure this out.
Any help is appreciated.