@@ -24,7 +24,13 @@ def base_validator(name, value, conditions):
24
24
def get_model (trace , * , backend , show , scale , kwargs ):
25
25
"""Returns model3d dict depending on backend"""
26
26
27
- model = dict (constructor = "Mesh3d" , kwargs = trace , args = (), show = show , scale = scale )
27
+ model = {
28
+ "constructor" : "Mesh3d" ,
29
+ "kwargs" : trace ,
30
+ "args" : (),
31
+ "show" : show ,
32
+ "scale" : scale ,
33
+ }
28
34
if backend == "matplotlib" :
29
35
x , y , z , i , j , k = (trace [k ] for k in "xyzijk" )
30
36
triangles = np .array ([i , j , k ]).T
@@ -85,14 +91,14 @@ def make_Cuboid(
85
91
a 3D-model.
86
92
"""
87
93
dimension = np .array (dimension , dtype = float )
88
- trace = dict (
89
- i = np .array ([7 , 0 , 0 , 0 , 4 , 4 , 2 , 6 , 4 , 0 , 3 , 7 ]),
90
- j = np .array ([0 , 7 , 1 , 2 , 6 , 7 , 1 , 2 , 5 , 5 , 2 , 2 ]),
91
- k = np .array ([3 , 4 , 2 , 3 , 5 , 6 , 5 , 5 , 0 , 1 , 7 , 6 ]),
92
- x = np .array ([- 1 , - 1 , 1 , 1 , - 1 , - 1 , 1 , 1 ]) * 0.5 * dimension [0 ],
93
- y = np .array ([- 1 , 1 , 1 , - 1 , - 1 , 1 , 1 , - 1 ]) * 0.5 * dimension [1 ],
94
- z = np .array ([- 1 , - 1 , - 1 , - 1 , 1 , 1 , 1 , 1 ]) * 0.5 * dimension [2 ],
95
- )
94
+ trace = {
95
+ "i" : np .array ([7 , 0 , 0 , 0 , 4 , 4 , 2 , 6 , 4 , 0 , 3 , 7 ]),
96
+ "j" : np .array ([0 , 7 , 1 , 2 , 6 , 7 , 1 , 2 , 5 , 5 , 2 , 2 ]),
97
+ "k" : np .array ([3 , 4 , 2 , 3 , 5 , 6 , 5 , 5 , 0 , 1 , 7 , 6 ]),
98
+ "x" : np .array ([- 1 , - 1 , 1 , 1 , - 1 , - 1 , 1 , 1 ]) * 0.5 * dimension [0 ],
99
+ "y" : np .array ([- 1 , 1 , 1 , - 1 , - 1 , 1 , 1 , - 1 ]) * 0.5 * dimension [1 ],
100
+ "z" : np .array ([- 1 , - 1 , - 1 , - 1 , 1 , 1 , 1 , 1 ]) * 0.5 * dimension [2 ],
101
+ }
96
102
97
103
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
98
104
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
@@ -183,7 +189,7 @@ def make_Prism(
183
189
k = np .concatenate ([k1 , j2 , j3 , k4 ])
184
190
185
191
x , y , z = c .T
186
- trace = dict ( x = x , y = y , z = z , i = i , j = j , k = k )
192
+ trace = { "x" : x , "y" : y , "z" : z , "i" : i , "j" : j , "k" : k }
187
193
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
188
194
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
189
195
@@ -246,25 +252,34 @@ def make_Ellipsoid(
246
252
y = np .cos (theta ) * np .cos (phi ) * dimension [1 ] * 0.5
247
253
z = np .sin (theta ) * dimension [2 ] * 0.5
248
254
249
- x , y , z = x .flatten ()[N - 1 :], y .flatten ()[N - 1 :], z .flatten ()[N - 1 :]
255
+ x , y , z = (
256
+ x .flatten ()[N - 1 : - N + 1 ],
257
+ y .flatten ()[N - 1 : - N + 1 ],
258
+ z .flatten ()[N - 1 : - N + 1 ],
259
+ )
260
+ N2 = len (x ) - 1
250
261
251
262
i1 = [0 ] * N
252
- j1 = np .array ([N ] + list ( range (1 , N )) , dtype = int )
253
- k1 = np .array (list ( range (1 , N )) + [ N ], dtype = int )
263
+ j1 = np .array ([N , * range (1 , N )] , dtype = int )
264
+ k1 = np .array ([ * range (1 , N ), N ], dtype = int )
254
265
255
- i2 = np .concatenate ([k1 + i * N for i in range (N - 2 )])
256
- j2 = np .concatenate ([j1 + i * N for i in range (N - 2 )])
257
- k2 = np .concatenate ([j1 + (i + 1 ) * N for i in range (N - 2 )])
266
+ i2 = np .concatenate ([k1 + i * N for i in range (N - 3 )])
267
+ j2 = np .concatenate ([j1 + i * N for i in range (N - 3 )])
268
+ k2 = np .concatenate ([j1 + (i + 1 ) * N for i in range (N - 3 )])
258
269
259
- i3 = np .concatenate ([k1 + i * N for i in range (N - 2 )])
260
- j3 = np .concatenate ([j1 + (i + 1 ) * N for i in range (N - 2 )])
261
- k3 = np .concatenate ([k1 + (i + 1 ) * N for i in range (N - 2 )])
270
+ i3 = np .concatenate ([k1 + i * N for i in range (N - 3 )])
271
+ j3 = np .concatenate ([j1 + (i + 1 ) * N for i in range (N - 3 )])
272
+ k3 = np .concatenate ([k1 + (i + 1 ) * N for i in range (N - 3 )])
262
273
263
- i = np . concatenate ([ i1 , i2 , i3 ])
264
- j = np . concatenate ([ j1 , j2 , j3 ])
265
- k = np . concatenate ([ k1 , k2 , k3 ])
274
+ i4 = [ N2 ] * N
275
+ j4 = k1 + N2 - N - 1
276
+ k4 = j1 + N2 - N - 1
266
277
267
- trace = dict (x = x , y = y , z = z , i = i , j = j , k = k )
278
+ i = np .concatenate ([i1 , i2 , i3 , i4 ])
279
+ j = np .concatenate ([j1 , j2 , j3 , j4 ])
280
+ k = np .concatenate ([k1 , k2 , k3 , k4 ])
281
+
282
+ trace = {"x" : x , "y" : y , "z" : z , "i" : i , "j" : j , "k" : k }
268
283
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
269
284
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
270
285
@@ -364,7 +379,7 @@ def make_CylinderSegment(
364
379
k .extend ([j5 , j5 + N - 1 ])
365
380
i , j , k = (np .hstack (l ) for l in (i , j , k ))
366
381
367
- trace = dict ( x = x , y = y , z = z , i = i , j = j , k = k )
382
+ trace = { "x" : x , "y" : y , "z" : z , "i" : i , "j" : j , "k" : k }
368
383
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
369
384
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
370
385
@@ -445,7 +460,7 @@ def make_Pyramid(
445
460
j = i + 1
446
461
j [- 1 ] = 0
447
462
k = np .array ([N ] * N , dtype = int )
448
- trace = dict ( x = x , y = y , z = z , i = i , j = j , k = k )
463
+ trace = { "x" : x , "y" : y , "z" : z , "i" : i , "j" : j , "k" : k }
449
464
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
450
465
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
451
466
@@ -581,21 +596,14 @@ def make_Tetrahedron(
581
596
a 3D-model.
582
597
"""
583
598
x , y , z = np .array (vertices ).T
584
- trace = dict (
585
- i = np .array (
586
- [
587
- 0 ,
588
- 0 ,
589
- 1 ,
590
- 2 ,
591
- ]
592
- ),
593
- j = np .array ([1 , 1 , 2 , 0 ]),
594
- k = np .array ([2 , 3 , 3 , 3 ]),
595
- x = x ,
596
- y = y ,
597
- z = z ,
598
- )
599
+ trace = {
600
+ "i" : np .array ([0 , 0 , 1 , 2 ]),
601
+ "j" : np .array ([1 , 1 , 2 , 0 ]),
602
+ "k" : np .array ([2 , 3 , 3 , 3 ]),
603
+ "x" : x ,
604
+ "y" : y ,
605
+ "z" : z ,
606
+ }
599
607
600
608
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
601
609
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
@@ -658,13 +666,6 @@ def make_TriangularMesh(
658
666
hull = ConvexHull (vertices )
659
667
triangles = hull .simplices
660
668
i , j , k = np .array (triangles ).T
661
- trace = dict (
662
- i = i ,
663
- j = j ,
664
- k = k ,
665
- x = x ,
666
- y = y ,
667
- z = z ,
668
- )
669
+ trace = {"x" : x , "y" : y , "z" : z , "i" : i , "j" : j , "k" : k }
669
670
trace = place_and_orient_model3d (trace , orientation = orientation , position = position )
670
671
return get_model (trace , backend = backend , show = show , scale = scale , kwargs = kwargs )
0 commit comments