# What are the coordinates of a point on a rigid body after a rotation in 3D Euclidean space, given the initial coordinates and a center of rotation

Main question

Let ($x_p$, $y_p$, $z_p$) be the initial coordinates of a point $P$ on a rigid body in a right-handed 3D Euclidean space. Let ($x_r$, $y_r$, $z_r$) be the coordinates of a center of rotation $R$. Let $\psi$, $\theta$ and $\phi$ be rotations along axes parallel to the z-axis, y-axis and x-axis respectively. If I apply firstly a rotation $\psi$, then a rotation $\theta$ and lastly a rotation $\phi$ on the rigid body about point $R$, what will be the new coordinates of the point $P$?

Follow-up question

Let's say I have the coordinates of a large yet finite number of points defined on the surface of a rigid body stored in a 1D array in the following manner: [x1, y1, z1, ..., xn, yn, zn]. What is the most efficient algorithm to compute their new coordinates after a rotation as defined in the Main question?

Answer Thanks to mike I was pointed in the right direction. A pseudo-code to compute the rotation matrix as needed in his answer is the following:

function rotation_matrix_3d(psi, theta, phi)
rotMat = [cos(theta)*cos(psi)                            -cos(theta)*sin(psi)                           sin(theta);
cos(phi)*sin(psi)+sin(phi)*sin(theta)*cos(psi) cos(phi)*cos(psi)-sin(phi)*sin(theta)*sin(psi) -sin(phi)*cos(theta);
sin(phi)*sin(psi)-cos(phi)*sin(theta)*cos(psi) sin(phi)*cos(psi)+cos(phi)*sin(theta)*sin(psi) cos(phi)*cos(theta)]

return rotMat
end

-

Let $\vec{v}_p=(x_p,y_p,z_p)$ and $\vec{v}_r=(x_r,y_r,z_r)$. Denote $\vec{v}_{p'}=(x_{p'},y_{p'},z_{p'})$ the coordinates of P after rotation.
Then we have: $$(\vec{v}_{p'}-\vec{v}_r)=R_x(\phi)R_y(\theta)R_z(\psi)(\vec{v}_{p}-\vec{v}_r)$$
So $$\vec{v}_{p'}=\vec{v}_r+R_x(\phi)R_y(\theta)R_z(\psi)(\vec{v}_{p}-\vec{v}_r)$$