11import plotly .graph_objects as go
2+ import numpy as np
23
34
45def box (
56 b : float ,
6- h : float ,
77 d : float ,
8- anchor = (0 , 0 , 0 ),
8+ h : float ,
9+ align : list [str ],
10+ anchor : tuple = (0 , 0 , 0 ),
911 color : str = "#aaaaaa" ,
1012 opacity : float = 0.5 ,
1113) -> go .Mesh3d :
12-
13- anchor_x , anchor_y , anchor_z = anchor
14+
15+ anchor_point = anchor
16+ anchor_arr = np .array (anchor_point )
17+ for align_instr in align :
18+ if align_instr == "center" :
19+ anchor_arr = anchor_arr - np .array ([b / 2 , d / 2 , h / 2 ])
20+
21+ anchor_x , anchor_y , anchor_z = anchor_arr
1422
1523 x0 = anchor_x
1624 x1 = b + anchor_x
17-
25+
1826 y0 = anchor_y
1927 y1 = d + anchor_y
2028
@@ -26,22 +34,55 @@ def box(
2634 z_array = [z0 , z0 , z0 , z0 , z1 , z1 , z1 , z1 ]
2735
2836 mesh = go .Mesh3d (
29- x = x_array ,
30- y = y_array ,
31- z = z_array ,
32- opacity = opacity ,
33- color = color ,
34- alphahull = 0
37+ x = x_array , y = y_array , z = z_array , opacity = opacity , color = color , alphahull = 0
3538 )
3639
3740 return mesh
3841
3942
40- def prism () -> go .Mesh3d :
41- return go .Mesh3d ()
43+ def prism (
44+ n_points : int ,
45+ h : float ,
46+ align : list [str ],
47+ anchor : tuple = (0 , 0 , 0 ),
48+ color : str = "#aaaaaa" ,
49+ opacity : float = 0.5 ,
50+ ) -> go .Mesh3d :
51+ anchor_x , anchor_y , anchor_z = anchor
52+
53+ arr = np .linspace (0 , 2 * np .pi , num = n_points , endpoint = False )
54+ x_poly = np .cos (arr ) + anchor_x
55+ y_poly = np .sin (arr ) + anchor_y
56+ z_poly = np .zeros (n_points ) + anchor_z
57+
58+ x_array = np .concat ([x_poly , x_poly ])
59+ y_array = np .concat ([y_poly , y_poly ])
60+ z_array = np .concat ([z_poly , z_poly + h ])
4261
62+ return go .Mesh3d (
63+ x = x_array , y = y_array , z = z_array , alphahull = 0 , color = color , opacity = opacity
64+ )
4365
44- def cone () -> go .Mesh3d :
45- return go .Mesh3d ()
4666
67+ def cone (
68+ n_points : int ,
69+ h : float ,
70+ align : list [str ],
71+ anchor : tuple = (0 , 0 , 0 ),
72+ color : str = "#aaaaaa" ,
73+ opacity : float = 0.5 ,
74+ ) -> go .Mesh3d :
75+ anchor_x , anchor_y , anchor_z = anchor
76+
77+ arr = np .linspace (0 , 2 * np .pi , num = n_points , endpoint = False )
78+ x_poly = np .cos (arr ) + anchor_x
79+ y_poly = np .sin (arr ) + anchor_y
80+ z_poly = np .zeros (n_points ) + anchor_z
4781
82+ x_array = np .concat ([x_poly , np .array ([anchor_x ])])
83+ y_array = np .concat ([y_poly , np .array ([anchor_y ])])
84+ z_array = np .concat ([z_poly , np .array ([anchor_z + h ])])
85+
86+ return go .Mesh3d (
87+ x = x_array , y = y_array , z = z_array , alphahull = 0 , color = color , opacity = opacity
88+ )
0 commit comments