# Convex Shape to triangles

Hello people,

i´m trying to convert a shape to several triangles to be used with box2d.

I´ve tried with delaunay 2d and 2d triangles but i don´t know how to manage the data to convert it into verticesXY and Vertices Count.

Is there any way to use the delaunay 2d indices to sort the vertices of the several triangles, to be sent to polydon 2D?

any help will be very appreciated.

L

Hello,

if your shape is convex it’s really easy to convert to triangles.

• Calculate the center point.
• Sort the points anticlockwise
• Join the triangles (triangle fan)
It’s not as optimal as techniques like ear clipping/cdt but at least it’s fairly easy to implement.

With delaunay i would use indices, a getslice on indices with a bin size of 2 does the job, vertices count is 3, but i think i calculate using this pin spreadcount, so use select with 3 as input and select count will be indices count /3, and send that part in the vertices count.

Hope that helps, if you got more questions don’t hesitate to ask.

I think i´ve got it!!
Thanks a lot Julien!!

i´ve used the delaunay solution with the indices,
And i can draw the diferent triangles, but i have a new problem :/

when i send this data to the polygon 2d (box2d) and generate the several poligons, the shapes don´t move,
maybe is this because the shapes are tangent to each other?

Any idea will be great.

L

Mm density set to 1? if set to 0 body will be static.

Thanks Julien,
Density is set to 2 (for my particular scene), and with a few random polygons it´s running properly.

I´ve changed only the incomming vertices and counts between random regular polygons and the delaunay data, and they are propertly displayed but static :/

I´ll try to attach a example patch.

L

I think i´m drawing the polygons clockwise, there is any way to sort the vertices in the right direction?

I´ve attached a example patch.

thanks again.
L

delaunay polygons.rar (10.3 kB)

Hi,

I´ve fixed the delaunay module and now it´s running ;)

Thanks a lot

L

delaunay polygons 2.rar (18.7 kB)