mapbox / earcut

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

The result of dividing a plane triangle is [] #151

Closed jynxio closed 3 years ago

jynxio commented 3 years ago

Direction:

Suppose the format of the three-dimensional coordinates is [X,Y,Z]. Suppose there are triangle A and triangle B, the set of vertex coordinates of triangle A is [0,0,0, 1,2,0, 2,0,0], B is [0,0,0, 1,0,2, 2,0,0]. Obviously their shapes are the same, except that A is located on the XY plane and B is located on the XZ plane, but the result of earcut A is valid, but the result of earcut B is invalid(see the example below for details), this is the problem I encountered. Excuse me, is this because of my wrong way of use, or is it because of a bug in the program?

Example

const d_a = [0,0,0, 1,2,0, 2,0,0]; const d_b = [0,0,0, 1,0,2, 2,0,0];

earcut(d_a, null, 3); // return [1, 0, 2] earcut(d_b, null, 3); // return []

mourner commented 3 years ago

It's Earcut's design limitation — it only triangulates the XY projection in 2D plane and passes Z as is. See #21 for the discussion.

jynxio commented 3 years ago

It's Earcut's design limitation — it only triangulates the XY projection in 2D plane and passes Z as is. See #21 for the discussion.

Thank you, I get it :)