-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathellipseKennedy.py
69 lines (56 loc) · 1.58 KB
/
ellipseKennedy.py
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
def BresenhemEllipse(rx,ry,cx,cy):
twoAsqr = 2*rx*rx
twoBsqr = 2*ry*ry
x = rx
y = 0
xchange = ry*ry*(1-(2*rx))
ychange = rx*rx
ellipse_error = 0
stoppingX = twoBsqr*rx
stoppingY = 0
result = []
temp = []
while(stoppingX >= stoppingY):
result.append((cx+x, cy+y)) # Q1
result.append((cx-x, cy+y)) # Q2
result.append((cx-x, cy-y)) # Q3
result.append((cx+x, cy-y)) # Q4
y = y + 1
stoppingY = stoppingY + twoAsqr
ellipse_error = ellipse_error + ychange
ychange = ychange + twoAsqr
if ((2*ellipse_error + xchange) > 0):
x = x - 1
stoppingX -= twoBsqr
ellipse_error += xchange
xchange += twoBsqr
x = 0
y = ry
xchange = ry*ry
ychange = rx*rx*(1-(2*ry))
ellipse_error = 0
stoppingX = 0
stoppingY = twoAsqr*ry
while(stoppingX <= stoppingY):
result.append((cx+x, cy+y)) # Q1
result.append((cx-x, cy+y)) # Q2
result.append((cx-x, cy-y)) # Q3
result.append((cx+x, cy-y)) # Q4
x = x + 1
stoppingX = stoppingX + twoBsqr
ellipse_error += xchange
xchange += twoBsqr
if ((2*ellipse_error + ychange) > 0):
y = y - 1
stoppingY -= twoAsqr
ellipse_error += ychange
ychange += twoAsqr
for i in result:
if i not in temp:
temp.append(i)
return temp
rx,ry,x,y = input('').split()
rx,ry,x,y = int(rx), int(ry), int(x), int(y)
s=BresenhemEllipse(rx,ry,x,y)
for i in s:
print(i)