开发者

Visibility of polygons from an edge

开发者 https://www.devze.com 2023-03-02 18:35 出处:网络
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 segme开发者_StackOverflow中文版nt lying within that area. e.g.

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 segme开发者_StackOverflow中文版nt lying within that area. e.g.

Visibility of polygons from an edge

  • Further,

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号