-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllipseScanConversion.py
More file actions
47 lines (44 loc) · 1.16 KB
/
EllipseScanConversion.py
File metadata and controls
47 lines (44 loc) · 1.16 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
"""
扫描椭圆转换算法
"""
import matplotlib.pyplot as plt
import math
def main():
a = int(input("please input the length of ellipse: "))
b = int(input("please input the short radius of ellipse: "))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set(xlim=[-a-b,a+b], ylim = [-a-b,a+b])
MidpointEllipse(a,b)
plt.show()
def MidpointEllipse(a,b):
x=0
y=b
d1 = b*b+a*a*(-b+0.25)
plt.scatter(x,y,color='red')
while b*b*(x+1)<a*a*(y-0.5):
if d1<0:
d1+=b*b*(2*x+3)
x+=1
else:
d1+=(b*b*(2*x+3)+a*a*(-2*y+2))
x+=1
y-=1
plt.scatter(x,y,color='red')
plt.scatter(-x,y,color='red')
plt.scatter(-x,-y,color='red')
plt.scatter(x,-y,color='red')
d2 = math.sqrt(b*(x+0.5)+math.sqrt(a*(y-1))-math.sqrt(a*b))
while y>0:
if d2<0:
d2+=b*b*(2*x+2)+a*a*(-2*y+3)
x+=1
y-=1
else:
d2+=a*a*(-2*y+3)
y-=1
plt.scatter(x,y,color='red')
plt.scatter(-x,y,color='red')
plt.scatter(-x,-y,color='red')
plt.scatter(x,-y,color='red')
main()