# Equation of circle from centre and radius

Given the centre of circle (x1, y1) and its radius r, find the equation of the circle having centre (x1, y1) and having radius r.

**Examples:**

Input :x1 = 2, y1 = -3, r = 8

Output :x^2 + y^2 – 4*x + 6*y = 51.

Input :x1 = 0, y1 = 0, r = 2

Output :x^2 + y^2 – 0*x + 0*y = 4.

**Approach:**

Given the centre of circle (x1, y1) and its radius r, we have to find the equation of the circle having centre (x1, y1) and having radius r.

the equation of circle having centre (x1, y1) and having radius r is given by :-

on expanding above equation

on arranging above we get

Below is the implementation of above approach:

## C++

`// CPP program to find the equation ` `// of circle. ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to find the equation of circle ` `void` `circle_equation(` `double` `x1, ` `double` `y1, ` `double` `r) ` `{ ` ` ` `double` `a = -2 * x1; ` ` ` ` ` `double` `b = -2 * y1; ` ` ` ` ` `double` `c = (r * r) - (x1 * x1) - (y1 * y1); ` ` ` ` ` `// Printing result ` ` ` `cout << ` `"x^2 + ("` `<< a << ` `" x) + "` `; ` ` ` `cout << ` `"y^2 + ("` `<< b << ` `" y) = "` `; ` ` ` `cout << c << ` `"."` `<< endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `x1 = 2, y1 = -3, r = 8; ` ` ` `circle_equation(x1, y1, r); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the equation ` `// of circle. ` `import` `java.util.*; ` ` ` `class` `solution ` `{ ` ` ` ` ` `// Function to find the equation of circle ` `static` `void` `circle_equation(` `double` `x1, ` `double` `y1, ` `double` `r) ` `{ ` ` ` `double` `a = -` `2` `* x1; ` ` ` ` ` `double` `b = -` `2` `* y1; ` ` ` ` ` `double` `c = (r * r) - (x1 * x1) - (y1 * y1); ` ` ` ` ` `// Printing result ` ` ` `System.out.print(` `"x^2 + ("` `+a+ ` `" x) + "` `); ` ` ` `System.out.print(` `"y^2 + ("` `+b + ` `" y) = "` `); ` ` ` `System.out.println(c +` `"."` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String arr[]) ` `{ ` ` ` `double` `x1 = ` `2` `, y1 = -` `3` `, r = ` `8` `; ` ` ` `circle_equation(x1, y1, r); ` ` ` `} ` ` ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find the ` `# equation of circle. ` ` ` `# Function to find the ` `# equation of circle ` `def` `circle_equation(x1, y1, r): ` ` ` `a ` `=` `-` `2` `*` `x1; ` ` ` ` ` `b ` `=` `-` `2` `*` `y1; ` ` ` ` ` `c ` `=` `(r ` `*` `r) ` `-` `(x1 ` `*` `x1) ` `-` `(y1 ` `*` `y1); ` ` ` ` ` `# Printing result ` ` ` `print` `(` `"x^2 + ("` `, a, ` `"x) + "` `, end ` `=` `""); ` ` ` `print` `(` `"y^2 + ("` `, b, ` `"y) = "` `, end ` `=` `""); ` ` ` `print` `(c, ` `"."` `); ` ` ` `# Driver code ` `x1 ` `=` `2` `; ` `y1 ` `=` `-` `3` `; ` `r ` `=` `8` `; ` `circle_equation(x1, y1, r); ` ` ` `# This code is contributed ` `# by mits ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the equation ` `// of circle. ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the equation of circle ` `public` `static` `void` `circle_equation(` `double` `x1, ` ` ` `double` `y1, ` ` ` `double` `r) ` `{ ` ` ` `double` `a = -2 * x1; ` ` ` ` ` `double` `b = -2 * y1; ` ` ` ` ` `double` `c = (r * r) - (x1 * x1) - (y1 * y1); ` ` ` ` ` `// Printing result ` ` ` `Console.Write(` `"x^2 + ("` `+ a + ` `" x) + "` `); ` ` ` `Console.Write(` `"y^2 + ("` `+ b + ` `" y) = "` `); ` ` ` `Console.WriteLine(c + ` `"."` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(` `string` `[]arr) ` `{ ` ` ` `double` `x1 = 2, y1 = -3, r = 8; ` ` ` `circle_equation(x1, y1, r); ` `} ` `} ` ` ` `// This code is contributed ` `// by SoumkMondal ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find the equation ` `// of circle. ` ` ` `// Function to find the ` `// equation of circle ` `function` `circle_equation(` `$x1` `, ` `$y1` `, ` `$r` `) ` `{ ` ` ` `$a` `= -2 * ` `$x1` `; ` ` ` ` ` `$b` `= -2 * ` `$y1` `; ` ` ` ` ` `$c` `= (` `$r` `* ` `$r` `) - (` `$x1` `* ` `$x1` `) - ` ` ` `(` `$y1` `* ` `$y1` `); ` ` ` ` ` `// Printing result ` ` ` `echo` `"x^2 + ("` `. ` `$a` `. ` `" x) + "` `; ` ` ` `echo` `"y^2 + ("` `. ` `$b` `. ` `" y) = "` `; ` ` ` `echo` `$c` `. ` `"."` `. ` `"\n"` `; ` `} ` ` ` `// Driver code ` `$x1` `= 2; ` `$y1` `= -3; ` `$r` `= 8; ` `circle_equation(` `$x1` `, ` `$y1` `, ` `$r` `); ` ` ` `// This code is contributed ` `// by Akanksha Rai ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

x^2 + (-4 x) + y^2 + (6 y) = 51.

## Recommended Posts:

- Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius
- Angle subtended by an arc at the centre of a circle
- Shortest distance from the centre of a circle to a chord
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Equation of circle when three points on the circle are given
- Number of rectangles in a circle of radius R
- Radius of the circle when the width and height of an arc is given
- Find minimum radius such that atleast k point lie inside the circle
- Angular Sweep (Maximum points that can be enclosed in a circle of given radius)
- Given equation of a circle as string, find area
- Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Check if a circle lies inside another circle or not
- Maximize a value for a semicircle of given radius

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.