计算CUDA中两个三角形之间的角度

发布于 2024-08-19 10:18:23 字数 297 浏览 7 评论 0原文

我想计算 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又怨 2024-08-26 10:18:23

对于每个平面,您需要构造它的法线向量(垂直于该平面中的所有线)。最简单的方法是求三角形中两条不平行线的叉积。 (例如(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 ternary A ? B : C

楠木可依 2024-08-26 10:18:23

三角形之间的角度与每个三角形的三个点定义的平面之间的角度相同。

由于点 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文