# Form Equation of Circle from Given Radius and Centre in Java

A circle is a closed shape formed by tracing a point that moves in a plane such that its distance from a given point is constant. In this article we will check how to form the equation of circle from given radius and centre.

We will be given a circle with centre i.e (x1, y1) and radius r. We need to form the equation of circle from given radius and centre. The equation of the circle is given by formula −

$$\mathrm{(x-x1)^2\:+\:(y-y1)^2\:=\:r^2}$$

Now after expanding and arranging the equation we get −

$$\mathrm{(x)^2\:–\:(2*x1*x)\:+\:(y)^2\:-\:(2*y1*y)\:=\:(r)^2\:-\:(x1)^2\:-\:(y1)^2}$$

Let’s start!

## To show you some instances

### Instance-1

• Given inputs for centre and radius are −

• Centre = (5, -2), Radius = 7

• After finding the equation of the circle the result will be −

• Equation of the circle is −

$$\mathrm{x^2\:+\:(-10.0\:x)\:+\:y^2\:+\:(4.0\:y)\:=\:20.0.}$$

### Instance-2

• Given inputs for centre and radius are −

• Centre = (9, 3), Radius = 7

• After finding the equation of the circle the result will be −

• Equation of the circle is −

$$\mathrm{x^2\:+\:(-18.0\:x)\:+\:y^2\:+\:(-6.0\:y)\:=\:-41.0.}$$

## Algorithm

• Step-1 − Declare and initialize the variables.

• Step-2 − Putting the values in formula.

• Step-3 − Getting the values.

• Step-4 − Print the result.

## Multiple Approaches

We have provided the solution in different approaches.

• By Using Static Input

• By Using User Defined Method

Let’s see the program along with its output one by one.

## Approach-1: By Using Static Input

In this approach, value of centre and radius will be initialized int the program. Then as per the algorithm we will find if the equation of circle from given radius and centre.

### Example

public class Main{
public static void main(String arg[]){

//declaring variables
double x1 = 9, y1 = 3, r = 7;

//applying logic
double m = -2 * x1;
double n = -2 * y1;
double o = (r * r) - (x1 * x1) - (y1 * y1);

// Printing the result
System.out.println("Equation of the circle is:");
System.out.println("x^2 + (" + m + " x) + " + "y^2 + ("+ n + " y) = " + o +".");
}
}


### Output

Equation of the circle is:
x^2 + (-18.0 x) + y^2 + (-6.0 y) = -41.0.


## Approach-2: By Using User Defined Method

In this approach, value of centre and radius will be initialized int the program. Then the user defined method will be called by passing these values as parameter. Inside method as per the algorithm we will find if the equation of circle from given radius and centre.

### Example

public class Main{
//main method
public static void main(String arg[]){

//declaring variables
double x1 = 5, y1 = -2, r = 7;

//calling user defined method
equation_circle(x1, y1, r);
}

//user defined method
static void equation_circle(double x1, double y1, double r){

//applying logic
double m = -2 * x1;
double n = -2 * y1;
double o = (r * r) - (x1 * x1) - (y1 * y1);

// Printing the result
System.out.println("Equation of the circle is:");
System.out.println("x^2 + (" + m + " x) + " + "y^2 + ("+ n + " y) = " + o +".");
}
}


### Output

Equation of the circle is:
x^2 + (-10.0 x) + y^2 + (4.0 y) = 20.0.


In this article, we explored how to find the equation of circle from given radius and centre by using Java programming language.

Updated on: 04-May-2023

131 Views 