java circle recognition from an arraylist of points

主宰稳场 提交于 2019-11-28 05:15:15

问题


I currently have an arraylist of points from a freehand drawing on a canvas. I was wondering if there is a simple algorithm to detect if that shape represents a circle.I have already researched this a little and the main items I am pointed at are either the Hough transform or having bitmap images but both of these seem a little over the top for what I need it for. Any pointers to algorithms or implementation would be very helpful.

thanks in advance sansoms,


回答1:


If you do not know what the user wanted to draw (e.g., a circle, an ellipse, a line, or a rectangle), you could use some basic optimization algorithm to find the shape best matching the hand-drawn points.

  • for each basic shape (oval, rectangle, triangle, line, etc.), create a random instance of that shape and measure the error w.r.t. the given points
  • optimize each of the shapes (individually) until you have the oval best matching the given points, the rectangle best matching the points, the best triangle, etc.
  • pick the shape that has the lowest error and draw it



回答2:


If I interpret your question correctly, you want to know if all the points are on a circle.

As illustrated in the picture, we pick three points A, B, C from the list and compute the origin O of the presumed circle. By checking the distance between O and each point from the list, we can conclude whether these points are on a circle.




回答3:


Maybe this answer can give you some ideas: https://stackoverflow.com/a/940041/12860

In short: calculate the second derivative. If it is quite constand, it is probably a circle.




回答4:


Reading your comment, an easier method to draw a circle is for the user to click the center point, then drag the radius of the circle. It's a lot less calculation, and easier for the user to draw.

You can do the same thing with a rectangle, or any other convex polygon.



来源:https://stackoverflow.com/questions/13452821/java-circle-recognition-from-an-arraylist-of-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!