-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmid point ellipse drawing algorithm.cpp
More file actions
71 lines (63 loc) · 1.79 KB
/
Copy pathmid point ellipse drawing algorithm.cpp
File metadata and controls
71 lines (63 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <graphics.h>
#include <cmath>
void midPointEllipse(int x_radius, int y_radius, int x_c, int y_c)
{
float x = 0, y = y_radius;
//putpixel(x, y, WHITE);
float p = pow(y_radius, 2) + (1/4 * pow(x_radius, 2)) -(pow(x_radius, 2) * y_radius);
float dx = 2 * pow(y_radius, 2) * x;
float dy = 2 * pow(x_radius, 2) * y;
while (dx < dy)
{
putpixel(x + x_c, y + y_c, WHITE);
putpixel(-x + x_c, y + y_c, WHITE);
putpixel(x + x_c, -y + y_c, WHITE);
putpixel(-x + x_c, -y + y_c, WHITE);
if (p < 0)
{
x++;
dx += 2 * pow(y_radius, 2);
p += dx + pow(y_radius, 2);
}
else
{
x++;
y--;
dx += 2 * pow(y_radius, 2);
dy -= 2 * pow(x_radius, 2);
p += dx - dy + pow(y_radius, 2);
}
}
float p2 = ((pow(y_radius, 2)) *pow(x + 0.5, 2)) + (pow(x_radius, 2)*pow(y - 1, 2)) - (pow(x_radius, 2) * pow(y_radius, 2));
while(y >= 0)
{
putpixel(x + x_c, y + y_c, WHITE);
putpixel(-x + x_c, y + y_c, WHITE);
putpixel(x + x_c, -y + y_c, WHITE);
putpixel(-x + x_c, -y + y_c, WHITE);
if (p2 > 0)
{
y--;
dy -= 2 * pow(x_radius, 2);
p2 += pow(x_radius, 2) - dy;
}
else
{
y--;
x++;
dx += 2 * pow(y_radius, 2);
dy -= 2 * pow(x_radius, 2);
p2 += dx - dy + pow(x_radius, 2);
}
}
}
int main()
{
initwindow(600, 600, "MidPointEllipse");
//inputs
midPointEllipse(100, 75, 200, 125);
midPointEllipse(160, 250, 300, 300);
getch();
closegraph();
}