2D Coordinates of Projection of 3D Vector onto 2D Plane 


*

*The plane $P$ is passing through the origin and has normal $n$. 

*$u$ is a 3D vector and $u'$ its projection onto $P$: $u' = u - \langle u,n \rangle n$ (assuming $n$ has unit length).

*$e'_1$ and $e'_2$ are 2D vectors that span $P$

*Suppose that $e'_1$ and $e'_2$ are related to $e_1$ and $e_2$ by the same rotation as $n$ and $e_3$ (Maybe that's not very clear. What I want is: if I were to align $n$ and $e_3$, $e'_1$ and $e'_1$ should be aligned with $e_1$ and $e_2$ respectively).
My question is: How to find the 2D coordinates of $u'$ in $P$? That means, finding $e'_1$ and $e'_2$ and $a$ and $b$ such that $u'_{2D} = a*e'_1 + b*e'_2$. 
My question is similar to this one but without the projection part.
Thanks!
 A: Your goal should be finding a suitable $2\times3$ matrix which you multiply with your 3D vector to obtain the projected 2D vector.
I assume that $e_1, e_2, e_3$ are both unit length and orthogonal to one another, i.e. that you're dealing with an orthogonal coordinate system in 3D. All 3D vectors are assumed to be expressed in this coordinate system. Without orthogonality, you'd have trouble matchiung the relation of $e_1', e_2', n$ to that of $e_1,e_2,e_3$, as $n$ is orthogonal to $e_1',e_2'$.
You first need to find a vector $e_1'$ which should be unit length, lie in the plane, but may be rotated about the origin in an arbitrary way. One way to achieve this is by choosing an arbitrary vector $v$, and computing the cross product between $v\times n$. The resulting vector will always be orthogonal to $n$. If you are unlucky, $v$ might be parallel to $n$, in which case the cross product has length zero. So in the possible presence of numerical complications (i.e. rounding errors, so you won't get an exact zero), it might be easiest to try $e_1,e_2,e_3$ as $v$, and choose the result with maximal length. Then normalize its length to 1, and you have a suitable $e_1'$.
Next, you compute $e_2'$ as the cross product of $e_1'$ and $n$. Depending on the way $e_1,e_2,e_3$ relate to one another, you'll have to do this either in one or in the other order to end up with the correct sign for $e_1$. Simply try them out. The length of the result should already be unit length, at least if $n$ had unit length and $e_1'$ was chosen as described above.
Now that you have $e_1'$ and $e_2'$, you can simply use these as the rows of your desired projection matrix. The rationale here is as follows: the matrix times vector multiplication will compute two scalar products, which correspond to the portion of your input vector which lies in the direction of that vector, i.e. the length of the orthogonal projection along one direction. Take two of these, and you have coordinates in a coordinate system within the plane, obtained from orthogonal projection onto that plane.
