# Distance between centers of two intersecting circles if the radii and common chord length is given

Given are two circles, with given radii, which intersect each other and have a common chord. The length of the common chord is given. The task is to find the distance between the centres of the two circles.

**Examples:**

Input:r1 = 24, r2 = 37, x = 40Output:44Input:r1 = 14, r2 = 7, x = 10Output:17

**Approach**:

- let the length of common chord
**AB**=**x** - Let the radius of the circle with centre
**O**is**OA**=**r2** - Radius of circle with centre
**P**is**AP**=**r1** - From the figure,
**OP**is perpendicular**AB**

**AC = CB**

**AC = x/2**(Since AB = x) - In triangle
**ACP**,

**AP^2 = PC^2+ AC^2**[By Pythagoras theorem]

**r1^2 = PC^2 + (x/2)^2**

**PC^2 = r1^2 – x^2/4** - Consider triangle
**ACO**

**r2^2 = OC^2+ AC^2**[By Pythagoras theorem]

**r2^2 = OC^2+ (x/2)^2**

**OC^2 = r2^2 – x^2/4** - From the figure,
**OP = OC + PC**

**OP = √( r1^2 – x^2/4 ) + √(r2^2 – x^2/4)** - Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles
- Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles
- Length of direct common tangent between the two non-intersecting Circles
- Length of direct common tangent between two intersecting Circles
- Length of the transverse common tangent between the two non intersecting circles
- Number of common tangents between two circles if their centers and radius is given
- Length of the perpendicular bisector of the line joining the centers of two circles
- Distance of chord from center when distance between center and another equal length chord is given
- Length of the chord the circle if length of the another chord which is equally inclined through the diameter is given
- Length of the direct common tangent between two externally touching circles
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Count ways to divide circle using N non-intersecting chord | Set-2
- Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius
- Shortest distance from the centre of a circle to a chord

Distance between the centres = sqrt((radius of one circle)^2 – (half of the length of the common chord )^2) + sqrt((radius of the second circle)^2 – (half of the length of the common chord )^2)

Below is the implementation of the above approach:

## C++

`// C++ program to find ` `// the distance between centers ` `// of two intersecting circles ` `// if the radii and common chord length is given ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `void` `distcenter(` `int` `r1, ` `int` `r2, ` `int` `x) ` `{ ` ` ` `int` `z = ` `sqrt` `((r1 * r1) ` ` ` `- (x / 2 * x / 2)) ` ` ` `+ ` `sqrt` `((r2 * r2) ` ` ` `- (x / 2 * x / 2)); ` ` ` ` ` `cout << ` `"distance between the"` ` ` `<< ` `" centers is "` ` ` `<< z << endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `r1 = 24, r2 = 37, x = 40; ` ` ` `distcenter(r1, r2, x); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find ` `// the distance between centers ` `// of two intersecting circles ` `// if the radii and common chord length is given ` `import` `java.lang.Math; ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` `static` `double` `distcenter(` `int` `r1, ` `int` `r2, ` `int` `x) ` `{ ` ` ` `double` `z = (Math.sqrt((r1 * r1) ` ` ` `- (x / ` `2` `* x / ` `2` `))) ` ` ` `+ (Math.sqrt((r2 * r2) ` ` ` `- (x / ` `2` `* x / ` `2` `))); ` ` ` ` ` `System.out.println (` `"distance between the"` `+ ` ` ` `" centers is "` `+ (` `int` `)z ); ` ` ` `return` `0` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `int` `r1 = ` `24` `, r2 = ` `37` `, x = ` `40` `; ` ` ` `distcenter(r1, r2, x); ` `} ` `} ` ` ` `// This code is contributed by jit_t. ` |

*chevron_right*

*filter_none*

## Python3

` ` `# Python program to find ` `# the distance between centers ` `# of two intersecting circles ` `# if the radii and common chord length is given ` ` ` `def` `distcenter(r1, r2, x): ` ` ` `z ` `=` `(((r1 ` `*` `r1) ` `-` `(x ` `/` `2` `*` `x ` `/` `2` `))` `*` `*` `(` `1` `/` `2` `)) ` `+` `\ ` ` ` `(((r2 ` `*` `r2)` `-` `(x ` `/` `2` `*` `x ` `/` `2` `))` `*` `*` `(` `1` `/` `2` `)); ` ` ` ` ` `print` `(` `"distance between thecenters is "` `,end` `=` `""); ` ` ` `print` `(` `int` `(z)); ` ` ` `# Driver code ` `r1 ` `=` `24` `; r2 ` `=` `37` `; x ` `=` `40` `; ` `distcenter(r1, r2, x); ` ` ` `# This code has been contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find ` `// the distance between centers ` `// of two intersecting circles ` `// if the radii and common chord length is given ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `static` `double` `distcenter(` `int` `r1, ` `int` `r2, ` `int` `x) ` `{ ` ` ` `double` `z = (Math.Sqrt((r1 * r1) ` ` ` `- (x / 2 * x / 2))) ` ` ` `+ (Math.Sqrt((r2 * r2) ` ` ` `- (x / 2 * x / 2))); ` ` ` ` ` `Console.WriteLine(` `"distance between the"` `+ ` ` ` `" centers is "` `+ (` `int` `)z ); ` ` ` `return` `0; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `r1 = 24, r2 = 37, x = 40; ` ` ` `distcenter(r1, r2, x); ` `} ` `} ` ` ` `// This code is contributed by jit_t ` |

*chevron_right*

*filter_none*

**Output:**

distance between the centers is 44

## Recommended Posts:

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.