Triangulate a set of points with a concave domain

前端 未结 6 1405
闹比i
闹比i 2021-02-14 02:47

Setup

Given some set of nodes within a convex hull, assume the domain contains one or more concave areas:

where blue dots are points, and the black li

6条回答
  •  情歌与酒
    2021-02-14 03:28

    Since my question is seeming to continue to get a decent amount of activity, I wanted to follow up with the application that I'm currently using.

    Assuming that you have your boundary defined, you can use a ray casting algorithm to determine whether or not the polygon is inside the domain.

    To do this:

    1. Take the centroid of each polygon as C_i = (x_i,y_i).
    2. Then, imagine a line L = [C_i,(+inf,y_i)]: that is, a line that spans east past the end of your domain.
    3. For each boundary segment s_i in boundary S, check for intersections with L. If yes, add +1 to an internal counter intersection_count; else, add nothing.
    4. After the count of all intersections between L and s_i for i=1..N are calculated:

      if intersection_count % 2 == 0:
          return True # triangle outside convex hull
      else:
          return False # triangle inside convex hull
      

    If your boundary is not explicitly defined, I find it helpful to 'map' the shape onto an boolean array and use a neighbor tracing algorithm to define it. Note that this approach assumes a solid domain and you will need to use a more complex algorithm for domains with 'holes' in them.

提交回复
热议问题