MATLAB: How to rotate vector v into z axis, performing same rotation on scatter plot

coordinate rotationrotation into z-axis

I have an nx3 matrix of 3d coordinates [x1, y1, z1; x2, y2, z2;…; xn, yn, zn]. In the center of these coordinates, there are 5 points that form a plane P. I've changed the coordinates to have the origin at the center of P. Now, I'd like P to lie in the xy-plane, as opposed to intercepting the xy-plane, which it does now. I have found a vector N orthonormal to P, and I found the angle between N and the z-axis. I want to rotate N into the z-axis, meanwhile performing this rotation on all coordinates in the matrix. I was thinking about a rotation matrix, but that requires I know the direction of x' and y' axes, where x'= x-axis if N is currently the z-axis (before rotation). In addition: I calculated the angles (in radians) between N and x (1.7867), N and y (0.7981), and N and z (2.3230). In other words, all I want is for angle Nz to equal 0; I don't mind if Nx and Ny are nonzero. Thanks!

Best Answer

You might find the makehgtform and hgtransform functions helpful.
Experiment with them.