From 1727d4b86a125c4ce722a5900a53734162837b51 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 3 Feb 2021 17:52:11 -0800 Subject: [PATCH] Small hacky tweak to fix more triangulation issues --- manimlib/utils/space_ops.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/manimlib/utils/space_ops.py b/manimlib/utils/space_ops.py index ef09f306..c124cbec 100644 --- a/manimlib/utils/space_ops.py +++ b/manimlib/utils/space_ops.py @@ -382,12 +382,18 @@ def earclip_triangulation(verts, ring_ends): for ring_group in (attached_rings, detached_rings) ] - # Closet point on the atttached rings to the first point + # Closet point on the atttached rings to an estimated midpoint # of the detached rings - i = min(i_range, key=lambda i: norm_squared(verts[i] - verts[j_range[0]])) + tmp_j_vert = midpoint( + verts[j_range[0]], + verts[j_range[len(j_range) // 2]] + ) + i = min(i_range, key=lambda i: norm_squared(verts[i] - tmp_j_vert)) # Closet point of the detached rings to the aforementioned # point of the attached rings j = min(j_range, key=lambda j: norm_squared(verts[i] - verts[j])) + # Recalculate i based on new j + i = min(i_range, key=lambda i: norm_squared(verts[i] - verts[j])) # Remember to connect the polygon at these points loop_connections[i] = j