Get points enclosed by a 3d polygon

断了今生、忘了曾经 提交于 2020-01-02 09:28:15

问题


I have a polygon that lies on a 3D plane. 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. Thanks in advance.


回答1:


"yes it's a convex 3p polygon ,but it all its points lie in the same plane"

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

  • 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

Further reading:

  • http://en.wikipedia.org/wiki/Point_in_polygon
  • http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
  • http://paulbourke.net/geometry/insidepoly/



回答2:


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. If it is odd - it is inside, if even - outside.




回答3:


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. 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. This should give you a set of relations for x, y, and z that only points inside the polygon satisfy.




回答4:


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). The main trick when adapting it is deciding on the ray direction. 'Abitrary' s a much better word than 'random'. For 2d Euclidean work I would shoot it in a direction parallel to one of the axes (and perpendicular to the other). 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.

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.




回答5:


Project your polygon onto the (x,y)-plane. 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. Note: If your plane is perpendicular to the (x,y)-plane, this won't work; 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.




回答6:


I have seen something similar implemented using one of matplotlib/scipy/numpy. I can't exactly remember the algorithm however, see whether this helps.



来源:https://stackoverflow.com/questions/5153816/get-points-enclosed-by-a-3d-polygon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!