Converting Plane to Triangle

Started by
2 comments, last by lawnjelly 12 years, 1 month ago
This is probably really simple .. but

I find myself needing to generate an 'example' triangle from a plane:

CPlane
{
Vec3 m_Normal;
float m_fConstant;
};
CTriangle
{
Vec3 a;
Vec3 b;
Vec3 c;
};


I know there are infinite possible positions of triangle on the plane, I just need to generate an 'example' triangle to define the plane for some 3rd party code, and it MUST NOT have duplicate corners (so the plane is undefined).

First point can just be the plane normal times the constant. For the 2nd and 3rd points I just need to move out from the first point along 2 axes (perpendicular? to the normal).

My first thoughts were, is it possible to use the 'reflection' approach in 3d:

i.e. in 2d
2, 1
can be reflected to
-1, 2
or 1, -2

to get vectors at 90 degrees

so then I was thinking about taking the normal and doing something like:

-y, x, -z
y, -x, -z
etc

Then I realised there could be problems e.g.
0, 0, 1

would generate
0, 0, -1 and
0, 0, -1

so both 'rotated axes' would be the same.

Is there a simple generalized solution to this problem, or would I need to use quaternions or matrices?
Advertisement
I *think* I may have one possible solution, not probably the best but:

If I do the cross product of the normal with a 'random' vector (just something different to the normal, e.g. normal.z, normal.x, normal y) then I should get a vector 'B' perpendicular to both.

If I then do a cross product of the normal and vector 'B', then I'd get a 3rd vector 'C' perpendicular to both. Then I just add B and C to the first point on the plane to get the 2nd and 3rd corners of the triangle.

Would that work?blink.png
Ok I've come up with a possible solution, but I think there must be a better way this this:

1) Pick a random vector, different to the normal ..

e.g. z, x, y

2) Calculate vector B as the cross product between the normal and the random vector (it must therefore be perpendicular to both).

3) Calculate vector C as the cross product between the normal and vector B (perpendicular to both).

4) Add B to the first triangle corner to get the 2nd corner, and add C to the first triangle corner to get the 3rd corner.

This *seems* to be working, although there are cases where the polarity of 0.0 coordinates are getting switched, which are causing a few issues. mellow.png

I still am sure it must be possible to do even simpler just by the reflection method, perhaps with some case statements to determine which axes to reflect?
You are doing something similar to the Gramm-Schmidt process - look it up to see how it avoids the singularities.
Thanks for the pointer! I must admit most of the stuff I read from google went over my head, being a non-mathemagician, but think I'll find an easy to understand implementation eventually.

This topic is closed to new replies.

Advertisement