Lecture 4
Lecture 4
R2 = x2 + y2
this equation supposes that we will start in (0,0) but if we start in another
position such as xc,yc
then x= x-xc and y= y-yc
R2 = (x-xc)2 + (y-yc)2
Y = yc±√𝑟 2 + 𝑥 − 𝑥𝑐 2
في الجزء الموجب والسالبy هتخلينا نرسمx مرة موجب ومرة سالب وبالتالي زيادةy ليها قيمة منx وبالتالي اصبحت كل
Example
"Draw a circle from the point (20, 20) with a radius of 10."
Then we will calculate the negative value for this
We will find pixels assuming that the Center is at Origin (0,0) then we will
add the coordinates of the center to the corresponding X and Y while drawing
a circle on the screen.
The points generation using the Mid-Point Circle Drawing Algorithm involves
the following steps-
Step-01:
P0 = 1 – R
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Follow the two cases
Example
Given the center point coordinates (0, 0) and radius as 10, generate all the
points to form a circle.
Solution
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 10
Step-01:
X0 = 0
Y0 = R = 10
Step-02:
Step-03:
0 -9 1 10 2 20
1 -6 2 10 4 20
2 -1 3 10 6 20
3 6 4 9 8 18
4 -3 5 9 10 18
5 8 6 8 12 16
6 5 7 7 14 14
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
Circle (Xc,Yc,X,Y) {
Plot (Y+Xc , X+Yc) ……Octet-1
Plot (X+Xc , Y+Yc) ……Octet-2
Plot (-X+Xc , Y+Yc) ……Octet-3
Plot (-Y+Xc , X+Yc) …..Octet-4
Plot (-Y+Xc , -X+Yc) ……Octet-5
Plot (-X+Xc , -Y+Yc) ……Octet-6
Plot (X+Xc , -Y+Yc) ……Octet-7
Plot (Y+Xc , -X+Yc) ……Octet-8
}
#include<iostream>
int x = r, y = 0;
// after translation
if (r > 0)
while (x > y)
y++;
if (P <= 0)
P = P + 2*y + 1;
else
x--;
P = P + 2*y - 2*x + 1;
if (x < y)
break;
// Printing the generated point and its
reflection
if (x != y)
}
}
// Driver code
int main()
midPointCircleDraw(0, 0, 3);
return 0;
Output: