Search code examples
javadetectiongeometry

circle detection from a unknown drawing


I am working on a system which can draw node and edge graphs. I am using Java canvas so I can get the user to free hand draw everything they want on the program. Is there an algorithm out there which can check the array list of points which I get from this, to check if the line is closer to a circle or a line? currently I'm just checking if any points (other than itself) are equal to the same point to classify a circle. I'm sure there are better ways of detecting a circle. any ideas?

thanks in advance.


Solution

  • The general tip - use vectors and angles for classification, instead of individual points. This is technique, on which many interactive text recognition systems are based.

    In your case, closed figures with higher probability are circles.

    So, if you can track continuous drawing-moves of user, just push each vector of drawing-move to stack.

    Afterwards, all you need - just calculate sum of angles between vectors from stack (note, that sign of angle depends on sign of pseudoscalar product). If sum is nearly pi - it means, that figure is a circle, otherwise - line

    P.S. Tip to track continuous drawing-moves - just calculate delay between sequential drags and clicks

    enter image description here