Given two points $P_0(x_0,y_0,z_0)$ and $P_1(x_1,y_1,z_1)$, and being $P_0$ the centroid of a square delimited by the following points: $$ (x_0 - 0.25, y_0 - 0.25, z_0) $$ $$ (x_0 + 0.25, y_0 - 0.25, z_0) $$ $$ (x_0 + 0.25, y_0 + 0.25, z_0) $$ $$ (x_0 - 0.25, y_0 + 0.25, z_0) $$ we know that vector $\vec{P_0P_1} = (x_1 - x_0, y_1 - y_0, z_1 - z_0)$ should be a normal of the previous plane. I would like to find the rotation matrix for the plane that solves the issue.

  • $\begingroup$ Not exactly clear what you are asking. Do you want to tilt the square in such a way that it is perpendicular to $\vec{P_0 P_1}$? Or do you need to rotate $P_1$? $\endgroup$ – Andrei Feb 28 '17 at 15:55
  • $\begingroup$ @Andrei Exactly, that's the point (the first one), and $P_0$ must be the center of rotation. Sorry if I formulated the question in a bad way... $\endgroup$ – Finfa811 Feb 28 '17 at 15:58

The normal to the original square is $\vec{n}=(0,0,1)$. To calculate the rotation of $\vec{n}$ onto $\vec{p}=\vec{P_0P_1}$, the axis of rotation is given by $\vec{p}\times\vec{n}$. Yo can calculate the angle from the dot product. You can get the rotation matrix using https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle If you want to rotate the square instead, it's the same rotation axis, with the opposite sign angle

  • $\begingroup$ Sorry, one more question. Now I can rotate $\vec{n}$ to make $\vec{p}$ the new normal of my square, so the rotation matrix $R$ that I have calculated is right. Is it possible to use $R$ to calculate the new position of the four points delimiting the square, or do I need another method for that purpose? $\endgroup$ – Finfa811 Mar 1 '17 at 9:18
  • $\begingroup$ You can use $R$ for the square as well $\endgroup$ – Andrei Mar 1 '17 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.