<jupyter_start><jupyter_text>Demonstration of the ear clip moduleThis module is the code from mrbaozi's repo https://github.com/mrbaozi/triangulation, simply turned into a module for ease of use. All credit to him.To use, simply build a list of lists, each inner list is a coordinate pair of one of the points on your simple polygon. Pass this to the triangulate method.<jupyter_code>import matplotlib.pyplot as plt
from earclip import triangulate
%matplotlib inline

poly = [[ 229.28340553,   78.91250014],
       [ 258.42948809,   17.98278109],
       [ 132.01956999,  -22.96900817],
       [ 107.97774096,   23.39276058],
       [  65.85573925,   28.63846858],
       [  41.66373597,  -92.78859248],
       [  -5.59948763,  -54.18987786],
       [ -44.61508682,  -69.7461117 ],
       [ -28.41208894, -106.93810071],
       [ -71.11899145, -125.56044277],
       [-100.84787818,  -88.51853387],
       [-211.53564549, -160.76853269],
       [-244.22754588, -147.51172179],
       [-226.83717643,  -42.0984372 ],
       [-230.65279618,  -10.5455196 ],
       [-240.50239817,   70.87826746],
       [ -12.48219264,  137.70176109],
       [   4.65848369,  204.21077075],
       [ 176.5243417 ,  193.73497584],
       [ 171.13537712,   87.27009315]]

#Plot the polygons and its inside triangles
for i in range(len(poly)):
    for j in range(2):
        poly[i][j] = poly[i][j]*1000.0
tris = triangulate(poly)
c = ['r','g','b','k','g','y']
i = 0
for tri in tris:
    plt.plot([tri[0][0],tri[1][0],tri[2][0],tri[0][0]],[tri[0][1],tri[1][1],tri[2][1],tri[0][1]],c=c[i % 5],alpha=0.5)
    i+=1
        
poly.append(poly[0]) #append the first point, to close the polygon for drawing
plt.plot([p[0] for p in poly],[p[1] for p in poly],'k-',lw=3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.167420814479638, 'fraction_numerical': 0.251131221719457, 'mean_word_length': 2.939866369710468, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '515307', 'license': 'MIT', 'n_tokens_mistral': 970, 'n_tokens_neox': 710, 'n_words': 156, 'path': 'jupyter/Demo.ipynb', 'repo_name': 'lionfish0/earclip', 'size': '1768'}