Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a line $l$ starting at origin ending at 0,0,1 along the $z$ axis. $l$ is rotated $P$ degrees around the $x$-axis and then $Q$ degrees around the $y$-axis. So I have a new endpoint for the line.

Now I have lot of points that I am projecting onto this line but what I am wondering is, can I just use the information about the line i.e. $P$ & $Q$ and precompute a (transformation/projection) matrix. And simply multiply each point with this matrix such that I get it's projection on the line.

share|cite|improve this question

By “projection onto the line”, do you mean orthogonal projection? If so, then for the original location of the line, along the $z$ axis, you can achieve this by simply setting $x$ and $y$ coordinates to zero, which corresponds to the projection matrix

$$M = \begin{pmatrix}0&0&0\\0&0&0\\0&0&1\end{pmatrix}$$

Now for the rotated situation. You can think of rotating the whole setup back into the situation where the line is the $z$ axis, where you perform the projection as outlined above, and then perform the rotations again to get things back to the new location of the line.

\begin{align*} X_P &= \begin{pmatrix}1&0&0\\0&\cos P&-\sin P\\0&\sin P&\cos P\end{pmatrix} \\ Y_Q &= \begin{pmatrix}\cos Q&0&\sin Q\\0&1&0\\-\sin Q&0&\cos Q\end{pmatrix} \\ T &= Y_Q\cdot X_P\cdot M\cdot X_P^{-1}\cdot Y_Q^{-1} \\ &= Y_Q\cdot X_P\cdot M\cdot X_{-P}\cdot Y_{-Q} \\ &= \small\begin{pmatrix} \sin^2Q\cdot\cos^2 P & -\sin P\cdot\sin Q\cdot\cos P & \sin Q\cdot\cos^2P\cdot\cos Q \\ -\sin P\cdot\sin Q\cdot\cos P & \sin^2P & -\sin P\cdot\cos P\cdot\cos Q \\ \sin Q\cdot\cos^2 P\cdot\cos Q & -\sin P\cdot\cos P\cdot\cos Q & \cos^2P\cdot\cos^2Q \end{pmatrix} \end{align*}

This way, you get a single matrix describing your whole operation.

share|cite|improve this answer

You can define two rotation matrices $R_1$ and $R_2$ that do the rotation about the $x-$ and $y-$ axes respectively. The matrix $R=R_2R_1$ then performs the desires operation.

You may also want to look up quaternions to do your rotations.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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