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

发布于 2024-11-16 06:23:09 字数 668 浏览 3 评论 0原文

我一直致力于网格库的开发。我想添加一个功能,以便它可以检测某个点是否位于 3D 网格内部。

我尝试过类似光线投射算法的东西。

但问题是, 在我的算法中,为了测试可能性,我将点沿 Z 轴投影到平面上。如果投影点在四边形/三边形内并且投影点的 z 值大于原始点的 Z 值,我将计算面。如果不是,我不会。如果总计数为奇数,则意味着该点位于 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);
}
}

如果该算法中的投影点等于该面上的顶点,则它将被多次计数,因为相同的顶点将被 4 个四边形/许多三角形共享。是否有更好的算法。 我应该如何避免这种过度计算???如果我跳过投影点作为面上顶点的可能性。,我将不会得到正确的结果。

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.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

墨洒年华 2024-11-23 06:23:09

处理这种情况的通常方法是对整个系统应用小的变换(旋转或剪切变换)。在某些情况下(至少在 2d 中),您甚至不需要知道变换的确切数量,但您可以象征性地执行此操作并相应地调整算法。

在你的情况下,我可能会首先检查你的光线是否击中顶点(或边缘,这会引起相同的问题,因为这次击中至少会被计算两次)。如果是这样,我会稍微修改您的投影方向,然后再次进行测试。由于更改投影方向可能需要对算法进行重大更改,因此您可以通过对系统的所有点应用小旋转(使用预先计算的旋转矩阵)来实现此目的。

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.

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.

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