简体   繁体   中英

Finding left/right vertices to a point in a triangle in 3D

Given a triangle in 3D and a point on one of its edges, I want to find out which of the vertices of that edge is to the left of that point, and which is to the right.

Please see the image below:

In this image, vertices v2 and v3 are always positioned as shown. There is also a line segment between v3 and v2 . The problem is with vertices v0 and v1 , which may be given in a swapped order. I want to find out whether v0 is to the 'left' or 'right' of v3 so that I can enforce v0 to always be to its left and v1 to always be to its right.

Since this problem is in 3D I am not sure how to efficiently compute the relative positions of the vertices. Do I first reduce this to a 2-dimensional problem (and if so, how) or is there another way?

in 3d the "left" and "right" is dependent to the position of the observer (lets call this position P ). Imagine that you are viewing that triangle from the other side , then the left and right are reversed. So viewing from position P you need to determine if the vertices are clockwise or anti-clockwise.

To do that you can compute this:

N = normalize( cross( v0 - v2, v1 - v2 ) );
PV = normalzie( P - v2 );
if( dot( PV, N ) > 0.0 )
{
    //anticlockwise , so you are viewing the picture like in your drawing, then v0 is on the left of vector v3v2, and v1 is on the right
}
else
{
    //clockwise, v0 is on the right
}

Note that if dot product is almost/or 0 then P is on the same plane as your triangle.

As clarified in the comments, "left" and "right" (or any other ordering of v0 and v1 ) depends on some reference. You mentioned you know the triangle's normal vector (call it N ) - that can be used for such a reference.

Let's say that the normal vector points towards the viewer in your example image. Then, compute the vector product of v2 - v3 and v0 - v3 . This will either point to the same half-space as the normal (meaning v0 is "to the left"), or to the opposite half-space (meaning v0 is "to the right").

Since N is normal to the triangle's plane, a vector v points to the same half-space if the angle between v and N is less than 90 degrees; in other words, if the dot product of v and N is positive.

These together give you the ordering criterion you need.

Find the cross product of vectors v2-v3 and v1-v2. Deduce the direction from the direction of the product.

Whether the vector is pointing upwards from the plane or downward.

This is if I have correctly understood your definition of right and left.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM