# 2D Shape approximations

This topic is 3866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, Does anybody know of any sort of algorythm that can guess what shape something is given a list of vertices? Thanks in advance

##### Share on other sites
What sort of shapes are you thinking of? Concave shapes? Regular triangles, quads, pentagons, etc?

##### Share on other sites
Just simple convex primatives, circles, triangles, sqaures etc.

##### Share on other sites
You may need to write some form of AI or algorithm that can recognize a specific pattern (such as a circle, or a square).

##### Share on other sites
You could create a hull from the vertex soup (Drop all vertices that are inside the shape), and then just count the number of vertices remaining. You'd need to add a certain threshold for circles though.

##### Share on other sites
Quote:
 Original post by Evil SteveYou could create a hull from the vertex soup (Drop all vertices that are inside the shape), and then just count the number of vertices remaining. You'd need to add a certain threshold for circles though.

Could you elaborate on that, I don't fully understand what your suggesting, what do the remaining vertices tell me?

Cheers

##### Share on other sites
Quote:
Original post by DarkMatter2008
Quote:
 Original post by Evil SteveYou could create a hull from the vertex soup (Drop all vertices that are inside the shape), and then just count the number of vertices remaining. You'd need to add a certain threshold for circles though.

Could you elaborate on that, I don't fully understand what your suggesting, what do the remaining vertices tell me?

Cheers

It's just clicked now, feeling really slow this morning. The vertices being passed would be of varying scales depending on how big the user decides to draw a shape, could I still apply this method? If the shape drawn is at a certain angle this may not work?

##### Share on other sites
Quote:
 Original post by DarkMatter2008It's just clicked now, feeling really slow this morning. The vertices being passed would be of varying scales depending on how big the user decides to draw a shape, could I still apply this method? If the shape drawn is at a certain angle this may not work?
What exactly are you trying to do? A shape with 3 vertices will always be a triangle, a shape with 4 will always be a quad, etc. Or do you want the shapes to be more like a "normal" triangle, quad, etc?

##### Share on other sites
Quote:
Original post by Evil Steve
Quote:
 Original post by DarkMatter2008It's just clicked now, feeling really slow this morning. The vertices being passed would be of varying scales depending on how big the user decides to draw a shape, could I still apply this method? If the shape drawn is at a certain angle this may not work?
What exactly are you trying to do? A shape with 3 vertices will always be a triangle, a shape with 4 will always be a quad, etc. Or do you want the shapes to be more like a "normal" triangle, quad, etc?

Well, what the user has is a free hand draw tool, which the user draws a shape. The vertices collected by that are simplified using the Douglas-Peucker line simplification algorithm, at the end of it you may have something that looks like a trianlge but may have four vertices, so counting the vertices won't really work.

##### Share on other sites
Quote:
 Original post by DarkMatter2008Well, what the user has is a free hand draw tool, which the user draws a shape. The vertices collected by that are simplified using the Douglas-Peucker line simplification algorithm, at the end of it you may have something that looks like a trianlge but may have four vertices, so counting the vertices won't really work.
You could remove vertices that have a shallow angle between the two neighboring vertices in that case. So if the angle formed by 3 vertices is less than 5 or 10 degrees, just drop it. That'll smooth out any gentle bends.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634134
• Total Posts
3015751
×