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.
- lets call the position when the mouse click down event happens point START
- every interval take another position called CURR
- the lets call the previous CURR, PREV
- calculate the slope (delta y/delta x) between CURR and PREV,
- calculate the slope of the line between CURR and START
- define some threshold for a difference between the two slopes
- if the slope crosses the threshold,
- store the line between START AND CURR as a SIDE
- define CURR as a new START
- 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.
精彩评论