三角形内的顶点 - 碰撞检测
我正在尝试检查顶点是否在三角形内,但我在为 3D 环境开发 CCW 函数时遇到问题。
对于 2D 环境 CCW 函数将是这样的
//CCW calculates the cross produt
double CCW ( point A , point B , point C ) {
return (B.x-A.x) * (C.y-A.y) - (B.y-A.y) * (C.x-A.x);
}
//The other part is designed to work on 3D
typedef struct{
double x;
double y;
double z;
}Point;
int inTriangle(point A, point B, point C, point D){
Point E;
E.x = (A.x + B.x + C.x)/3;
E.y = (A.y + B.y + C.y)/3;
E.z = (A.z + B.z + C.z)/3;
return ( CCW(A,B,D) * CCW (A,B,E) > 0 &&
CCW(B,C,D) * CCW(B,C,E) > 0 &&
CCW(A,C,D) * CCW(A,C,E) );
}
I am trying to check whether a Vertex is inside an triangle , but i have problems developping a CCW function for a 3D enviroment.
for a 2D enviroment CCW function would be like that
//CCW calculates the cross produt
double CCW ( point A , point B , point C ) {
return (B.x-A.x) * (C.y-A.y) - (B.y-A.y) * (C.x-A.x);
}
//The other part is designed to work on 3D
typedef struct{
double x;
double y;
double z;
}Point;
int inTriangle(point A, point B, point C, point D){
Point E;
E.x = (A.x + B.x + C.x)/3;
E.y = (A.y + B.y + C.y)/3;
E.z = (A.z + B.z + C.z)/3;
return ( CCW(A,B,D) * CCW (A,B,E) > 0 &&
CCW(B,C,D) * CCW(B,C,E) > 0 &&
CCW(A,C,D) * CCW(A,C,E) );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想知道顶点是否直接位于三角形的平面内及其边界内(即,在三角形的表面上),您可以分别检查这两件事。首先检查顶点是否位于三角形的平面内。然后您应该能够将三角形和顶点投影为 2D 并使用您的 2D 方法。
它还具有消除大量顶点的好处,因为它们不在三角形的平面上,这是一个快速计算。
If you want to know if the vertex lies directly in the plane of the triangle and inside the bounds of it (i.e., on the surface of the triangle), you can check those two things seperately. First check to see if the vertex lies in the plane of the triangle. Then you should be able to project the triangle and vertex into 2D and use your 2D method.
It also has the benefit of eliminating a lot of vertices because they are not on the plane of the triangle, which is a quick computation.
如果该点位于三角形的平面上,您可以使用此处描述的重心方法。
If the point is on the plane of the triangle, you may use a barycentric method described here.
要检查该点是否在三角形平面上,您可以编写三角形平面方程。使用 3 个点编写很简单,而且它是线性的,因此计算速度会非常快。
要了解如何编写方程,请查看 http://en.wikipedia.org/wiki/Plane_(geometry) ),
要确定该点是否在平面上,只需检查它是否满足平原方程并具有足够的精度。
To check if the point is on triangles's plane you can write the triangle's plane equation. It it simple to write using 3 points and it's is linear so the computations will be very fast.
To understand how to write the equation check http://en.wikipedia.org/wiki/Plane_(geometry), it's simple.
To determine if the point is in the plane simple check that it's satisfy plain's equation with enough for you accuracy