Given a circle with a given radius has its centre at a particular position in the coordinate plane. In the coordinate plane, another point is given. The task is to find the shortest distance between the point and the circle.

**Examples:**

Input:x1 = 4, y1 = 6, x2 = 35, y2 = 42, r = 5Output:42.5079Input:x1 = 0, y1 = 0, x2 = 5, y2 = 12, r = 3Output:10

**Approach**:

**r**

**(x1, y1)**

**(x2, y2)**

**d**

which is equal to

**(d-r)**

**d = √((x2-x1)^2 – (y2-y1)^2)**

**BC = √((x2-x1)^2 – (y2-y1)^2) – r**

Below is the implementation of the above approach:

## C++

`// C++ program to find ` `// the Shortest distance ` `// between a point and ` `// a circle ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the shortest distance ` `void` `dist(` `double` `x1, ` `double` `y1, ` `double` `x2, ` `double` `y2, ` `double` `r) ` `{ ` ` ` `cout << ` `"The shortest distance "` ` ` `<< ` `"between a point and a circle is "` ` ` `<< ` `sqrt` `((` `pow` `((x2 - x1), 2)) ` ` ` `+ (` `pow` `((y2 - y1), 2))) ` ` ` `- r ` ` ` `<< endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `x1 = 4, y1 = 6, ` ` ` `x2 = 35, y2 = 42, r = 5; ` ` ` `dist(x1, y1, x2, y2, r); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find ` `// the Shortest distance ` `// between a point and ` `// a circle ` `class` `GFG ` `{ ` ` ` `// Function to find the shortest distance ` `static` `void` `dist(` `double` `x1, ` `double` `y1, ` `double` `x2, ` ` ` `double` `y2, ` `double` `r) ` `{ ` ` ` `System.out.println(` `"The shortest distance "` ` ` `+ ` `"between a point and a circle is "` ` ` `+ (Math.sqrt((Math.pow((x2 - x1), ` `2` `)) ` ` ` `+ (Math.pow((y2 - y1), ` `2` `))) ` ` ` `- r)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `double` `x1 = ` `4` `, y1 = ` `6` `, ` ` ` `x2 = ` `35` `, y2 = ` `42` `, r = ` `5` `; ` ` ` `dist(x1, y1, x2, y2, r); ` `} ` `} ` ` ` `/* This code contributed by PrinciRaj1992 */` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find ` `# the Shortest distance ` `# between a point and ` `# a circle ` ` ` `# Function to find the shortest distance ` `def` `dist(x1, y1, x2, y2, r): ` ` ` `print` `(` `"The shortest distance between a point and a circle is "` ` ` `,((((x2 ` `-` `x1)` `*` `*` `2` `) ` `+` `((y2 ` `-` `y1)` `*` `*` `2` `))` `*` `*` `(` `1` `/` `2` `)) ` `-` `r); ` ` ` ` ` `# Driver code ` `x1 ` `=` `4` `; ` `y1 ` `=` `6` `; ` `x2 ` `=` `35` `; ` `y2 ` `=` `42` `; ` `r ` `=` `5` `; ` `dist(x1, y1, x2, y2, r); ` ` ` ` ` `# This code has been contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the Shortest distance ` `// between a point and a circle ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the shortest distance ` `static` `void` `dist(` `double` `x1, ` `double` `y1, ` `double` `x2, ` ` ` `double` `y2, ` `double` `r) ` `{ ` ` ` `Console.WriteLine(` `"The shortest distance "` ` ` `+ ` `"between a point and a circle is "` ` ` `+ (Math.Sqrt((Math.Pow((x2 - x1), 2)) ` ` ` `+ (Math.Pow((y2 - y1), 2))) ` ` ` `- r)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `double` `x1 = 4, y1 = 6, ` ` ` `x2 = 35, y2 = 42, r = 5; ` ` ` `dist(x1, y1, x2, y2, r); ` `} ` `} ` ` ` `/* This code contributed by PrinciRaj1992 */` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find ` `// the Shortest distance ` `// between a point and ` `// a circle ` ` ` `// Function to find the shortest distance ` `function` `dist(` `$x1` `, ` `$y1` `, ` `$x2` `, ` `$y2` `, ` `$r` `) ` `{ ` ` ` `echo` `"The shortest distance between a point and a circle is "` ` ` `,sqrt((pow((` `$x2` `- ` `$x1` `), 2)) ` ` ` `+ (pow((` `$y2` `- ` `$y1` `), 2))) ` ` ` `- ` `$r` `; ` `} ` ` ` `// Driver code ` `$x1` `= 4; ` `$y1` `= 6; ` `$x2` `= 35; ` `$y2` `= 42; ` `$r` `= 5; ` `dist(` `$x1` `, ` `$y1` `, ` `$x2` `, ` `$y2` `, ` `$r` `); ` ` ` `// This code is contributed by AnkitRai01 ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

The shortest distance between a point and a circle is 42.5079

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Shortest distance between a Line and a Point in a 3-D plane
- Shortest distance from the centre of a circle to a chord
- Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Find the shortest distance between any pair of two different good nodes
- Perpendicular distance between a point and a Line in 2 D
- Distance between a point and a Plane in 3 D
- 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
- Check whether it is possible to join two points given on circle such that distance between them is k
- Distance of chord from center when distance between center and another equal length chord is given
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Area of the circle that has a square and a circle inscribed in it
- Check if any point overlaps the given Circle and Rectangle
- Shortest distance to every other character from given character
- Equation of circle when three points on the circle are given
- Check if a circle lies inside another circle or not
- 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
- Check whether a point exists in circle sector or not.
- Find if a point lies inside a Circle

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.