Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# 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.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}