@p3artschool/

CSHS-2019-05-03-Q3

No description

Files
• main.py
• demo.png
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
```
```# CSHS-2019-05-03-Q3.py
# 2019-05-03
# python3
# run on https://repl.it
# run on ubuntu 18.04 LTS
#
# 要執行本程式, 請按上方run▶
#
import numpy as np
import matplotlib.pyplot as plot
from shapely.geometry import LineString
#
# 定義圖面函數
def set_graphic_area(width,height) :

cm2inch = 1/2.54    # inch per cm
#
# define graphic area
#
left_margin = 1.0   # cm
right_margin = 1.0  # cm
#
figure_width  = width  # cm , from xmin to xmax
figure_height = height # cm , from ymin to ymax
#
top_margin = 1.0    # cm
bottom_margin = 1.0 # cm
#
box_width = left_margin + figure_width + right_margin   # cm
box_height = top_margin + figure_height + bottom_margin # cm
#
top_value    = 1.0 - top_margin / box_height
bottom_value = bottom_margin / box_height
left_value   = left_margin / box_width
right_value  = 1.0 - right_margin / box_width
#
return (box_width*cm2inch,box_height*cm2inch,top_value,bottom_value,left_value,right_value,width)
#
# end of def
#
# Define the arc
# center position is cxy = (cx, cy)
# start_angle, end_angle is in degrees
#
def shapely_Arc(cxy, r, start_angle, end_angle) :
#
numsegments = 1440
# The coordinates of the arc
x = cxy[0] + r * np.cos(theta)
y = cxy[1] + r * np.sin(theta)
Arc = LineString(np.column_stack([x, y]))
return Arc
#
# end of def
#
# ------------------------------------------------------------
#
r0 = 15
tup7 = set_graphic_area(2*r0, 2*r0)
fig = plot.figure(figsize=(tup7[0], tup7[1]))
top    = tup7[2] ,
bottom = tup7[3] ,
left   = tup7[4] ,
right  = tup7[5] ,
)
#
plot.xlim(-tup7[6]/2, tup7[6]/2)
plot.ylim(-tup7[6]/2, tup7[6]/2)
ax.grid(True)
ax.set_axis_on()
#
## ------------------------------------------------------------

#
## -------------------------------------------------------------
#