问题
I'm looking for an algorithm for detecting simple shapes as rectangles, triangles, squares and circles, from a given set of (x,y) points. I'm also looking for a way of, once detected, transform the path to a more clean shape.
I've scrambled the internet but haven't found any "simple" approaches. Almost all of them are way to advanced for my simple implementation.
Thanks in advance.
回答1:
On detection:
There are most likely no simple general approaches for classifying any set of points into a shape. However, there are a few basic functions that you could probably build that will be useful for classifying many of the shapes. For instance:
- Whether or not the points form a straight line
- Whether or not the points form a convex/concave polygon (useful for disqualifying points from matching certain shapes)
- Finding center of points and finding distance to center from each point
- Whether or not two points share a common axis
With the above functions, you should be able to write some basic logic for classifying several of the shapes.
来源:https://stackoverflow.com/questions/15811192/2d-shape-recognition-and-resolving-algorithm