CTK Exchange
Front Page
Movie shortcuts
Personal info
Awards
Reciprocal links
Terms of use
Privacy Policy

Interactive Activities

Cut The Knot!
MSET99 Talk
Games & Puzzles
Arithmetic/Algebra
Geometry
Probability
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
My Logo
Math Poll
Other Math sit's
Guest book
News sit's

Recommend this site

Manifesto: what CTK is about Search CTK Buying a book is a commitment to learning Table of content Products to download and subscription Things you can find on CTK Chronology of updates Email to Cut The Knot Recommend this page

CTK Exchange

Subject: "programmatically find eqns of tangent lines to 2 circles"     Previous Topic | Next Topic
Printer-friendly copy     Email this topic to a friend    
Conferences The CTK Exchange College math Topic #637
Reading Topic #637
jason z
guest
Jul-17-07, 11:05 PM (EST)
 
"programmatically find eqns of tangent lines to 2 circles"
 
   In reference to this page:

https://www.cut-the-knot.org/Curriculum/Geometry/TangentTwoCirclesII.shtml


I'd like to be able to write some code to draw the external tangent lines of two circles, but the only solutions I have found for the equations of these lines determine them analytically. Is there a way to find them programmatically? Any help would be greatly appreciated! Thanks!


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top

  Subject     Author     Message Date     ID  
programmatically find eqns of tangent lines to 2 circles jason z Jul-17-07 TOP
  RE: programmatically find eqns of tangent lines to 2 circles alexb Jul-17-07 1
     RE: programmatically find eqns of tangent lines to 2 circles mydogisarobot Jul-18-07 2
         RE: programmatically find eqns of tangent lines to 2 circles alexb Jul-18-07 3
             RE: programmatically find eqns of tangent lines to 2 circles mydogisarobot Jul-18-07 5
                 RE: programmatically find eqns of tangent lines to 2 circles alexb Jul-19-07 6
                 RE: programmatically find eqns of tangent lines to 2 circles mpdlc Jul-19-07 7
                     RE: programmatically find eqns of tangent lines to 2 circles mydogisarobot Jul-22-07 8
                         RE: programmatically find eqns of tangent lines to 2 circles alexb Jul-23-07 9
                     RE: programmatically find eqns of tangent lines to 2 circles mpdlc Jul-23-07 10
  RE: programmatically find eqns of tangent lines to 2 circles mpdlc Jul-18-07 4

Conferences | Forums | Topics | Previous Topic | Next Topic
alexb
Charter Member
2056 posts
Jul-17-07, 11:09 PM (EST)
Click to EMail alexb Click to send private message to alexb Click to view user profileClick to add this user to your buddy list  
1. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #0
 
   Honestly, I do not understand your question. You can program (hard code) an analytic expression. But, apparently, it is not what you want. So what might it be?

You of course know that the problem of finding the external tangent to two circles is solved by finding a tangent from a point to a circle.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mydogisarobot
Member since Jul-17-07
Jul-18-07, 06:28 AM (EST)
Click to EMail mydogisarobot Click to send private message to mydogisarobot Click to view user profileClick to add this user to your buddy list  
2. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #1
 
   The equations that I have (from the paper "Two circles and their common tangents") need to be used analytically - there aren't equations that specifically calculate the points of tangency (or the lines containing these points) given the location and radius of the two circles. I'm looking for equations, given two circles and their respective radii, that will give the points of tangency.

Sorry if the previous question wasn't thorough enough - my brain is a bit'soggy.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
alexb
Charter Member
2056 posts
Jul-18-07, 07:21 AM (EST)
Click to EMail alexb Click to send private message to alexb Click to view user profileClick to add this user to your buddy list  
3. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #2
 
   Please have a look at another page. The construction there seems to me simpler.

https://www.cut-the-knot.org/Curriculum/Geometry/TangentTwoCirclesI.shtml

The only thing that is assumed there is that one is able to find the points of intersection of two circles. But this is just solving a quadratic equation and selecting one of the two intersections.

Should anything be unclear, please refer your questions to specific steps in this construction.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mydogisarobot
Member since Jul-17-07
Jul-18-07, 11:57 PM (EST)
Click to EMail mydogisarobot Click to send private message to mydogisarobot Click to view user profileClick to add this user to your buddy list  
5. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #3
 
   Here's how I'm going to do it - please let me know if I'm making a misstep:

First, find the equation of the circle that has a radius equal to the distance between the centers of the two circles whose center lies on the line that passes through the centers of these circles.

Next, find the equation of the circle (whose origin is the center of the larger circle) with a radius equal to the difference of the radii of the two circles.

Then find the intersection of the two circles. These points can be used to find the angle of the radius that goes through the points, which in turn are used to find the tangent points on the circles. The intersections are found by using both circle equations to solve for either x or y, and then using that value to solve for the other unknown value.

I'm wondering if there's a better way to do this for my situation, though. I have two circles located somewhere in the Cartesian plane, and they are traveling along a path that is known (for instance, a sine curve). So at any given time, I know where the circles are and their respective radii. Is the method above still the best way to find the tangent lines, or could there be a better method?

Thanks so much for everyone's help thus far!


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
alexb
Charter Member
2056 posts
Jul-19-07, 00:09 AM (EST)
Click to EMail alexb Click to send private message to alexb Click to view user profileClick to add this user to your buddy list  
6. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #5
 
   >First, find the equation of the circle that has a radius
>equal to the distance

Half the distance

>between the centers of the two circles
>whose center lies

at the midpoint of the segment joining the centers of the given circles.

>Next, find the equation of the circle (whose origin is the
>center of the larger circle) with a radius equal to the
>difference of the radii of the two circles.
>
>Then find the intersection of the two circles. These points
>can be used to find the angle of the radius that goes
>through the points, which in turn are used to find the
>tangent points on the circles. The intersections are found
>by using both circle equations to solve for either x or y,
>and then using that value to solve for the other unknown
>value.

Yes, that's about right.

>I'm wondering if there's a better way to do this for my
>situation, though. I have two circles located somewhere in
>the Cartesian plane, and they are traveling along a path
>that is known (for instance, a sine curve). So at any given
>time, I know where the circles are and their respective
>radii. Is the method above still the best way to find the
>tangent lines, or could there be a better method?
>

I do not know.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mpdlc
guest
Jul-19-07, 09:14 AM (EST)
 
7. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #5
 
   The pure geometric method as indicated, even elegant in my opinion, it is not well suited for moving circumferences just as you suggest it is your purpose, since you have to solve discretely you only get isolated snapshot solutions without continuity.
Indeed that is an intrinsic problem dealing with Geometry, which is mainly static, and why Calculus appeared. So if you desire continuity to your solutions you are forced to use Analytical Geometry where you are capable to get the equations of your tangents with variable coefficients depending from a parameter let us say time t.

However even the analytic method I outlined in my last post it will work with circumferences with variable coordinates for center and radius by just making Xa=Xa(t) ; Ya=Ya(t) Ra=Ra(t) function of parameter t same with the radius and center of the other circumference, the whole procedure it will result a very cumbersome task.


I describe below a much direct way of approaching it analytically

1) We obtain the center of similitude of the to circumferences A and B

Being the equation for the circumferences

(x-Xa)^2+(y-Ya)^2 – Ra^2 = 0

(x-Xb)^2+(y-Yb)^2 – Rb^2 = 0

The coordinates for the center of similitude S are

Xs = (RaXb – RbXa)/(Rb –Ra); and Ys = (RaYb – RbYa)/(Rb –Ra)

Since as said above Xa, Ya, Ra, and Xb, Yb, Rb are variable so will be the coordinates for the center of similitude S


2) We express the equation of the tangent of for any arbitrary point (X1, Y1) in one of the circumferences, I suggest to use the one with simplest expression let us say circumference A

(x-Xa)X1+(y-Ya)Y1 – Ra^2 = 0

The above equation has to be valid also for the center of similitude so by substitution of x for Xs and y for Ys in the tangent equation and in the circumference equation (x-X1)^2+(y-Y1)^2 – Ra^2 = 0, resolving this two equations we will get two values for X1 and two values for Y1 which are the points of tangency in circumference A. Those two points are continuous variable functions of parameter t.

3) Finally we write the two equations for the lines passing by S and the two set (X1, Y1) that line is also tangent to circumference B

Obviously the step two is the one with more algebraically complex depending of the function that links the movement of the center, but by far the method is much more direct.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mydogisarobot
Member since Jul-17-07
Jul-22-07, 08:29 PM (EST)
Click to EMail mydogisarobot Click to send private message to mydogisarobot Click to view user profileClick to add this user to your buddy list  
8. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #7
 
   So I'm still having problems with this. In the geometrical method, I'm stuck when I set the equations of the two circles equal to each other. At this point, I get rid of the y^2 term but am left with one equation with both x and y in it. I'm not sure how to solve it in my program.

As for the other method, I'm not quite following it after the calculation of the center of similitude.

Some additional background: my program is written in Actionscript (Flash), so positions of elements are calculated at every step and then rendered.

After looking at the Common Tangents to Two Circles (I) Java applet, I noticed that TSOQ is a right trapezoid. The lengths of the sides of this trapezoid can be calculated, which produces the angle of the radius that intersects the tangent point of either circle:

The angle (in degrees) of the radius of circle O is just 90 - sin^-1(OU/OQ).

Or am I doing something wrong here? Thanks again for all the help. It's much appreciated!


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
alexb
Charter Member
2056 posts
Jul-23-07, 09:08 AM (EST)
Click to EMail alexb Click to send private message to alexb Click to view user profileClick to add this user to your buddy list  
9. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #8
 
   >So I'm still having problems with this. In the geometrical
>method, I'm stuck when I set the equations of the two
>circles equal to each other.

Detect and consider this case separately. The angles you keep mentioning (from the centers to the points of tangency) are in this case perpendicular to the line of centers.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mpdlc
Member since Mar-12-07
Jul-23-07, 11:15 AM (EST)
Click to EMail mpdlc Click to send private message to mpdlc Click to view user profileClick to add this user to your buddy list  
10. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #7
 
   In the particular case of the two circumference have the same radius R it is obvious that center of similitude is a point at infinite in the direction of line connecting the centers, but in this particular case is quite direct to obtain the equation for two tangent since the slope of tangents equal to the slope of the line joining the center and its distance to the center equal R

Below is the equation


(y-Ya) – m(x-Xa)/sqr (1+m^2) = + R ;
or minus R for the other tangent where as said m is the slope of line joining the centers
m =(Yb-Ya) /( Xb-Xa)

And since you plan to move the center around Xa = Xa(t) ; Ya =Ya(t) and
Xb = Xb(t) ; Yb =Yb(t) you can also make R=R(t) too.


I attach also a visual geometric method for the obtaining the coordinates of center of similitude as you can see if you make Rb equal to Ra the denominators become zero and coordinates for Xs and Ys are infinite

I guess you need some clarification on second paragraph that besides it contains an nomenclature error it was not properly and clearly expressed so disregarded it and take it as follows
What we have to do now is to substitute the expression of Xs in place of x and the one for Ys in the place of y in the equation of the tangent
(x-Xa)X1+(y-Ya)Y1 – Ra^2 = 0 it will become
(Xs-Xa)X1+(Ys-Ya)Y1 – Ra^2 = 0 (1)
This equation may result nasty depending of the equations selected for the moving centers so Xs = Xs(t) and Ys=Ys(t) can result bulky expressions.
Now since the point (X1 Y1) also belong to the circumference centered in A it must comply with its equation
(x-Xa)^2+(y-Ya)^2 – Ra^2 = 0
(X1-Xa)^2+(Y1-Ya)^2 – Ra^2 = 0 (2)

Now resolving this two equations (1) and (2) we will get two values for X1=X1(t) and two values for Y1(t) which are the points of tangency in circumference A. Tangent which will contain also (Xs Ys).Those two points are continuous variable functions of parameter t.


Those values of X1 and Y1 we can now substitue in (x-Xa)X1+(y-Ya)Y1 – Ra^2 = 0 and we finally get the two tangent equations

mpdlc

Attachments
https://www.cut-the-knot.org/htdocs/dcforum/User_files/46a4d10474d4d84f.gif

  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mpdlc
guest
Jul-18-07, 04:22 PM (EST)
 
4. "RE: programmatically find eqns of tangent lines to 2 circles"
In response to message #0
 
   The following is an alternative method base on Analytical Geometry

I assume you can program to draw a straight line given its analytical equation, that it is easy just take two point belonging to the line for instance.
I also assume you have from the shelf an algorithm for solving a quadratic equation.

Now coming to the subject of tangents let us define the line as

x cosα+ y sinα – p = 0 ;(1)

Remember we must get two sets of values for cosα sinα and p, since there are two exterior tangents.

Expressing the distance of above line to the center of the circle A (Xa, Ya) being Ra its radius and the the distance of to above line to the center of the circle B (Xb, Yb) being Rb its radius , since they are tangents.

We get the two equations system (2) below. In this equations cosα and sinα are the unknowns and p is taking as a parameter


Xa cosα+ Ya sinα = Ra + p ;(2)
Xb cosα+ Yb sinα = Rb + p

And the always auxiliary equation (cosα)^2+ (sinα)^2 = 1 ;(3)

Solving by the Cramer’s Rule the system (2) we get


cosα = ((Ra + p) Yb - (Rb + p)Ya) / (XaYb-XbYa) ;(4)
sinα = ((Rb + p) Xa - (Ra + p)Xb) / (XaYb-XbYa)

By substitution of cosα and sinα in the auxiliary equation (3) we get a quadratic equation in p which will render two values p1 and p2.
Again by substitution of p1 and p2 in (4) we will get two set of values for cosα and sinα .
Now plugging p1 an one set of cosα and sinα values in equation (1) we will get one tangent. We do same for p2 and the other set to obtain the other tangent.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top

Conferences | Forums | Topics | Previous Topic | Next Topic

You may be curious to have a look at the old CTK Exchange archive.
Please do not post there.

Copyright © 1996-2018 Alexander Bogomolny

Search:
Keywords:

Google
Web CTK