-
intersect_polyline_with_polygon returns the intersected polylines, but I was wondering if a similar function exists which would return the intersected polygons. I couldn't see any such function, so perhaps it's more of a question of how this can be achieved using the existing API. E.g. left side is a polygon intersected by the red polyline, and the result is the 3 polygons on the right. PS the line doesn't have thickness, hence there aren't really gaps between the polygons on the right, but it's just illustrative. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yeah that's an interesting problem, there was Q&A question I answered some time ago:
Exampleextends Node2D
func _draw():
var circle = GoostGeometry2D.circle(50)
var polyline = PoolVector2Array([
Vector2(-45, -54.5),
Vector2(6, -19.5),
Vector2(-8, 20.5),
Vector2(66, 29.5)
])
var crack_width = 1.0
var deflate_result = GoostGeometry2D.deflate_polyline(polyline, crack_width)
assert(not deflate_result.empty())
var deflated_polyline = deflate_result[0]
var polygons = GoostGeometry2D.clip_polygons(circle, deflated_polyline)
for poly in polygons:
draw_colored_polygon(poly, Random.color) It looks to me that this kind of task is more or less common (you're not the only one asking this question, at least), so it might make sense to provide API for this, like But it could be considered hack-ish depending on the exact use case. Deflating polyline into a polygon could possibly result in unwanted artifacts like cutting the edges slightly of the original polygon if There's also another potential solution to this problem: you can generate a partial rectangular-ish polygon with desired curve (in such a way that would cover parts that you want to cut), and do intersect operation between original and generated polygons, and then clipping the original polygon with the result of previous operation! This way, you'll have no gap, but you have to make sure to properly cover your subject polygon in order to cut all parts. See also discussion upstream at the Clipper repository: "Splitting polygons with split lines?". |
Beta Was this translation helpful? Give feedback.
Yeah that's an interesting problem, there was Q&A question I answered some time ago:
Example