java circle recognition from an arraylist of points

前端 未结 4 1701
情话喂你
情话喂你 2020-12-19 18:07

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 hav

相关标签:
4条回答
  • 2020-12-19 18:39

    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.

    0 讨论(0)
  • 2020-12-19 18:54

    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.

    0 讨论(0)
  • 2020-12-19 18:56

    enter image description here

    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.

    0 讨论(0)
  • 2020-12-19 19:00

    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
    0 讨论(0)
提交回复
热议问题