Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding line which is tangent to 2 circles 5

Status
Not open for further replies.

GPerk

Programmer
Jul 6, 2002
161
US
Given two circles at X1,Y1 and X2,Y2 with radii R1 & R2,
I need to find the lines which are tangent to the two circles.

The two circles do not intersect or touch, so there will be four tangent lines.

Where can I find an algorithm or code (any language) that will determine these four lines?
 
A google search for "find line tangent to two circles" turned up over 1 million hits. The first one here should provide the answer you need.



Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Yes, I found lots of pages that discuss how to CONSTRUCT the tangent lines, but nothing about the algorithm to COMPUTE the X & Y for those points at the tangents.

I have a book, "A Programmer's Geometry" by Adrian Bowyer, et al, published in 1983. It gives the following

dR = R2 - R1 ' diff. in radius of circles C1 & C2
dX = X2 - X1 ' diff in X, centers of the circles
dY = Y2 - Y1 ' diff in Y
Denom = dX ^ 2 + dY ^ 2
If Denom < 0.00001 Then
' Centers are same
Else
Root1 = Denom - dR ^ 2
If Root1 < -0.00001 Then
' Tangent does not exist
Else
Root2 = Sqr(Root1)
A = (-dR * dX - dY * Root2) / Denom
B = (-dR * dY + dY * Root2) / Denom
C = -(R1 + A * X1 + B * Y1)

where the results: Ax + By + C = 0
is the equation of the one of the tangent lines.
But so far the results don't seem reasonable.
For example, with:
X1 = 200: Y1 = 200: R1 = 50
X2 = 400: Y2 = 201: R2 = 100 (Y2=201 to avoid dY=0)
gives:
A= -0.2548 B= 0.00359 C=0.2487
Perhaps I don't know how to interpret the results?

 
Assuming a helper line between the centers of the two circles, the four possible tangent lines are:
1. Left outer edge of circle 1 to the left outer edge of circle 2
2. Left outer edge of circle 1 to the right outer edge of circle 2 (a diagonal, if you will)
3. Right outer edge of circle 1 to the left outer edge of circle 2 (the other diagonal)
4. Right outer edge of circle 1 to the right outer edge of circle 2

To find these equations, you need to provide two X values and then solve for Y for each of the four lines above, to calculate the A, B & C values you need.

In order to find the X value, you need to find two normals for each of these lines -- the first normal extends from the center of circle 1 to the point on the circumference where it will be perpendicular to the line that joins the other circle. The second normal extends from the center of circle 2 to the point on it's circumference where it will perpendicular to the same join line.

Repeat for the other three lines.

The simplest case is where both circles are the same diameter, then the point where the normal and the join line meet is merely the centerpoint of the circle minus the radius (the normal would follow along an X or Y axis, making the math easy!).

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Not solved, but another clue.

a line which passes through the centers of both circles will also pass through the points where the paris of tangents intersect. Of course for the instance where the circles are concentric, the tangenst do not exist.




MichaelRed


 
1. The two pairs of common tangents intersect on the line between the centres
2. The line through the centres, the common tangent and the two radii through the tangent points form two similar triangles - you can now solve for the intersection point
3. Solve the triangle to get the slope of the tangent
4. Use slope of line plus known point (intersection of tangent and line through centres) to solve for common tangent
5. Use tangent equation and circle equation to solve for tangent points

You will of course need to check for exceptions:
1. One circle inside the other: no solutions
2. Intersecting circles: external tangents only
3. Tangent circles: 2 external and 1 common

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
johnwm,

there are actuall four triangles, and all are "similar" in the geometry jargon. they are (by deffinition), Right triangles (the Base is a line PERPINDICTULAR to the tangent).

The "soloution" you mention (point 2.) escapes me for the moment. I am used to having more information to solve this than I see so far. I "see" that there is a right triangle (on angler is 90 degrees, the other two must have an aggregate of 90 degrees and the base is the radius of the circle, which was given in the problem statement. In my 'curcles", we need one additional piece of information, either of the remailing angles, the hypotenuse or opposite side length.

In the interest of brevity, perhaps you could post back which of these is known (or at least knowable) and how it is so known?




MichaelRed


 
Michael,
My bad - I took it that we all realised that there are 2 pairs of triangles, one for the internal (crossed) tangents and another for the external tangents. I'm not about to give a full solution for what may well be a homework question, but there are several alternatives available, for instance:

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
johnwm, if you feel it is a homework problem, it would be appropiate to RF it. I hadn't thought it to be such, and even on further consideration, think that it is not likely. If it is homework, it is certainly of a higher degree of difficulty than I am use to seeing in these fora.




MichaelRed


 
If I was sure it was homework, I would certainly RF it! I'm giving OP benefit of the doubt at present, and trying to guide his search. When I was at school this would be 16-18 yr old studies

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Guess your school was more rigouous than mine, else (mayhap) I just to D@#$%@#$% old to remember some days?




MichaelRed


 
To Johnwm: I hope the quality of our high schools has improved to the point that this problem would be solved there. But I doubt it. It wasn't when I graduated from high school in 1948 at the age of 16 yrs + 2 months.

No this is not a homework problem, except in the sense that I am working on it "at home".

I am working on a simulation program where 2 pulleys of different radius are connected by a belt. I need to know the points of tangency. At first I thought I only needed the 2 "outside" lines, but my brother pointed out that sometimes the belts are "twisted" (figure 8) - so I need all 8 points. However, the pulleys will always be well separated so we don't have to worry about the circles intersecting each other.

To MichaelRed: Re your statement: "I 'see' that there is a right triangle (one angle is 90 degrees, the other two must have an aggregate of 90 degrees and the base is the radius of the circle, which was given in the problem statement. In my 'curcles", we need one additional piece of information, either of the remailing angles, the hypotenuse or opposite side length." Note that the 2 outside tangents meet at point P. An arc centered at P and going thru the center of the smaller circle, goes thru the tangent points on the smaller circle (near but not at the perpendicular). So we can use the distance (P to X1,Y1) to find the tangent point on the smaller circle (via simultaneous equations).

I got the spur gears working in the simulation and I thought the pulleys would be easy. Not so!
 
hmmmmmmmmmmmm ... mmmmmmmmmmmmmmmm ... mmm

but ... but ... but ... sputter ...

We do not know the locus (X, Y) of P. Further, even if we knew the locus of P, we still do not have the equation for ANY of the tangents (e.g. y = mx + b) where the soloution would (in my opinion) be composed of the matris of the slopes and intercepts.

On the other hand, your explination seems to obviate the necessity of all of this, as the mechanical advantage of the pullys does not depend on these issues, but just hte rations of the pulleys and the number of wheels involved.

MichaelRed


 
MichaelRed,
Go to Dr Math gives the procedure for CONSTRUCTING the tangents.
I tried it on graph paper and it works (even with my cheap dime-store compass).
Let me re-state the method:
1. draw a small circle C1 in middle of paper
2. draw a larger(2 * C1) circle C2 on the right side of the paper
3. draw a line L0 thru the center of the circles across the whole paper
4. construct perpendiculars(L1 & L2) to L0 thru the centers of the circles
5. draw a line thru the 2 point where L1 crosses C1 and where L2 crosses C2 at the top of the circles
6. this last line crosses L0 at point P
7. at the midpoint between P and center of C1, draw a cirle(Ca) with DIAMETER of P - C1. This circle passes thru the tangents to C1
8. repeat for C2, drawing Cb
So the problem is reduces to finding the intersections of C1 & Ca and of C2 & Cb
I can construct it but so far I haven't computed it.
 
I misstated the construct procedure in my post of 9 Jan 06 0:39 (I plead wee-hours fatigue.)

The final arc is NOT centered a P.
It is centered at MIDPOINT between P and the circle.
 
OK, it took a while but I have the problem solved.
To get a copy of my VB source, go to

Since I included the form definition in the file, you will need to save the source as a .frm file, start a new project, then Project/Remove form, then Project/Add form with the name of the file you saved. When you Run you get an error and Project Properties window - just click on the downarrow by Startup Object and select Form1. (Is there an easier way to do this?)

The program is very interactive and it should, with the comments in the source, make it clear how the tangents are constructed.
 
<When I was at school this would be 16-18 yr old studies

Not in the USA, I'm sorry to say. This would be more like early college material, in degree programs that required math classes.

GPerk, that's an excellent piece of code. Another star!

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top