Rohan Baweja

Ranch Hand

Posts: 31

posted 14 years ago

I've created two circles using Ellipse2D.Double() class and I want to know if its possible to find the coordinates of the two intersecting points from the methods provided in the Ellipse class or it requires some complex mathematical function to evaluate those points. Help me, please. Thanks

Michael Morris

Ranch Hand

Posts: 3451

posted 14 years ago

Well, it really depends on what you are trying to do. When you say circles, do yo mean that the width and height of the bounding box are equal or have you compensated for screen aspect? There is certainly nothing complex about finding the intersection of two circles mathematically, any high school junior should be able to do that. You have to solve for the two simultaneous quadratic equations of the circles. The general equation for a circle is:

for a circle with radius

for an ellipse with a horizontal semi-axis of

In any case there are three possible solutions: there are two intersection points, one intersection point with a common tangent or no intersection at all. While the math for this can get nasty, it is not really all that complicated.

Another alternative is to do it programatically by getting the PathIterator for each circle. That should return a series of line segments. With that you should be able to find the line segments that intersect. That could really cost you in performance though according to how many segements you have to iterate.

Originally posted by Rohan Baweja:

I've created two circles using Ellipse2D.Double() class and I want to know if its possible to find the coordinates of the two intersecting points from the methods provided in the Ellipse class or it requires some complex mathematical function to evaluate those points. Help me, please. Thanks

Well, it really depends on what you are trying to do. When you say circles, do yo mean that the width and height of the bounding box are equal or have you compensated for screen aspect? There is certainly nothing complex about finding the intersection of two circles mathematically, any high school junior should be able to do that. You have to solve for the two simultaneous quadratic equations of the circles. The general equation for a circle is:

for a circle with radius

**r**and center at

**P(h, k)**. For an ellipse it becomes:

for an ellipse with a horizontal semi-axis of

**a**, verical semi-axis of

**b**, and center at

**P(h, k)**. Of course if the ellipse is rotated then the equations become more complex.

In any case there are three possible solutions: there are two intersection points, one intersection point with a common tangent or no intersection at all. While the math for this can get nasty, it is not really all that complicated.

Another alternative is to do it programatically by getting the PathIterator for each circle. That should return a series of line segments. With that you should be able to find the line segments that intersect. That could really cost you in performance though according to how many segements you have to iterate.

*Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction.* - Ernst F. Schumacher