views:

56

answers:

3

The general problem is projecting a polygon onto a plane is widely solved, but I was wondering if anybody could make some suggestions for my particular case.

I have a planar polygon P in 3-space and I would like to project it onto the plane through the origin that is orthogonal to the unit vector u. The vertices of P and the coordinates of u are the only data I have (all w.r.t. the standard basis of R^3).

However, I don't just want the projected coordinates. I actually would like to find an orthonormal basis of the plane orthogonal to u and to then find the coordinates of the projected vertices in this new basis.

The basis itself doesn't matter so long as it is orthonormal. So really I need to do two things within the framework of the GNU Scientific Library:

(1) Find two orthonormal basis vectors for the homogeneous plane orthogonal to the unit vector u.

(2) Find the coordinates in this basis of the projection of P's vertices onto the plane.

Any ideas on how to do this using gsl?

+2  A: 

I haven't used GSL, but you only need to use dot-product, cross-product, and normalizing to get the result.

(1) Pick any vector r that is not a multiple of u. Let v = the normalized cross-product of r and u. Let w = the cross-product of u and v. Your orthonormal basis vectors are v and w.

(2) To project a vertex a to this plane, it's (a dot v) * v + (a dot w) * w. (The v coordinate is a dot v, the w coordinate is a dot w)

To help think about how this works, choose u = <1,0,0> and r = <3,0,5> to start, and visualize the 3-d vectors.

Tom Sirgedas
Thanks very much!
Zach Conn
+1  A: 

The question is missing one piece of information, namely the direction of one of the basis vectors. The question says the basis vectors must be orthonormal (i.e., unit length and perpendicular to eachother) and of course perpendicular to u (since they are in a plane perpendicular to u), but that still leaves them free to rotate around u to any angle.

Matt S
Yes, you're right. There is freedom in choosing the basis. All I needed was *some* such basis, not any particular one.
Zach Conn
+1  A: 

To compute vectors v and w so that u,v,w are an orthonormal basis:

void    make_basis3( const double* u, double* v, double* w)
{  double   h[3];
double  d;
double  s = ( u[0] > 0.0) ? 1.0 : -1.0;
double  f = s/(s+u[0]);
h[0] = u[0]+s;  h[1] = u[1]; h[2] = u[2];
d = f*h[1]; v[0] = -d*h[0]; v[1] = 1.0-d*h[1]; v[2] = -d*h[2];
d = f*h[2]; w[0] = -d*h[0]; w[1] = -d*h[1]; w[2] = 1.0-d*h[2];
}

Here u is assumed to be of length 1.

What's going on here is that the first few lines compute a vector h such that the householder matrix based on h (ie Q=I - 2*h*h'/h'*h where ' is transpose) maps u to (+-1,0,0) and the last two lines apply this matrix to (0,1,0) to get v and to (0,0,1) to get w. Since Q is orthogonal and symmetric, u,v,w is an orthonormal basis.

I think this method is preferable to using cross products because: it's shorter, it's more efficient, it's less susceptible to rounding errors and it generalizes to higher dimensions.

If P is a point, P.v and P.u are coordinates of P projected onto the plane orthogonal to u, through the origin.

dmuir