Hi,
This seems inherently a simple task, but I'm having real problems with it!

I have a plane, let's call it P, with its direction defined by its normal vector n, and the camera distance, d, both of which I know:

 P: \textbf{n}.\textbf{x} = d

Upon P, lie a set of coordinates:
<br />
C = \left(\begin{array}{ccc}<br />
x_1 &  & x_n\\<br />
y_1 & ... & y_n\\<br />
z_1 &  & z_n\\<br />
\end{array}\right)<br />

I need to rotate these coordinates onto the x-y plane to give a top-down view. I can't move the camera - it's fixed.

My initial attempt was to work out the rotation angles from the normal (x-rotation = phi, y-rotation = theta and z-rotation = psi):

<br />
\phi = cos^{-1}( n_z )<br />
\psi = sin^{-1}( \frac{-n_x}{sin(\phi}})<br />

I could then do:

<br />
C' = R_x(\phi) . R_z(\psi) . \left(\begin{array}{c}x_i\\y_i\\z_i\end{array}\rig  ht)<br />

(where (xi,yi,zi) is each coordinate in C).

For some reason, this worked sometimes, but other times the angle was completely wrong!

So I tried something else. When the P is rotated to align with the x-y plane we have:

<br />
R .<br />
\left(\begin{array}{c}<br />
X\\<br />
Y\\<br />
Z<br />
\end{array}\right)<br />
 = <br />
\left(\begin{array}{c}<br />
X'\\<br />
Y'\\<br />
0<br />
\end{array}\right)<br />

And we know the combined x-y-z rotation matrix:


For ease of reading, hereafter we have:
<br />
	r_3 = [ a, b, c ], where<br />
	\begin{array}{l}<br />
		a = \sin(\theta)\sin(\phi) \\<br />
		b = -\sin( \theta )\cos( \phi ) \\<br />
		c = \cos( \theta )<br />
	\end{array}<br />

Since we don't know what X' and Y' will be, we only use the bottom row of the rotation
matrix. For three coordinates on the original plane, we then have 3 equations with which
to find phi and theta:

<br />
	\begin{array}{l}<br />
		a.x_1 + b.y_1 + c.z_1 = 0 \\<br />
		a.x_2 + b.y_2 + c.z_2 = 0 \\<br />
		a.x_3 + b.y_3 + c.z_3 = 0 \\<br />
	\end{array}<br />

Which gives rise to the linear system
<br />
	A = \left(<br />
	\begin{array}{ccc}<br />
		x_1 & y_1 &  z_1 \\<br />
		x_2 & y_2 &  z_2 \\<br />
		x_3 & y_3 &  z_3 \\<br />
	\end{array}<br />
	\right)<br />
<br />
	x = <br />
	\left(<br />
	\begin{array}{c}<br />
		a \\<br />
		b \\<br />
		c \\<br />
	\end{array}<br />
	\right)<br />
<br />
	Ax = \textbf{0}<br />

Which we solve using Singular Value Decomposition to get a,b and c (take the last column of the "V" matrix). We can then work out phi and theta:

<br />
\begin{array}{l}<br />
	\theta = cos^{-1}( c )\\<br />
	\phi   = cos^{-1}( \frac{b}{sin(\theta)} )<br />
\end{array}<br />

These values were then subbed into the compound rotation matrix given above, and psi was set to 0 giving R. Finally I multiplied each coordinate by R:
<br />
C' = R(\phi, \theta, \psi) \,. \, C<br />

This again, didn't work. Although I'm convinced that in theory it should. Is anyone able to spot any errors I might have made? Or can anyone contribute a different idea? This has taken me the last week of work so any advice is most gratefully received!!!
Thanks!