# Earcut triangulation not working for this case

**URL:** <https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [April 29, 2024, 7:29am UTC](https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753 "2024-04-29T07:29:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ads4](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ads4/32/46763_2.png) [@ads4](https://discourse.threejs.org/u/ads4)\
**Post date:** [April 29, 2024, 7:29am UTC](https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753/1 "2024-04-29T07:29:31Z")

</div>

Hello everybody,

I have problems with my triangulation algorithm. It works fine but it doesn’t work in some weird cases.  
I have an external algorithm that computes rotations, etc. The data is issued from that algorithm and should work in the triangulation algorithm but don’t.

Please find here the code I am talking about: [https://codepen.io/ads4/pen/JjVVOep](https://codepen.io/ads4/pen/JjVVOep)  
The result of the triangulation is in the console.

The first sheet is well triangulated, but the 2nd and the 3rd are not. It’s fine for the 4th one.

I really need help, thank you really much in advance.

---

<div class="post-metadata">

**Author:** ![makc3d](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/makc3d/32/10452_2.png) [@makc3d](https://discourse.threejs.org/u/makc3d)\
**Post date:** [April 29, 2024, 8:09am UTC](https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753/2 "2024-04-29T08:09:13Z")

</div>

start by plotting your polygons to see what’s wrong with them

---

<div class="post-metadata">

**Author:** ![ads4](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ads4/32/46763_2.png) [@ads4](https://discourse.threejs.org/u/ads4)\
**Post date:** [April 29, 2024, 8:44am UTC](https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753/3 "2024-04-29T08:44:07Z")

</div>

the polygons are perfectly fine, the problem comes from the triangulation  
I think it is related to the inversion of Y and Z axes

---

<div class="post-metadata">

**Author:** ![makc3d](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/makc3d/32/10452_2.png) [@makc3d](https://discourse.threejs.org/u/makc3d)\
**Post date:** [April 30, 2024, 8:45am UTC](https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753/4 "2024-04-30T08:45:03Z")

</div>

how does z axis fit into this? earclip algo operates in 2D

---

<div class="post-metadata">

**Author:** ![rob-myers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rob-myers/32/17590_2.png) [@rob-myers](https://discourse.threejs.org/u/rob-myers)\
**Post date:** [April 30, 2024, 9:43pm UTC](https://discourse.threejs.org/t/earcut-triangulation-not-working-for-this-case/64753/5 "2024-04-30T21:43:32Z")

</div>

Hey, your codepen is 404ing for me.
