简体   繁体   English

验证体积/ 3D空间中的点

[英]Verification of a Point in a Volume/ 3D space

I've been working on development of a mesh library.I want to add a feature such that it will detect if a point is located inside of a 3D mesh or not. 我一直在致力于网格物体库的开发,我想添加一个功能,使其可以检测点是否位于3D网格物体内部。

I've tried something like ray casting algo. 我已经尝试过类似射线铸造算法的东西。

But the problem is., In my algo., to test the possibility,I project the point onto plane along Z axis.If projected point is within the quad/tri and z value of projected point is greater that that of original point's Z value, I'll count the face.If not I wont.If the total count is ODD then that means the point is inside the 3D volume. 但是问题是,在我的算法中,为了测试这种可能性,我将点沿Z轴投影到平面上。如果投影点在quad / tri内,并且投影点的z值大于原始点的Z值,我将计算人脸。如果不是,我将不计算。如果总计数为ODD,则表示该点在3D体积内。

ispointinside3Dspace(point,facelist)
{
for faces in the object:
{
  project the point onto the face along Z axis;
  if( projected point is within the face):
  {
        if( projectedpoint->z > point->z ):
        {
           face_hit++;
        }
   }
}
if(face_hit%2==1)
{
   return(1);
}
else
{
   return(0);
}
}

If the projected point in this algo is equal to vertex on that face., it will be counted more than once as same vertex will be shared by 4 quads/many tris.Is there any better algo. 如果该算法中的投影点等于该面上的顶点,则将不止一次计数,因为同一顶点将被4个quad /许多tris共享。是否有更好的算法。 How should I avoid this overcounting???If I skip the possibility of projected point being a vertex on a face.,I wont get proper results. 我应该如何避免这种过度计算?如果我忽略投影点是面上顶点的可能性,我将无法获得正确的结果。

The usual approach for this kind of situations is to apply a small tranformation to the whole system (either a rotation or a shear transform). 对于这种情况,通常的方法是对整个系统应用较小的变换(旋转或剪切变换)。 In some cases (at least in 2d) you don't even need to know the exact amount of your transformation but you can do this symbolically and adjust the algorithm accordingly. 在某些情况下(至少在2d中),您甚至不需要知道变换的确切数量,但是可以象征性地进行此操作并相应地调整算法。

In your case, I would probably first check, if your ray hits a vertex (or an edge, which poses the same problem since this hit would be counted at least twice). 在您的情况下,我可能首先会检查您的射线是否击中了顶点(或边缘),因为同样的问题,该命中至少会被计算两次,所以会出现相同的问题。 If so, I'd modify the direction of your projection by a small amount and do the test again. 如果是这样,我会少量修改您的投影方向,然后再次进行测试。 Since changing the projection direction would probably require major changes in your algorithm, you can do this alternatively by applying a small rotation (using a precalculated rotation matrix) to all points of your system. 由于更改投影方向可能需要对算法进行重大更改,因此您可以通过对系统的所有点进行较小的旋转(使用预先计算的旋转矩阵)来进行替换。

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

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