简体   繁体   中英

How to find Edges and Vertices of a hand drawn polygon

I would like to make a shape recognition program that would trace a mouse and record it's location at each 1/2 second. How could I use these points to find a rough polygon? In other words, if you just draw a shape resembling a triangle or square, it will more likely be a be a 50-100-gon, how can I simplify it to get the shape I were trying to draw? I know that you could do a genetic algorithm, but do not know exactly how that would work, and I would like to know any alternatives.

edit: convex hulls will not work, concavity is needed to be preserved.

i'll give this a shot.

  1. lets call the position when the mouse click down event happens point START
  2. every interval take another position called CURR
  3. the lets call the previous CURR, PREV
  4. calculate the slope (delta y/delta x) between CURR and PREV,
  5. calculate the slope of the line between CURR and START
  6. define some threshold for a difference between the two slopes
  7. if the slope crosses the threshold,
    1. store the line between START AND CURR as a SIDE
    2. define CURR as a new START
  8. repeat until CURR is within a certain radius of the original START or crosses one of the previous sides

you might be able to determine the shape simply by counting sides.

For each point along the 100-agon, find the area of the tiny triangle formed by that point and the points on either side. Remove the point that created the smallest triangle. Repeat until the smallest triangle is larger than some threshold.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM