Jump to content
  • Advertisement
Sign in to follow this  
lawnjelly

Converting Plane to Triangle

This topic is 2342 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


Link to 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?blink.png

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

Share this post


Link to 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


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

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!