mapbox / earcut

The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
ISC License
2.21k stars 207 forks source link

wrong triangulation #159

Open lzxue opened 1 year ago

lzxue commented 1 year ago

Use latitude and longitude coordinates is wrong

draw as polygon

image

draw as line image

the data

{
    "vertices": [
        57.915138,
        42.457222,
        57.990749,
        45.449139,
        58.578686,
        45.599289,
        59.099235,
        45.341999,
        60.001514,
        44.999783,
        61.111194,
        44.35775,
        61.121418,
        44.268665,
        62.028694,
        43.486527,
        65.294136,
        43.545277,
        66.60611,
        41.251415,
        68.443611,
        40.596111,
        68.617222,
        40.613333,
        57.915138,
        42.457222
    ],
    "holes": [],
    "dimensions": 2
}

Use projected coordinates is ok

draw as polygon image

draw as line image

{
    "vertices": [
        -595675.270653422,
        -97137.56776251551,
        -587258.2926350506,
        365653.92892832495,
        -521809.445176526,
        389511.2666772781,
        -463862.19556357805,
        348669.2554599289,
        -363420.9567301143,
        294632.69788446557,
        -239891.94418663438,
        194118.13950136025,
        -238753.81371276453,
        180258.65645650402,
        -137756.31138380617,
        59467.24496770464,
        225751.02927116212,
        68485.68337761611,
        371799.30688517727,
        -277358.2804402346,
        576348.9825373087,
        -373905.20303173736,
        595675.2706534192,
        -371380.04541214835,
        -595675.270653422,
        -97137.56776251551
    ],
    "holes": [],
    "dimensions": 2
}
mtschanen commented 1 year ago

Can this really be considered a bug? Spherical coordinates are not euclidian, so it's no wonder earcut can't work with them.