计算CUDA中两个三角形之间的角度 [英] Calculate the angle between two triangles in CUDA

查看:69
本文介绍了计算CUDA中两个三角形之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算3D空间中两个三角形之间的角度.两个三角形将始终恰好共享两个点.例如

I wanted to calculate the angle between two triangles in 3D space. The two triangles will always share exactly two points. e.g.

三角形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中是否可以有效地计算它们之间的角度?

Is there a way to calculate the angle between them efficiently in CUDA?

推荐答案

对于每个平面,您需要构造其法线向量(垂直于该平面中的所有线).最简单的方法是取三角形中两条非平行线的叉积.(例如(P3-P1) X (P2-P1)和(P4-P1) X (P2-P1).

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).

标准化这些.

这两个方向矢量的点积为您提供角度的余弦.

The dot product of those two direction vectors gives you the cosine of the angle.

棘手的是要当心退化的三角形!如果定义这三个三角形的所有3个点都是共线的(那个三角形只是一条线),则您要的内容不确定,叉积将被零除.在这种情况下,您需要决定要做什么.

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.

由于您正在尝试在GPU上执行此操作,因此,如果您担心效率问题,那么理想情况下,您将希望编写此函数时不带任何分支.这意味着您应该尝试使用三元 A而不是使用 if 子句来测试退化的三角形,而不是使用它?B:C

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

这篇关于计算CUDA中两个三角形之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆