# Converting Plane to Triangle

This topic is 2435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
Hidden
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?

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.

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?

##### Share on other sites
You are doing something similar to the Gramm-Schmidt process - look it up to see how it avoids the singularities.

##### Share on other sites
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.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011722
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!