计算CUDA中两个三角形之间的角度
我想计算 3D 空间中两个三角形之间的角度。这两个三角形总是恰好共享两个点。例如
三角形1:
Point1 (x1, y1, z1),
Point2 (x2, y2, z2),
Point3 (x3, y3, z3).
三角形2:
Point1 (x1, y1, z1),
Point2 (x2, y2, z2),
Point4 (x4, y4, z4).
有没有办法在CUDA中有效地计算它们之间的角度?
I wanted to calculate the angle between two triangles in 3D space. The two triangles will always share exactly two points. e.g.
Triangle 1:
Point1 (x1, y1, z1),
Point2 (x2, y2, z2),
Point3 (x3, y3, z3).
Triangle 2:
Point1 (x1, y1, z1),
Point2 (x2, y2, z2),
Point4 (x4, y4, z4).
Is there a way to calculate the angle between them efficiently in CUDA?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于每个平面,您需要构造它的法线向量(垂直于该平面中的所有线)。最简单的方法是求三角形中两条不平行线的叉积。 (例如(P3-P1)X(P2-P1)和(P4-P1)X(P2-P1)。
将它们归一化。
这两个方向的点积向量给出角度的余弦。
棘手的一点是要注意退化三角形!如果定义任一三角形的所有 3 个点都是共线的(该三角形只是一条线),那么您所要求的是未定义的,并且叉积将除以零,您需要决定在这种情况下要做什么,
因为您尝试在 GPU 上执行此操作,所以理想情况下您会希望编写没有任何分支的函数。担心效率。这意味着您应该尝试使用三元
A : C
来测试退化三角形,而不是使用if
子句。For each plane, you need to construct it's normal vector (perpendicular to all lines in that plane). The simple way to do that is to take the cross-product of two non-parallel lines in the triangle. (ex (P3-P1) X (P2-P1) and (P4-P1) X (P2-P1).
Normalize those.
The dot product of those two direction vectors gives you the cosine of the angle.
The tricky bit is to watch out for degenerate triangles! If all 3 points defining either triangle are colinear, (that triangle is just a line) then what you're asking for is undefined, and the cross-product will divide by zero. You need to decide what you're going to do in that case.
Since you're trying to do this on a GPU, you'll ideally want to write this function without any branches, if you're concerned about efficiency. That would mean instead of testing for degenerate triangles with an
if
clause, you should try and do it with a ternaryA ? B : C
三角形之间的角度与每个三角形的三个点定义的平面之间的角度相同。
由于点 1 或点 2 都位于两个平面内,因此计算出从其中一个点到点 3,然后到点 4 的方向余弦。然后,这两条线之间的角度的余弦就是乘积之和相应的方向余弦。
The angle between the triangles is the same as the angle between the planes defined by the three points of each triangle.
Since both Point 1 or Point 2 lie in both planes, figure out the direction cosines from one of those points to Point 3, and then to Point 4. Then, the cosine of the angle between these two lines is just the sum of the products of the corresponding direction cosines.