How to find the edges and vertices of a drawn polygon

I would like to make an image recognition program that will track the mouse and record its location every 1/2 second. How could I use these points to find a rough polygon? In other words, if you just draw a shape that resembles a triangle or square, most likely it will be a 50-100-gon, how can I simplify it to get the shape that I was trying to draw? I know that you can make a genetic algorithm, but you don’t know exactly how this will work, and I would like to know any alternatives.

edit: convex hulls will not work, it is necessary to preserve concavity.

+4
source share
2 answers

For each point on the 100-agon, find the area of ​​the tiny triangle formed by this point, and the points on each side. Remove the point that created the smallest triangle. Repeat until the smallest triangle exceeds a certain threshold.

+1
source

I will do it.

  • allows you to call a position when a mouse click event occurs, the START point
  • each interval takes a different position named CURR
  • allows you to call the previous CURR, PREV
  • calculate the slope (delta y / delta x) between CURR and PREV,
  • calculate line slope between CURR and START
  • determine some threshold difference between the two slopes
  • if the slope crosses the threshold,
    • save line between START AND CURR as SIDE
    • define CURR as a new START
  • repeat until CURR is within the defined radius of the original START or crosses one of the previous sides.

you could determine the shape simply by counting the sides.

+3
source

All Articles