开发者

How to find Edges and Vertices of a hand drawn polygon

开发者 https://www.devze.com 2023-03-10 13:49 出处:网络
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 jus

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消