Jump to content
  • Advertisement
Sign in to follow this  
jonathanplumb

Help finding 3D points based on a triangle in 3D space

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

I've been trying like mad to solve this problem, but heard this problem might be REAL easy using a matrix. (FYI, I'm using C# and have access to XNA Framework, so you can reference either).

Basically, I have 3 points in 3D space (that obviously create a triangle). The triangle is generally vertical, however the input can be rotated so the triangle can essentially be in any position and rotation.

I need to create a square with 4 points that is perpendicular to the triangle. So P1 and P2 of the triangle should be used for the plane position and P3 should be used as the "up" facing vector.

The line drawn by P1 and P2 should divide the square perfectly in half.

Any help would be great ... I've been white-boarding the triangles for hours and am just pulling out my hair.

If you're having issues seeing what I'm talking about, the application is for 3 points on the front, top, and back of a head. I need the left 2 points of the square to represent the front and back of an object off the left-side of the head and the right 2 points of the square to represent the front and back of an object off the right-side of the head.

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Really, all you need for this is the (unit-length) normal of the triangle, which can be computed as:
Vector3 normal = normalize(cross(P2 - P1, P3 - P1));
The points of interest can then be computed as follows:
float width = length(P2 - P1);
float half_width = width * .5;
vector3 square_verts[4] = {
P1 - normal * half_width,
P1 + normal * half_width,
P2 - normal * half_width,
P2 + normal * half_width
}
That's assuming I'm understanding your question correctly, of course.

Share this post


Link to post
Share on other sites
Where do you get the normalize() and cross() functions? I looked them up and they say System.Windows.Vector, but I've included System.Windows and no Vector structure OR namespace exists within Windows... (C# .NET 4.0)

Share this post


Link to post
Share on other sites
Whoa, those are some nice images :)

Still, I think you'll find that what you've described is basically the same as what I posted earlier. (And anyway, the OP hasn't returned to this thread, so I'm guessing he's either figured it out or given up by now.)

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!