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 line illustrates the domain. Assume the points are held as a 2D array points
of length n
, where n
is the number of point-pairs.
Let us then triangulate the points, using something like the Delaunay method from scipy.spatial:
As you can see, one may experience the creation of triangles crossing through the domain.
Question
What is a good algorithmic approach to removing any triangles that span outside of the domain? Ideally but not necessarily, where the simplex edges still preserve the domain shape (i.e., no major gaps where triangles are removed).
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:
- Take the centroid of each polygon as
C_i = (x_i,y_i)
. - Then, imagine a line
L = [C_i,(+inf,y_i)]
: that is, a line that spans east past the end of your domain. - For each boundary segment
s_i
in boundaryS
, check for intersections withL
. If yes, add +1 to an internal counterintersection_count
; else, add nothing. After the count of all intersections between
L
ands_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.