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

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

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

##### Share on other sites
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 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 on other sites
Nevermind, I found Normalize in Microsoft.Xna.Framework.Vector3.Normalize() as well as Cross() and "Distance()" instead of Length.

##### 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 on other sites
Thanks. Even if the OP doesn't come back, someone searching in the future might find the images useful though.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×