简体   繁体   English

获取由3d多边形包围的点

[英]Get points enclosed by a 3d polygon

I have a polygon that lies on a 3D plane. 我有一个位于3D平面上的多边形。 i want to get all points enclosed by this polygon.can anyone help me ? 我希望得到这个多边形所包含的所有点。任何人都可以帮助我吗? i can make a 3D scan line algorithm by replacing the scan lines by planes and get the intersection of planes with my polygon but i want a faster solution. 我可以通过用平面替换扫描线来制作3D扫描线算法,并获得与我的多边形的平面的交叉但我想要更快的解决方案。 Thanks in advance. 提前致谢。

One approach that I can see right now is to shoot an 我现在能看到的一种方法是射击 random 随机 arbitrary ray from each point that you want to verify and count how many times it intersects with the surface of your 3d mesh. 来自您要验证的每个点的任意光线,并计算它与3d网格曲面相交的次数。 If it is odd - it is inside, if even - outside. 如果它是奇怪的 - 它在里面,如果是偶数 - 在外面。

If your polygon is convex, then you can use the following approach: 如果多边形是凸的,则可以使用以下方法:

Each face of the polygon is part of a plane given by the equation ax + by + cz = d . 多边形的每个面都是由方程ax + by + cz = d给出的平面的一部分。 Find this equation for all faces, modify them to < d or > d depending on which relation describes points on the inside of the polygon, then solve this system of linear inequalities. 找到所有面的这个等式,根据哪个关系描述多边形内部的点,将它们修改为< d> d ,然后求解这个线性不等式系统。 This should give you a set of relations for x, y, and z that only points inside the polygon satisfy. 这应该给你一组x,y和z的关系,只有多边形内的点满足。

CygnusX1's answer is the standard point-in-a-polygon test, and can be modified for a variety of different systems (eg. I have a version coded for working on a spheroid). CygnusX1的答案是标准的多边形点测试,可以针对各种不同的系统进行修改(例如,我有一个编码用于处理椭球体的版本)。 The main trick when adapting it is deciding on the ray direction. 适应它的主要技巧是决定光线方向。 'Abitrary' sa much better word than 'random'. 'Abitrary'比'随机'更好。 For 2d Euclidean work I would shoot it in a direction parallel to one of the axes (and perpendicular to the other). 对于2d欧几里德的工作,我会在平行于其中一个轴(并垂直于另一个轴)的方向上拍摄它。 For a sphere, you use one of the poles. 对于球体,您使用其中一个极点。 For a 2d planar polygon in 3d, then I would be tempted to choose a line that is perpendicular to one of the axes. 对于3d中的二维平面多边形,那么我很想选择一条垂直于其中一条轴的直线。

Or I would transform my coordinates so that all calculations are in the plane. 或者我会转换我的坐标,以便所有计算都在平面上。 This will greatly simplify the actual point-in-polygon test. 这将大大简化实际的多边形点测试。 I think this will also be faster (significantly so for large polygons and many tests): each polygon corner only needs to be transformed once, but it will be used in two tests per point-in-polygon test. 我认为这也会更快(对于大型多边形和许多测试而言也是如此):每个多边形角只需要转换一次,但是每个多边形点测试将在两个测试中使用它。

Project your polygon onto the (x,y)-plane. 将多边形投影到(x,y)平面上。 Now it's a 2-D problem. 现在这是一个二维问题。 Each point (x,y) inside the 2-D projection represents a point (x,y,z) inside the 3-D polygon. 2-D投影内的每个点(x,y)表示3-D多边形内的点(x,y,z)。 Note: If your plane is perpendicular to the (x,y)-plane, this won't work; 注意:如果您的平面垂直于(x,y)平面,这将不起作用; and if it is nearly perpendicluar, you will get a loss of precision. 如果它几乎是垂直的,你会失去精确度。 So in practice, you would project onto the coordinate plane that is least perpendicular to your 3-D plane. 因此,在实践中,您将投射到与您的三维平面最不垂直的坐标平面上。

I have seen something similar implemented using one of matplotlib/scipy/numpy. 我已经看到使用matplotlib / scipy / numpy之一实现了类似的东西。 I can't exactly remember the algorithm however, see whether this helps. 我不能完全记住算法,但看看是否有帮助。

"yes it's a convex 3p polygon ,but it all its points lie in the same plane" “是的,它是一个凸3p多边形,但它的所有点都在同一个平面上”

In that case - just convert the polygon and all the test points into 2D local coordinates of the plane and use a 2D algorithm: 在这种情况下 - 只需将多边形和所有测试点转换为平面的2D局部坐标,并使用2D算法:

  • 2D ray shooting: You can still use similar algorithm to my 3d suggestion - shoot 2D rays originating from your test point and count how many times you hit the border of your polygon. 2D射线拍摄:你仍然可以在我的3D建议中使用类似的算法 - 拍摄源自测试点的2D光线,并计算你击中多边形边界的次数。

  • Linear inequalities: If your polygon is convex, you can follow suszterpatt's approach, with your polygon defined as an intersection of halfplanes ax+by<d 线性不等式:如果你的多边形是凸的,你可以遵循suszterpatt的方法,你的多边形被定义为半平面的交叉点ax+by<d

Further reading: 进一步阅读:

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

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