You are on page 1of 6

ST.

XAVIER’S COLLEGE
MAITIGHAR, KATHMANDU

Computer Graphics (CG)

Lab Report 6
Circle Using Equation of Circle

Submitted by
Jeshika Baniya
019BIM017

Submitted to
Mr. Ganesh Yogi
Lecturer
Department of Computer Science
St. Xavier’s College
Equation of a Circle
In geometry, a circle can also be represented in the expanded form. It is the result of expanding
the binomial squares in the standard form and combining like terms. To find the equation of
circle we use the distance formula.
In this section, we will learn the standard and general form of the equation of a circle, and also
solve some problems based on it.
There are two forms of the equation of a circle:
 Standard Form
 General Form
Standard Form
If the equation of a circle is in standard form, we can easily find the center of the circle (h, k) and
the radius of the circle. The standard equation of a circle is:
(x-h)2+(y-k)2=r2
Where (h, k) is the coordinates of the center, and r is the radius of the circle. Remember that the
value of r is always positive.
General Form
The general form of the equation is the expanded form of the standard equation. We know the
standard equation of the circle:
(x-h)2+(y-k)2=r2…………(1)
Expanding the equation (1), we get:
x2+h2-2hx+y2+k2-2ky=r2
Rearrange the above equation, we get:
x2+y2-2hx-2ky+h2+k2=r2
x2+y2-2xh-2yk+h2+k2-r2=0…………(2)
Substitute the values of h, k, and r by the following values, we get:
h=-g,k=-f,c=h2+k2-r2
Put these values in the equation (2), we get:
x2+y2-2x(-g)-2y(-f)+c=0
Where (-g, -f) is the center of the circle, and the radius (r) is √g2+f2-c2.
x2+y2+2gx+2fy+c=0
Where g, f, and c are constants.

We can further substitute the values 2g, 2f, and c by D, E, and F, respectively.
x2+y2+Dx+Ey+F=0
Algorithm
Step 1: Set the initial variables
r = circle radius
(h, k) = coordinates of circle center
x=o
I = step size

xend=
Step 2: Test to determine whether the entire circle has been scan-converted.
If x > xend then stop.

Step 3: Compute y =
Step 4: Plot the eight points found by symmetry concerning the center (h, k) at the current (x, y)
coordinates.
Plot (x + h, y +k) Plot (-x + h, -y + k)
Plot (y + h, x + k) Plot (-y + h, -x + k)
Plot (-y + h, x + k) Plot (y + h, -x + k)
Plot (-x + h, y + k) Plot (x + h, -y + k)
Step 5: Increment x = x + i
Step 6: Go to step 2
Program: Circle using Equation of Circle
package jeshika;
import javax.swing.*;
import java.awt.*;
public class eqnofcircle extends JFrame{
eqnofcircle(){
setSize(500,500);
setTitle("CIRCLE");
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g){
int h=150,k=150,radius=40,x=0;
double xend=radius/Math.sqrt(2);
while(x <= xend){
int y=(int)(Math.sqrt(radius*radius - x*x));
g.fillOval(x + h, y + k, 2, 2);
g.fillOval(-x + h, y + k, 2, 2);
g.fillOval(x + h, -y + k, 2, 2);
g.fillOval(-x + h, -y + k, 2, 2);
g.fillOval(y + h, x + k, 2, 2);
g.fillOval(-y + h, -x + k, 2, 2);
g.fillOval(-y + h, x + k, 2, 2);
g.fillOval(y + h, -x + k, 2, 2);
x++; } }
public static void main(String[] args0{
new eqnofcircle(); }
}
Output:

You might also like