-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_shape.py
90 lines (76 loc) · 4.23 KB
/
build_shape.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
87
88
89
90
import combine_functions
import marble_path
import slope_function
def print_stats(x_t, y_t, z_t, r_t, num_time_steps):
min_x = min(x_t(i) for i in range(num_time_steps + 1))
max_x = max(x_t(i) for i in range(num_time_steps + 1))
min_y = min(y_t(i) for i in range(num_time_steps + 1))
max_y = max(y_t(i) for i in range(num_time_steps + 1))
print("Min, max x: %.4f %.4f" % (min_x, max_x))
print("Min, max y: %.4f %.4f" % (min_y, max_y))
x0 = x_t(0)
y0 = y_t(0)
xn = x_t(num_time_steps)
yn = y_t(num_time_steps)
print("Start of the curve: (%.4f, %.4f)" % (x0, y0))
print("End of the curve: (%.4f, %.4f)" % (xn, yn))
dist = ((xn - x0) ** 2 + (yn - y0) ** 2) ** 0.5
print("Distance: %.4f (x %.4f, y %.4f)" % (dist, (xn - x0), (yn - y0)))
print("Top: %.4f Bottom: %.4f" % (z_t(0), z_t(num_time_steps)))
print("Begin rotation: %.4f" % r_t(0))
print("End rotation: %.4f" % r_t(num_time_steps))
def generate_shape(module, args):
module.describe_curve(args)
if getattr(module, 'build_time_t', None) is not None:
time_t = module.build_time_t(args)
else:
time_t = lambda t: t
if getattr(module, 'build_x_y_r_t', None) is not None:
x_t, y_t, r_t = module.build_x_y_r_t(args)
elif getattr(module, 'build_x_y_t', None) is not None:
x_t, y_t = module.build_x_y_t(args)
r_t = marble_path.numerical_rotation_function(x_t, y_t)
else:
x_t = module.build_x_t(args)
y_t = module.build_y_t(args)
r_t = marble_path.numerical_rotation_function(x_t, y_t)
num_time_steps = args.num_time_steps
# TODO: because the circle replacement does not keep the endpoints
# the same, this will disrupt any attempt to set a scale such as
# in generate_hypotrochoid's closest_approach. For now, those
# arguments are incompatible
if getattr(args, 'kink_replace_circle', None):
x_t, y_t, r_t = combine_functions.replace_kinks_with_circles(args=args,
time_t=time_t,
x_t=x_t,
y_t=y_t,
r_t=r_t,
kink_args=args,
num_time_steps=num_time_steps)
slope_angle_t = slope_function.slope_function(x_t=x_t,
y_t=y_t,
time_t=time_t,
slope_angle=args.slope_angle,
num_time_steps=num_time_steps,
overlap_args=args,
kink_args=args)
if getattr(args, 'zero_circle', None):
updated_functions = combine_functions.add_both_zero_circles(args=args,
num_time_steps=num_time_steps,
x_t=x_t,
y_t=y_t,
slope_angle_t=slope_angle_t,
r_t=r_t)
num_time_steps, x_t, y_t, slope_angle_t, r_t = updated_functions
z_t = marble_path.arclength_height_function(x_t, y_t, num_time_steps, slope_angle_t=slope_angle_t)
print_stats(x_t, y_t, z_t, r_t, num_time_steps)
for triangle in marble_path.generate_path(x_t=x_t, y_t=y_t, z_t=z_t, r_t=r_t,
tube_args=args,
num_time_steps=num_time_steps,
time_t=time_t,
slope_angle_t=slope_angle_t):
yield triangle
def main(module, sys_args=None):
args = module.parse_args(sys_args)
marble_path.print_args(args)
marble_path.write_stl(generate_shape(module, args), args.output_name)