Search code examples
algorithmshapesgesture-recognition

2D Shape recognition and resolving algorithm


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.


Solution

  • 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:

    1. Whether or not the points form a straight line
    2. Whether or not the points form a convex/concave polygon (useful for disqualifying points from matching certain shapes)
    3. Finding center of points and finding distance to center from each point
    4. 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.