Visibility of polygons from an edge

北慕城南 提交于 2019-12-08 01:50:48

问题


Given is a 2D are with the polygons. I need to find out the polygons visible in a perpendicular line of sight from the a given line segment lying within that area. e.g.

  • Further,

    What can be the optimizations when the polygons have only vertical and horizontal edges.


回答1:


I'd suggest the following ...

  • Rotate the problem so your 'line of sight' segment is aligned to the x axis.
  • Find the (axis aligned) bounding rectangle (BR) of each polygon.
  • Sort the polygons using the Y coordinate of the bottom edge of each BR
  • Create a clipping 'range buffer' to mark the portions of the viewing segment that will be no longer visible.
  • For each polygon C (current) in the sorted list do ...
    1. Use C's left and right bounds as its initial clipping range.
    2. Trim C's clipping range with the range already marked as clipped in the 'range buffer'.
    3. Now for each subsequent polygon S of a similar depth (ie where S's BR bottom edge starts below C's BR top edge) ...
      • loop to next S if it doesn't overlap horizontally with C
      • determine if S is overlapping from the left or right (eg by comparing the BR horizontal midpoints of S and C). If S overlaps from the right and S's left-most vertex is below C's right-most vertex, then truncate C's clipping range accordingly. (Likewise if S overlaps from the left.)
    4. If the residual clipping range isn't empty, then at least part of C is visible from your viewing segment. Now add C's residual clipping range to the clipping 'range buffer'.


来源:https://stackoverflow.com/questions/5892539/visibility-of-polygons-from-an-edge

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