简体   繁体   English

Ray和3D Face Intersection

[英]Ray and 3D Face Intersection

I have a 3D face defined by n points ( v1 , v2 , v3 ,..., vn ), in 3D coordinates, and I have a ray of the equation: 我在3D坐标中有一个由n个点( v1v2v3 ,..., vn )定义的3D面,我有一个等式的光线:

P=P0+t(P1-P0) . P=P0+t(P1-P0)

where 0<=t<=1 . 其中0<=t<=1

Now, how to find the intersection point ( or lack of) between this ray and the face? 现在,如何找到此光线与人脸之间的交点(或缺点)?

Also, it would be great if there is an existing C# implementation on this? 此外,如果现有C#实现,那将会很棒吗?

Edit: The 3D face can be concave or convex. 编辑:3D面可以是凹面凸面。 All the points are coplanar. 所有要点都是共面的。

I suppose your 3D polygon is planar (otherwise it's not really a polygon and it's not well defined). 我想你的3D多边形是平面的(否则它不是真正的多边形,并且没有很好地定义)。 Therefore you can find a 2D orthonormal basis for this plane. 因此,您可以找到此平面的2D标准正交基础。 Which means you can use any 2D triangulation algorithm (you can find many c# implementations on the web) and go back to 3D using your orthonormal basis. 这意味着您可以使用任何2D三角测量算法(您可以在Web上找到许多c#实现)并使用标准正交基础返回到3D。 This way you will get 3D triangles and will be able to easily do your ray-polygon intersection test by running multiple ray-triangle intersection tests. 通过这种方式,您将获得3D三角形,并且可以通过运行多个光线 - 三角形相交测试轻松地进行光线 - 多边形相交测试。

Another way is perform a ray-plane intersection calculation. 另一种方法是执行射线平面相交计算。 Take the intersection point P, represent it using 2D coordinates with the above orthonormal basis. 取交点P,使用具有上述标准正交基础的2D坐标表示它。 In addition, as in the previous solution, represent your polygon in 2D using the same basis. 此外,与前面的解决方案一样,使用相同的基础在2D中表示多边形。 Then run any "is point in polygon" 2D algorithm and you will get your results. 然后运行任何“多边形点”2D算法,您将得到您的结果。

Update : Here is the math You can take any two points on the plane p1, p2 (eg two of the polygon's points) and take the vector u = p2 - p1. 更新 :这是数学你可以在平面p1,p2上取任意两个点(例如,多边形的两个点)并取矢量u = p2 - p1。 Normalize it, and it is the first basis vector. 将其标准化,它是第一个基础向量。 Then you take the plane's normal N and calculate v = cross_product(u , N) and normalize v. This is the second basis vector. 然后你取平面的法线N并计算v = cross_product(u,N)并标准化v。这是第二个基矢量。 Note that both vectors have unit length and they are orthogonal to each other. 注意,两个矢量都具有单位长度并且它们彼此正交。 Therefore they form an orthonormal basis. 因此它们形成了标准正交基础。

Now define p1 to be the plane's origin. 现在将p1定义为平面的原点。 Then the translation to 2D of any point q on the polygon (q can be one of the polygon's vertices, or any other point on the polygon's plane): 然后将多边形上任意点q的二维平移(q可以是多边形顶点之一,或多边形平面上的任何其他点):

x = dot_product(q - p1, u)
y = dot_product(q - p1, v)

Here x,y are the point's 2D coordinates. 这里x,y是点的2D坐标。

So after translating everything to 2D and doing your 2D algorithms you can translate any 2D point (x, y) back to 3D like this: 因此,在将所有内容转换为2D并执行2D算法后,您可以将任何2D点(x,y)转换回3D,如下所示:

q = p1 + x * u + y * v

Here * is the scalar-vector product (x,y are the scalars and u,v are the vectors). 这里*是标量矢量积(x,y是标量,u,v是矢量)。

Alex. 亚历克斯。

If your points are not co-planar (ie the don't all lie on a single plane) then you need to sub-divide the surface into a set of planes and then do the line-polygon intersection for each plane. 如果您的点不是共面的(即,并非所有点都位于单个平面上),则需要将曲面细分为一组平面,然后对每个平面进行线 - 多边形交叉。 Better still, define a list of triangles and then do search on the line-triangle intersection results. 更好的是,定义一个三角形列表,然后搜索线 - 三角形交叉结果。

However, you don't say if your points define a faceted object (ie made of triangles) or define a set of control points for a curved surface. 但是,您不会说您的点是定义多面物体(即由三角形组成)还是为曲面定义一组控制点。 The former is handled by the above. 前者由上述处理。 If it's a curved surface, I think this in an incalulatable problem, that is, there is no trivial solution to the problem of determining the intersection of a line and a curved surface defined by a set of points. 如果它是一个曲面,我认为这是一个不可测量的问题,也就是说,确定由一组点定义的直线和曲面的交点的问题没有简单的解决方案。 The best you can do is to use an iterative process of finding the intersection point, but even this could lead to unstable searches (ie searches that never complete). 您可以做的最好的事情是使用迭代过程来查找交叉点,但即使这样也可能导致搜索不稳定(即从未完成的搜索)。

I think converting to a set of triangles is the best answer. 我认为转换成一组三角形是最好的答案。

您正在使用光线多边形交叉算法,这里是指向它的图形Gems条目的链接: http//www-graphics.stanford.edu/courses/cs348b-98/gg/intersect.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM