Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Intersecting circles

Rohan Baweja
Ranch Hand
Posts: 31
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
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.