-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregular_polygon.py
More file actions
61 lines (48 loc) · 1.33 KB
/
regular_polygon.py
File metadata and controls
61 lines (48 loc) · 1.33 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
import math
def line(x1,y1,x2,y2):
print(0)
print('LINE')
print(8)
print('Polygon')
print(10)
print(x1)
print(20)
print(y1)
print(11)
print(x2)
print(21)
print(y2)
def rotx(x,y,a):
return x*math.cos(a) - y*math.sin(a)
def roty(x,y,a):
return x*math.sin(a) + y*math.cos(a)
def rotline(x1,y1,x2,y2,a):
line(rotx(x1,y1,a), roty(x1,y1,a), rotx(x2,y2,a), roty(x2,y2,a))
def header():
print(0)
print('SECTION')
print(2)
print('ENTITIES')
def footer():
print(0)
print('ENDSEC')
print(0)
print('EOF')
header()
n = 7
hole = 3
width = 10
edge = 20
circle = 12
r = edge / 2 / math.sin(math.pi / n)
for i in range(n):
a = 2*i*math.pi/n
rotline(-edge/2, r*math.cos(math.pi/n) + width/2, edge/2, r*math.cos(math.pi/n) + width/2, math.pi/n + a)
for p in range(2*circle):
rotline(hole/2*math.cos(p*math.pi/circle), r + hole/2*math.sin(p*math.pi/circle),
hole/2*math.cos((p+1)*math.pi/circle), r + hole/2*math.sin((p+1)*math.pi/circle),
a)
rotline(width/2*math.cos(p*math.pi/n/circle - math.pi/n + math.pi/2), r + width/2*math.sin(p*math.pi/n/circle - math.pi/n+ math.pi/2),
width/2*math.cos((p+1)*math.pi/n/circle - math.pi/n+ math.pi/2), r + width/2*math.sin((p+1)*math.pi/n/circle - math.pi/n+ math.pi/2),
a)
footer()