-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheart.py
More file actions
98 lines (88 loc) · 1.76 KB
/
Copy pathheart.py
File metadata and controls
98 lines (88 loc) · 1.76 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from math import sin,cos,pi
scale = 24
shifty = 0
shiftx = 0
def line(x1,y1,x2,y2):
print(0)
print('LINE')
print(8)
print('Polygon')
print(10)
print((shiftx+x1)*scale)
print(20)
print((shifty+y1)*scale)
print(11)
print((shiftx+x2)*scale)
print(21)
print((shifty+y2)*scale)
def header():
print(0)
print('SECTION')
print(2)
print('ENTITIES')
def footer():
print(0)
print('ENDSEC')
print(0)
print('EOF')
def sq(x):
return x*x
def cu(x):
return x*x*x
def f(x,y,z):
return cu(sq(x)+9/4*sq(y)+sq(z)-1)-sq(x)*cu(z)-sq(y)*cu(z)*9/80
def root(x, y, z1, z2):
if max(z1,z2)-min(z1,z2) < 0.0001:
return z2
z = (z1+z2)/2
if f(x,y,z) < 0:
return root(x,y,z1,z)
else:
return root(x,y,z,z2)
zlim = 5
zstep = 0.01
def interval(x, y):
z = -zlim
while z < zlim:
if f(x,y,z) < 0:
return [root(x,y,-zlim,z), root(x,y,zlim,z)]
z += zstep
return None
def cut(y):
maxz = 0
xstep = 50
for xx in range(2*xstep-1):
x = xx/xstep
x1 = x + 1/xstep
i = interval(x, y)
maxz = max(maxz,max(i)-min(i))
j = interval(x1, y)
if j is None:
line(x,i[0],x,i[1])
line(-x,i[0],-x,i[1])
return [x, maxz]
line(x,i[0],x1,j[0])
line(x,i[1],x1,j[1])
line(-x,i[0],-x1,j[0])
line(-x,i[1],-x1,j[1])
def hole():
r = 1.5/scale
w = 0.15/scale
p=0.18
line(-w,p-r,w,p-r)
line(w,p-r,w,p+r)
line(w,p+r,-w,p+r)
line(-w,p+r,-w,p-r)
header()
maxz = 0
ysteps = 40
for y in range(ysteps):
d=cut(0.68*y/ysteps)
hole()
shiftx += 2.1*d[0]
maxz = max(maxz, d[1])
if shiftx > 6:
shiftx = 0
shifty -= maxz*1.05
maxz = 0
footer()