3
$\begingroup$

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

1 Answers 1

3

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

  • 0
    Edited to remove some typos.2010-08-20
  • 0
    Thanks, that does the trick!2010-08-23
  • 0
    Glad it helped :)2010-08-23