math,geometry,line,circle , Find line that is tangent to 2 given circles

Find line that is tangent to 2 given circles


Tag: math,geometry,line,circle

I've got a situation in which I have 2 circles (C1 and C2) and i need to find the line equation for the line that is tangent to both of these circles.

So as far as i'm aware, given a single point (P1) and C2's point and radius it is possible to quite easily get 2 possible points of tangency for C2 and P1 to make 2 line equations. But as i don't have P1, only the knowledge that the point will be one of a possible 2 points on C1, i'm not sure how to calculate this.

I assume it will be something along the lines of getting the 2 tangent line equations of C1 that are equal to the same of C2.

Both circles can have any radius, they could be the same or they could be hugely different. They will also never overlap (they can still touch though). And I'm looking for the 2 possible internal tangents.

Oh, and also, visuals would be very helpful haha :)


Let O be the intersection point between the line through the centers and the tangent.

Let d be the distance between the centers and h1, h2 be the distances between O and the centers. By similarity, these are proportional to the radii.


h1 / h2 = r1 / r2 = m,
h1 + h2 = d,


h1 = m d / (1 + m),
h2 =   d / (1 + m).

Then the coordinates of O are found by interpolating between the centers

xo = (h2.x1 + h1.x2) / d
yo = (h2.y1 + h1.y2) / d

and the angle of the tangent is that of the line through the centers plus or minus the angle between this line and the tangent,

a = arctan((y2 - y1)/(x2 - x1)) +/- arcsin(r1 / h1).

You can write the implicit equation of the tangent as

cos(a).y - sin(a).x = cos(a).yo - sin(a).xo.


implement pow in java without using math lib

I did a code like this: public static double myPow(double x, int n){ if(n==0) return 1; double t = myPow(x, n/2); if(n % 2 != 0){ if(n < 0){ return (1 / t * t * x); } else { return t * t * x; } } else {...

LinkedHashSet and subList, getting n of collection

I am trying to do a homework in math which is find a subset of collection {1,2,..,n} where n is a number given in the code, I cannot get it done with the sublist so I need to get your help with a math programming. For example for n =...

Determining angles on an SVG path between two lines

I'm trying to make my robot follow a path that is a drawn SVG path on a webpage. To keep it simple, assume that the SVG Is like so: <svg xmlns=""> <path id="path" d="M 100 100 L 300 300 L 100 500 z"> </svg> Which makes a triangle. The robot...

Have I properly sorted these runtimes in order of growth?

I am doing this small task which I have to arrange asymptotic runtime in ascending order. Here are the runtimes: Here is the order I believe they should go in: log10(n^4), n^3, 2^((log4n)), 2^(100n), e^pi^4096, n! + 12^1000 Is this correct? Or are there any errors? Thanks!...

Arithmetic on a struct representing a large integer

I've wrote an implementation of Murmur3 hash and have defined the 128-bit keys as hash128_t typedef struct { uint64_t p1; uint64_t p2; } hash128_t; I'm trying to write my own hashmap using these keys, but I'm not exactly sure how to do arithmetic with a struct nor a number this...

How to calculate a random point inside a cube

I'm trying to figure out the math to find a random point inside a cube. I have something small but it can't take into account the rotation of the cube. Here are some images of my results. Here you can see the cube is rotated to some degree but when...

Math operations within HTML

Is it possible to perform math operations within HTML, like <div width="50/2">? Or can this only be done using Javascript or CSS?

generating a pseudo unique number(code) based on a sequence of numbers with no repetition within 4 digits

I'm generating a somewhat unique code that I don't want to repeat within at least 1000 consecutive numbers this is my function. take a number multiply it by another number then take the last $length=5 digits before the decimal point function createPseudoUniqueString($input,$length) { return substr( intval($input*738510.93067),-$length) ; } is there...

Reversing RotateAxisAngle back to angles

I'm trying to figure out how to reverse RotateAxisAngle to get back rotations around these arbitrary axes (or equivalent rotations that yield same net rotation, doesn't have to be identical). Does anyone know how to do it? I'm using MathGeoLib, but I don't see an opposite way, to return back...

Convert a large int to a float between 0.0f and 1.0f

I'm working on a project where I have a pane that goes from 0 to 500 on the x and z, but I need to convert that coordinate (from 0 to 500) to a float in the range of 0.0 to 1.0 in because it is required from some of...

Power by squaring for negative exponents

I am not sure if power by squaring takes care of negative exponent. I implemented the following code which works for only positive numbers. #include <stdio.h> int powe(int x, int exp) { if (x == 0) return 1; if (x == 1) return x; if (x&1) return powe(x*x, exp/2); else...

2D Line reflection on a “mirror”

So I've been working at this on and off for a week, googling and all and I haven't found how to do this. I have a table of "rays" and a table of "lines", and I want the lines to act as mirrors and reflect a ray whenever the ray...

Bash script for basic mathematic operations

I am new to Linux, and I just want a Bash Script to do basic arithmetic operation to a text file 1 2 3 4 and the results should be addition and multiplication in separate text files say add + 5 for 1st text file and mult * 5 in...

Ranking with time weighting

I am looking for a basic algorithm that gives more weigh to the recent reviews. So, the output value of the algorithm is mutable. For example, two reviews with exactly the same score, will have a different ranking based on the timestamp of the creation. Review_1 Score 10 creation 10/5/2014...

Separating axis theorem: rotation around center of mass

The problem is in Polygon::FindAxisLeastPenetration: double Polygon::FindAxisLeastPenetration(unsigned int *faceIndex, const Polygon &polygonA, const Polygon &polygonB) const { double bestDistance = -std::numeric_limits<double>::infinity(); unsigned int bestIndex; for (unsigned int i = 0; i < polygonA.points.size(); i++) { Vector2D n = polygonA.normals[i]; Vector2D nw = polygonA.rotationMatrix * n; //ROTATION Matrix22 buT = polygonB.rotationMatrix.Transposed();...

fixed point multiplication for normal multiplication

I need to multiply X with a floating point number in floating point as i don't have floating point operations in my processor. I understand the method but don't know why that method exists? Suppose we want to multiply 2*4.5 in decimal I do the below: 2 * 4.5 (100.1)...

sum of series AP GP clrs appendix A.1-4

I am trying to prove an equation given in the CLRS exercise book. The equation is: Sigma k=0 to k=infinity (k-1)/2^k = 0 I solved the LHS but my answer is 1 whereas the RHS should be 0 Following is my solution: Let's say S = k/2^k = 1/2 +...

Excel log equivilent to JS Math.log()

In my javascript code I have the following Math.log(20) = 2.995732273553991 In my excel formula I try to replicate this with =LOG(20) = 1.301029996 Anyone have any idea why I'm getting two different outcomes? I'd like my excel to match my js. ...

PHP math does not work in sql value ZERO

I am trying to math between value of 0 but in php code it's work properly but when that value come from database then it does not work. Here is a demo to test only PHP code: <?php $a = 0; echo $a+1; ?> The result of this code 1...

Rotate a grid of points in C++

If i had an array of point structs defined as struct Point{ float x; float y; }; How would I rotate the points in this array by a given angle? As an example: Any help would be appreciated!...

Matlab: Writing to a file

I want to store mean_2....mean_8, std_2....std_8, and coVariance as separate columns in a file. Help Please? This Code calculates IntervalFeatures of Erp signal with 256 time frames and plots them Datapoints are store in A ___________HowTheCodeWorks________________________________________________ each 1x4 sliding sub-matrix is made a column for eg:- if A is...

How to get a pizza program to round to a full pizza In PYTHON [duplicate]

This question already has an answer here: How do you round UP a number in Python? 9 answers Python round up integer to next hundred 6 answers so i'm making a pizza program in Python 3.3 that takes input from the user and prints the amount of pizza's needed....

Calculate The object angle(face) having two points? [closed]

C++, I want calculate the angle of the direction of the two points. Here is a picture which shows the two points and the direction of how to get the angle of the direction? p1 - start point. p2 - direction point. me need direction angle(facing?) from p1 to p2...

Issues With length() And Multiples Of 3

Lets see if someone can wrap their head around this: if you get the length of a String using length(), the String always being multiples of 3,(in my case: " etc.") each 3 characters representing a letter, with .1 indicating a capitol letter, how do you use the length to...

Solving a complex recurrence relation for the Traveling Salesman

I need to solve the exact time complexity for the brute force version of the Traveling Salesman using a recurrence relation. I've worked out the recurrence relation to be as follows: T(n)=T(n-1)*(n-1)+1 But I'm having trouble reducing that that to a closed form of the function, and thus get the...

Why we use CORDIC gain?

I'm studying the cordic. And I found the cordic gain. K=0.607XXX. From CORDIC, K_i = cos(tan^-1(2^i)). As I know the K is approched 0.607xxx.when I is going to infinity this value come up with from all K multiplying. I understand the reason of exist each k. But I am curioused...

c++ mathematical calculations [closed]

I have to solve problem using c++, and can't really come up with solution. The condition is. In a skyscraper there are a lot of offices, on every office door there must be put plate with its number from 1 to the number of the last office. The plate can...

How to calculate the number of all possible combinations for a range of numbers from 1 to N?

Other than doing this: from itertools import combinations def brute_force(x): for l in range (1,len(x)+1): for f in list(combinations(range(0,len(x)),l)): yield f x = range(1,18) len(list(brute_force(x))) [out]: 131071 How could I mathematically calculate the number of all possible combinations? Is there a way to do it computationally without enumerating the possible...

Matlab: For loop with window array

This is my one dimensional array A, containing 10 numbers: A = [-8.92100000000000 10.6100000000000 1.33300000000000 ... -2.57400000000000 -4.52700000000000 9.63300000000000 ... 4.26200000000000 16.9580000000000 8.16900000000000 4.75100000000000]; I want the loop to go through like this; (calculating mean interval wise) - Interval length of 2,4,8 (a(1)+a(2))/2 - value stored in one block of...

How can we use cordic to tanh(x+1)/tanh(x)?

How can we use cordic to tanh(x+1)/tanh(x) I can't get a idea about how to apply cordic to above function. In other word, which point on the above function, can we apply cordic?...

Rotate line segment with Button

I have a line which has points (x1,y1) and (x2,y2). I wanted to attach a Button to it, it should align with the line by rotating based on the line segment points. I need some help in calculating the rotation angle for the Button.

randint() unexpected behavior

I'm writing a python script to find out some things about randomization. I have the following code: from random import randint one = 0 two = 0 olddiff = 0 diff = 0 sumdiff = 0 avgdiff = 0 headcounter = 0 counter = 0 while (headcounter < 500000): while...

why when i change slaying in the last else statment it crashes the browser

i was playing around in code academy and for some reason when i change the last slaying i the else statement to true instead of making the person invincible it just crashes my browser any ideas why thank you in advance var slaying = true; var youHit = Math.floor(Math.random()*2); var...

Sort list of coordinates

I have the following problem: I have a list of all the x, y coordinates of a polygon's points. I now need to sort them in such a way that I obtain the points in a clockwise order. Currently I have the 6 coordinates to draw a polygon but its...

XSLT remove data if attribute value is higher than threshold

I am newbie to XSLT. My am is to remove elements from XML based on a field if it is higher than some threshold value which I will be getting as parameter to it. My XML is as shown below: <tns:PM objectClass="MyNode" objectName="" className="com.project.converter.PMFamilyConverter" interfaceName="ComponentPM" xmlns:tns="http://www.myproject/SS/PMSchema" xmlns:xsi="" xsi:schemaLocation=""> <tns:family desc="family0"...

calculate % change in javascript

var current = 12000; var june = 14600; var may = 11200; I want percent change with respect to 'current' month parameter. The output should be in percent and it can add or subtract w.r.t. the current month. How to do this?...

Points, Vectors, Dot Product & Cross Product of python [on hold]

Need help with this of python Write a program with 3 functions to find out the (function 1) dot product, (function 2) angle, and (function 3) cross product of two vectors. Program should ask a user to input three points in 3D space such as (x1, y1, z1), (x2, y2,...

Visually midway between two points on a x axis log scale [closed]

The follow plot shows my question: I would like to add a line between the points of 1e-1 and 1e-2. So I thought just (1e-1+1e-2)/2. But for a log scale that is not "midway". How can I calculate the "visual" midway value between these, or any two points in this...

How is the Point2D “angle” method to be understood?

I thought I'd use the Point2D class for calculating e. g. the angle betwen 2 points instead of creating a utility method. It turned out, it's not usable at all. Code example: Point2D p1; Point2D p2; p1 = new Point2D(0, 0); p2 = new Point2D(10, 10); System.out.println( "Point2D: " +...

How to get rid of scale factor from CORDIC

From CORDIC, K_i = cos(tan^-1(2^i)). As I know the K is approached 0.607xxx. How do I approach to 0.607xxx? Also does it mean that I can use 0.607xxx instead of cos(tan^-1(2^I))? I am citing from this article. I am trying to implement hyperbolic tanh function. And so far I understand...

3 X 3 magic square recursively

I'm trying to find all possible solutions to the 3X3 magic square. There should be exactly 8 solutions. My code gets them all but there are a lot of repeats. I'm having a hard time tracking the recursive steps to see why I'm getting all the repeats. // This program...

What is the reason behind calculating GCD in Pollard rho integer factorisation?

This is the pseudo code for calculating integer factorisation took from CLRS. But what is the point in calculating GCD involved in Line 8 and the need for doubling k when i == k in Line 13.? Help please....

How can I correctly convert geographical coordinates to pixels on screen?

I'm trying to make a Java project that pinpoints the place on a image of a map, when given coordinates (taken from Google Maps). I've tried using the top-left corner of the image (place that has highest latitude, and the lowest longitude), as an some kind of an reference point,...

Implement pow(x, n)

Why does this function give the wrong answer -1 rather than the right answer 1 when I try this? myPow(-1.00000, -2147483648) double QuickPower(double x, int n) { if(n==0){ return 1; } if(n==1){ return x; } if(n>=2){ int res=n%2; double half=QuickPower(x,n/2); return res? Half*half*x: half*half; } } double myPow(double x, int...

Reverse ^ operator for decryption

I'm trying to reverse the following code in order to provide a function which takes the buffer and decrypts it. void crypt_buffer(unsigned char *buffer, size_t size, char *key) { size_t i; int j; j = 0; for(i = 0; i < size; i++) { if(j >= KEY_SIZE) j = 0;...

Quaternion to EulerXYZ, how to differentiate the negative and positive quaternion

I've been trying to figure out the difference between these, and why ToEulerXYZ does not get the right rotation. Using MathGeoLib: axisX: x 0.80878228 float y -0.58810818 float z 0.00000000 float axisY: x 0.58811820 float y 0.80877501 float z 0.00000000 float axisZ: x 0.00000000 float y 0.00000000 float z 1.0000000...

Removing a prior sample while using Welford's method for computing single pass variance

I'm successfully using Welford's method to compute running variance and standard deviation as described many times on Stack Overflow and John D Cook's excellent blog post. However in the stream of samples, sometimes I encounter a "rollback", or "remove sample" order, meaning that a previous sample is no longer valid...