Tuesday 24 January 2012

More on circles


Yesterday I described circle-point and circle-circle intersection tests. These are very straightforward to do, and it is interesting to look at why this is so, as it can help solve other problems with circles.


There are two main ways to describe a circle mathematically. It can be described parametrically with the following formulae,




where (a, b) is the centre of the circle, r is the radius and θ is the angle around the circle anti-clockwise from the x axis. This is useful for drawing a circle but not suited for testing whether things intersect or overlap.


The other form is an equation, based on Pythagoras' theorem,




This is less useful for generating points but is the best form for intersection tests. For example a point (x0, y0) is contained in a circle if its distance to the centre of the circle is less than the radius, so if it satisfies the following inequality based on the above equation,



Two circles overlap if the distance between their centres is less than the sum of their radii. So if the circles are at (a0, b0) and (a1, b1) with radii r0 and r1, the inequality is




With a small modification this can also be used to determine whether one circle contains another, so the smaller circle lies entirely inside a larger one without touching it. The inequality for that is.




In all the inequalities if the less than sign is replaced with a equals side they become the condition for the point and circle or circles to be touching, although testing this has to be done with care due to rounding errors.

No comments:

Post a Comment