Python: Checking If Coordinates Are Within Circle

MichaelH picture MichaelH · Sep 4, 2012 · Viewed 10k times · Source

Possible Duplicate:
How can I make Turtle recognize a circle?

enter image description hereI have a function that draws a few circles and I am going to place dots inside them. Depending if the dot falls within the circle, depends on wether the colour will change or not.

The biggest issue I am finding is how to check whether or not the dot is within the circle. Does anyone have any idea how to calculate coordinates within a circle or is their a method which can check coordinates against the circle?

Answer

gefei picture gefei · Sep 4, 2012

For a circle with center (x,y) and radius r, a point (x1, y1) is within the circle if

(x1-x)² + (y1-y)² <= r²