Finding the Intersection of Two CirclesDate: 08/19/99 at 22:44:21 From: Tom Groff Subject: Cad Geometry I have been writing a simple 2D wireframe CAD application in Visual Basic. I have resolved most of the intersection problems (Lines, Arcs and Circles) that I have come across even though my math is poor. I have stubbed my mental toe on the intersection points of two circles. My function checks for the four possible situations and deals with them in the following Pseudo Code. If Circ1 center point = Circ2 center point then Intersection = false 'Circles are concentric. elseif Distance between centers = Circ1 radius + Circ2 radius then Intersection = true 'Circles are tangent. x = (cx1+cx2)/2 'Intersection is the midpoint y = (cy1+cy2)/2 'between the circle center pts. elseif Distance between centers < Circ1 radius + Circ2 radius then Intersection = false 'Circles do not meet. else Intersection = true 'Circles definitely intersect. Since we know the distance between the circle centers and the two circle radii, we have a non-right triangle. The apex of this triangle is one of the intersections of the two circles. Using the ArcCos() function, I can find the angle of the first radius triangle leg to the circle center point. Ang = Arccos(((DistC^2)+(Rad1^2)-(Rad2^2))/(2*DistC*Rad1)) Using more trig I can determine the distance to the midpoint between the circles. CenDist = Cos(Ang) * Rad1 Dist = Sin(Ang) * Rad1 Finally I walk up the line between the center points (CenDist). DistRatio = -(CenDist / hypot(Abs(cx1 - cx2), Abs(cy1 - cy2))) x1 = ((cx1 - cx2) * (DistRatio)) + cx1 y1 = ((cy1 - cy2) * (DistRatio)) + cy1 This gives me the point on the CenterLine in line with the two intersection points. Logic says I should be able to find the inverse slope of the CenterLine, drive it through the new point on the CenterLine and walk out "Dist" to my circle intersection points. Sab = (cy1 - cy2) / (cx1 - cx2) 'Slope of the existing line Iab = cy1 - (Sab * cx1) 'Y-int. of the existing line Scd = -(1 / Sab) 'Inv. slope of the existing line Icd = y1 - (Scd * x1) 'Y-int. of calculated line What is frustrating is that after all this work I found I do not know how to define a new point at a given distance along a slope. I have only one point on my new slope and no endpoints known. Any suggestions? end if Date: 08/20/99 at 13:07:43 From: Doctor Peterson Subject: Re: Cad Geometry Hi, Tom. Your specific question, stated in the simplest terms, is this: you have a point P = (a,b) on a line, and the slope m of the line, and you want to find the point Q a given distance d along the line from that point P. Let's draw the situation: | / | / | +Q | / | d/ | / | +P (a,b) | / / | / / | / / | / /slope=m | / / | / / ------+-------------/------------------- O / | / | / The most natural way to approach this is with vectors. The point Q is the sum of the vector OP, which you know, and the vector PQ, for which you know the slope and the length. Here's how we can find PQ, which we'll call D: First, we can find a vector V in the direction of the slope; let's use V = (1, m). (This means we go over 1 and up m, producing the right slope.) Second, we have to find a vector in the same direction, whose length is 1. Since the length of our vector V is sqrt(1 + m^2), if we divide by this we will get a unit vector: 1 m U = (-----------, -----------) sqrt(1+m^2) sqrt(1+m^2) Now we can multiply this by the distance d to get a vector with the right direction and length: d dm D = (-----------, -----------) sqrt(1+m^2) sqrt(1+m^2) Now the point you are looking for is the sum of the vectors P and D: d dm Q = P + D = (a + -----------, b + -----------) sqrt(1+m^2) sqrt(1+m^2) If you aren't familiar with vectors, you should be, because they make graphics work much easier. Back to your original problem, you may want to note that you don't need any trig at all. Since CenDist = cos(Ang) and Ang is an arccos, you can get CenDist directly as CenDist = ((DistC^2)+(Rad1^2)-(Rad2^2))/(2*DistC*Rad1) * Rad1 Dist is one leg of a right triangle with hypotenuse Rad1 and other leg CenDist, so you can use the Pythagorean Theorem to get it. Other than that, the rest of your work looks fine. (Don't forget, of course, that there will be two points of intersection in opposite directions.) - Doctor Peterson, The Math Forum http://mathforum.org/dr.math/ |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/