Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

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 am crossposting this question from Stack Overflow since it is more math then programming related.

In Reference to my question about projecting a planar Polygon to a plane, i came to another problem.

I want to project a base contour which is aligned to the x-y-plane along a projection vector from from a point P1 to a point P2. This already works, but now i also need to change the alignment of my base contour using the position of P1 and two vectors defining the new alignement base's x and y should be transformed to.

I want to use a transformation matrix M for this, which premultiplied to my projecton matrix p should give me the transformation matrix from a vertex v in the base contour to a vertex v' on the projection plane such as

v' = (P x M) * v

So, my question is:

How to create a transformation matrix which transforms a vertex v relative to a coordinate system with O = (0,0,0), xdir = (1,0,0), and ydir = (0,1,0) to a vertex relative to a coordinate system with O'=(ox, oy, oz) and xdir and ydir as two arbitrary perpendicular unit vectors?


  • I use 4x4 matrices
share|cite|improve this question
up vote 3 down vote accepted

You have $O\rightarrow O'$, $e_1\rightarrow e_1'$, $e_2\rightarrow e_2'$. Also using cross product to find the orthogonal, we have $e_1 \times e_2 =e_3\rightarrow e_1'\times e_2'$.

Explicitly -







$e_3'=e_1'\times e_2'$ [here $\times$ indicates cross product - and you need to append 1 to make it a 4-vector]


Here $xdir_x$, $xdir_y$ etc. are xdir and ydir's coordinates in the first system.

So you need to solve an equation in 4x4 matrices for getting the right transformation.

$\textbf{R}=\begin{pmatrix}e_1\\e_2\\e_3\\O\end{pmatrix}$, $\textbf{S}=\begin{pmatrix}e_1'\\e_2'\\e_3'\\O'\end{pmatrix}$

To find the required transformation $\textbf{T}$, we have $\textbf{R}\textbf{T}=\textbf{S}$ and so $\textbf{T}=\textbf{R}^{-1}\textbf{S}$.

share|cite|improve this answer
Edited to remove some typos. – KalEl Aug 20 '10 at 23:44
Thanks, that does the trick! – sum1stolemyname Aug 23 '10 at 6:20
Glad it helped :) – KalEl Aug 23 '10 at 8:56

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.