# Constructing an Extrusion between two non-parallel planes

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?

Clarifications

• I use 4x4 matrices
-

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_1=(1,0,0,1)$

$e_2=(0,1,0,1)$

$e_3=(0,0,1,1)$

$O=(0,0,0,1)$

$e_1'=(xdir_x,xdir_y,xdir_z,1)$

$e_2'=(ydir_x,ydir_y,ydir_z,1)$

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

$O'=(o_x,o_y,o_z,1)$

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}$.

-
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