Is there a library that can split a concave polygon into convex ones

Hi, I am trying to triangulate the polygon. I found the two triangulation libraries: delaunator and spade. However, I realized that these two libraries can only support solving convex polygons after trying them.So I want to split the concave polygon into into convex ones and then triangulate them. But I am not familiar with this field. Are there any recommended libraries?

I recently did a search for such libraries myself. I have not actually made use any of them yet for the purpose I had in mind, so I can’t say which ones are actually good, but I did glance through their docs and code; here's a copy of my notes from the search, which I was going to use as a list of ones to try out.

All of these should support non-convex polygons and holes.

If you try any of them, let me know how it goes!

3 Likes

Thanks! Just tried earcutr and earcut, but the API design of both libraries is kinda unreasonable to me.

For example, there is an argument dimensions which must be 2, but we still need to input this value manually every time we call this function in crates/earcutr. And in crates/earcut, we need to pass the triangles as a mutable variable to the earcut function, instead of getting the calculated triangles as a return value from the earcut function, which is not quite intuitive.

But anyway, crates/earcut seems enough for my needs.

That’s probably a part of the "designed with attention to perf" part. Returning a new vector of triangles would be super inefficient compared to reusing a buffer when you’re calling the function a lot; writing the result to an out parameter instead is pretty standard practice in high-performance APIs.

1 Like

I don't think Spade requires a convex polygon as its input. What happens if you try to create a triangulation using Triangulation in spade - Rust?

We use both earcutr and spade in crates.io: Rust Package Registry