Jump to content

  • Log In with Google      Sign In   
  • Create Account


Converting Plane to Triangle


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 lawnjelly   Members   -  Reputation: 429

Like
0Likes
Like

Posted 20 March 2012 - 03:58 AM

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?

Sponsor:

#2 lawnjelly   Members   -  Reputation: 429

Like
0Likes
Like

Posted 20 March 2012 - 04:48 AM

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. Posted Image

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?

#3 Crowley99   Members   -  Reputation: 178

Like
0Likes
Like

Posted 20 March 2012 - 09:42 AM

You are doing something similar to the Gramm-Schmidt process - look it up to see how it avoids the singularities.

#4 lawnjelly   Members   -  Reputation: 429

Like
0Likes
Like

Posted 21 March 2012 - 12:45 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS