Jump to content
• ### What is your GameDev Story?

• Advertisement

# Converting Plane to Triangle

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

If you intended to correct an error in the post then please contact us.

## 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 this post

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

#### Share this post

##### Link to post
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 this post

##### 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 this post

##### 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.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 11
• 15
• 11
• 11
• 9
• Advertisement
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015829
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!