[英]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. 给定3D三角形,并且在其边缘之一上有一个点,我想找出该边缘的哪个顶点在该点的左侧,而哪个在右侧。
Please see the image below: 请参见下图:
In this image, vertices v2
and v3
are always positioned as shown. 在此图像中,顶点v2
和v3
始终如图所示放置。 There is also a line segment between v3
and v2
. v3
和v2
之间还有一条线段。 The problem is with vertices v0
and v1
, which may be given in a swapped order. 问题是顶点v0
和v1
可能以交换顺序给出。 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. 我想找出v0
是位于v3
的“左侧”还是“右侧”,以便我可以强制v0
始终位于其左侧,而v1
始终位于其右侧。
Since this problem is in 3D I am not sure how to efficiently compute the relative positions of the vertices. 由于此问题在3D中,因此我不确定如何有效地计算顶点的相对位置。 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
). 在3d中,“左”和“右”取决于观察者的位置(以下称为此位置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. 因此,从位置P观察时,您需要确定顶点是顺时针还是逆时针。
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. 请注意,如果dot
积几乎为/或0,则P
与三角形位于同一平面上。
As clarified in the comments, "left" and "right" (or any other ordering of v0
and v1
) depends on some reference. 如评论中所阐明的,“ left”和“ right”(或v0
和v1
任何其他顺序)取决于某些参考。 You mentioned you know the triangle's normal vector (call it N
) - that can be used for such a reference. 您提到您知道三角形的法线向量(称为N
)-可以用作此类参考。
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
. 然后,计算v2 - v3
和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"). 这将指向与法线相同的半空间(意味着v0
在“左侧”),或者指向相反的半空间(意味着v0
在“右侧”)。
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; 由于N
垂直于三角形的平面,因此如果v
与N
之间的角度小于90度,则向量v
指向相同的半空间;否则,向量v
指向相同的半空间。 in other words, if the dot product of v
and N
is positive. 换句话说,如果v
和N
的点积为正。
These together give you the ordering criterion you need. 这些共同为您提供所需的订购标准。
Find the cross product of vectors v2-v3 and v1-v2. 求向量v2-v3和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. 这是如果我正确理解了您对左右的定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.