# 2d polygons? how to work with concave polygons

Hello all,

I have to create certain 2d shapes which will be designated areas so I have been using the custom mesh example; however I am having an issue with a more than 4 sided object that is concave.

In this example I have the 3 objects 2 are rectangles, and 1 is a 6 sided polygon. They will be random I need to do this in a way that is automated.

I am able to fill most of the polygon area, by going around each point and creating triangles out of the vertexes; however there are some patches, and when I try to do the concave area it goes through it.

I figure I could use the comparator I already have set up and just fill up the regions that way, and then for the concave part I just need to compare the points and I figured I could flip the triangle as a mirror and that would fix that issue…

The problem is this is an extremely rough approach and I find it ridiculous there is no 2d polygon function like in JavaFX and AWT… Is there anyway I could call in an FX Polygon?

Thanks,

~KZ

Well you search for an algorithm like this?

That seems like it is something more than what I need… But it also seems like it could be what I need, I’ll have to look up a formula or something for what I need. Is there a way to use it in JME i.e., a command or…?

I will look into that algorithm more tomorrow, I am very tired now, but if you have any other suggestions, let me know, thanks.

I am also curious if I can use Open GL directly and use their polygon… I still do not know why there isn’t one for JMonkey…

@KonradZuse said: That seems like it is something more than what I need... But it also seems like it could be what I need, I'll have to look up a formula or something for what I need. Is there a way to use it in JME i.e., a command or...?

I will look into that algorithm more tomorrow, I am very tired now, but if you have any other suggestions, let me know, thanks.

I am also curious if I can use Open GL directly and use their polygon… I still do not know why there isn’t one for JMonkey…

Because JME is a game engine and not a modeling engine… and it almost never comes up.

Most of the devs that need to split a polygon into triangles will know how to do it, I guess. The last time I needed something like this was in the 90s… I think I just split based on the two closest points… split on two closest points again, etc. until I had triangles.