# Shortest distance from the centre of a circle to a chord

Given a circle which has a chord inside it. The length of the chord and the radius of the circle are given. The task is to find the shortest distance from the chord to the centre.

**Examples:**

Input:r = 4, d = 3Output:3.7081Input:r = 9.8, d = 7.3Output:9.09492

**Approach**:

**r**

**d**

**OBC**,

from **pythagorus theorem**,

**OB^2 + (d/2)^2 = r^2**

so, **OB = √(r^2 – d^2/4)**

Below is the implementation of the above approach:

## C++

`// C++ program to find ` `// the shortest distance from ` `// chord to the centre of circle ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the shortest distance ` `void` `shortdis(` `double` `r, ` `double` `d) ` `{ ` ` ` `cout << ` `"The shortest distance "` ` ` `<< ` `"from the chord to centre "` ` ` `<< ` `sqrt` `((r * r) - ((d * d) / 4)) ` ` ` `<< endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `r = 4, d = 3; ` ` ` `shortdis(r, d); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find ` `// the shortest distance from ` `// chord to the centre of circle ` `class` `GFG ` `{ ` ` ` `// Function to find the shortest distance ` `static` `void` `shortdis(` `double` `r, ` `double` `d) ` `{ ` ` ` `System.out.println(` `"The shortest distance "` ` ` `+ ` `"from the chord to centre "` ` ` `+ (Math.sqrt((r * r) - ((d * d) / ` `4` `)))); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `double` `r = ` `4` `, d = ` `3` `; ` ` ` `shortdis(r, d); ` `} ` `} ` ` ` `/* This code contributed by PrinciRaj1992 */` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find ` `# the shortest distance from ` `# chord to the centre of circle ` ` ` `# Function to find the shortest distance ` `def` `shortdis(r, d): ` ` ` `print` `(` `"The shortest distance "` `,end` `=` `""); ` ` ` `print` `(` `"from the chord to centre "` `,end` `=` `""); ` ` ` `print` `(((r ` `*` `r) ` `-` `((d ` `*` `d) ` `/` `4` `))` `*` `*` `(` `1` `/` `2` `)); ` ` ` `# Driver code ` `r ` `=` `4` `; ` `d ` `=` `3` `; ` `shortdis(r, d); ` ` ` `# This code has been contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find ` `// the shortest distance from ` `// chord to the centre of circle ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find the shortest distance ` ` ` `static` `void` `shortdis(` `double` `r, ` `double` `d) ` ` ` `{ ` ` ` `Console.WriteLine(` `"The shortest distance "` ` ` `+ ` `"from the chord to centre "` ` ` `+ (Math.Sqrt((r * r) - ((d * d) / 4)))); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `double` `r = 4, d = 3; ` ` ` `shortdis(r, d); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` ` ` `// PHP program to find ` `// the shortest distance from ` `// chord to the centre of circle ` ` ` ` ` `// Function to find the shortest distance ` `function` `shortdis(` `$r` `, ` `$d` `) ` `{ ` ` ` `echo` `"The shortest distance "` `; ` ` ` `echo` `"from the chord to centre "` `; ` ` ` `echo` `sqrt((` `$r` `* ` `$r` `) - ((` `$d` `* ` `$d` `) / 4)); ` `} ` ` ` `// Driver code ` ` ` `$r` `= 4; ` ` ` `$d` `= 3; ` ` ` `shortdis(` `$r` `, ` `$d` `); ` ` ` `// This code is contributed by Naman_Garg. ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

The leshortest distance from the chord to centre 3.7081

## Recommended Posts:

- Shortest distance between a point and a circle
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- 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
- Equation of circle from centre and radius
- Angle subtended by an arc at the centre of a circle
- Find the Diameter or Longest chord of a Circle
- Count ways to divide circle using N non-intersecting chord | Set-2
- Distance between centers of two intersecting circles if the radii and common chord length is given
- Shortest distance between a Line and a Point in a 3-D plane
- Find the shortest distance between any pair of two different good nodes
- Check whether it is possible to join two points given on circle such that distance between them is k
- Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given

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.