Simple 2d polygon triangulation

前端 未结 4 2050
故里飘歌
故里飘歌 2020-12-28 09:26

Trying to triangulate a set of simple 2d polygons, I\'ve come up with this algorithm:

  • 1) For each vertex in the polygon, compute the angle bet
4条回答
  •  被撕碎了的回忆
    2020-12-28 10:01

    While ear clipping works reasonably well, simplistic methods slow down as the polygon increases in complexity since checking the entire polygon when collapsing each ear becomes increasingly slow.

    The ear clipping algorithm from libgdx is a good place to start from, since its very robust - using FIST (Fast Industrial-Strength Triangulation of Polygons).

    I used this as a basis for polygon tessellation, then added spatial optimizations for the point-in-triangle tests, (O(n log n) instead of O(n^2)).

    See:

    • C code, tests.
    • Rust code, tests
    • Original code from libgdx.

    Note, while the algorithm doesn't explicitly support holes, you can use keyhole edges between separate islands, which will then be correctly triangulated.

提交回复
热议问题