@@ -114,7 +114,7 @@ def cone(
114114def sphere (
115115 radius = 0.5 ,
116116 center = (0.0 , 0.0 , 0.0 ),
117- direction = (0 .0 , 0.0 , 1 .0 ),
117+ direction = (1 .0 , 0.0 , 0 .0 ),
118118 theta_resolution = 30 ,
119119 phi_resolution = 30 ,
120120 start_theta = 0.0 ,
@@ -124,7 +124,7 @@ def sphere(
124124 color = "#555" ,
125125 opacity = 0.5 ,
126126) -> go .Mesh3d :
127- anchor_x , anchor_y , anchor_z = center
127+ anchor_x , anchor_y , anchor_z = ( 0. , 0. , 0. )
128128 phi = np .linspace (start_phi , 2 * np .radians (end_phi ), phi_resolution + 1 )
129129 theta = np .linspace (start_theta , np .radians (end_theta ), theta_resolution + 1 )
130130
@@ -134,9 +134,9 @@ def sphere(
134134 z_array = np .ravel (anchor_z + np .cos (phi ) * radius_zy )
135135 y_array = np .ravel (anchor_y + np .sin (phi ) * radius_zy )
136136 x_array = np .ravel (anchor_x + radius * np .cos (theta ))
137-
138137 x_array , y_array , z_array = apply_transformations (x_array , y_array , z_array , center , direction )
139-
138+ # print(center, direction)
139+ # print(y_array)
140140 return go .Mesh3d (
141141 x = x_array , y = y_array , z = z_array , alphahull = 0 , color = color , opacity = opacity
142142 )
@@ -264,10 +264,6 @@ def rectangle(
264264 y_array = [y0 , y0 , y1 , y1 , y0 , y0 , y1 , y1 ]
265265 z_array = [z0 , z0 , z0 , z0 , z1 , z1 , z1 , z1 ]
266266
267- # i_array = [0, 1]
268- # j_array = [1, 2]
269- # k_array = [3, 3]
270-
271267 x_array , y_array , z_array = apply_transformations (x_array , y_array , z_array , center , normal )
272268
273269 mesh = go .Mesh3d (
@@ -330,6 +326,7 @@ def transform_points(
330326 collection (which is originally oriented toward (1, 0, 0)).
331327 """
332328 transform_matrix = reorient (direction = new_direction )
329+ # print(transform_matrix)
333330 oriented_point_matrix = transform_matrix @ point_matrix
334331 oriented_point_matrix_3 = oriented_point_matrix [0 :3 ]
335332 if not np .allclose (new_center , [0.0 , 0.0 , 0.0 ]):
@@ -341,119 +338,6 @@ def transform_points(
341338 return translated_point_matrix .T
342339
343340
344- # def rectangular_grid(
345- # center=(0.0, 0.0, 0.0),
346- # b=1.0,
347- # d=1.0,
348- # normal=(0.0, 0.0, 1.0),
349- # rows=1,
350- # cols=1,
351- # color: str = "#aaa",
352- # ) -> go.Mesh3d:
353- # """
354- # Returns a grid like:
355- # ... ... ...
356- # | . | . | . |
357- # | 3 | 4 | 5 | ...
358- # | 0 | 1 | 2 | ...
359-
360- # Where 0, 1, 2, 3, 4, ... etc. are the "indexes" of the grid
361- # rectangles. They are numbered from the bottom-left left-to-right,
362- # down-to-up until the bth rectangle which has an index of (m * n - 1)
363- # where m is rows and n is columns.
364-
365- # b: total width of grid
366- # d: total depth (height) of grid
367-
368- # color: str | dict[Callable, str] will color the rectangles either all
369- # one color (str) or conditionally color them based on whether the
370- # index value of each rectangle returns True in the dict callable key
371- # (the color in the value will be applied if True; the first matching
372- # condition applies).
373-
374- # """
375- # # nodes
376- # center = np.array(center)
377- # normal = np.array(normal)
378-
379- # # Direction cosines
380- # x_dir = (1, 0, 0)
381- # y_dir = (0, 1, 0)
382- # z_dir = (0, 0, 1)
383- # assumed_normal = z_dir
384- # norm = np.linalg.norm(normal)
385- # cos_alpha = np.dot(x_dir, normal) / norm
386- # cos_beta = np.dot(y_dir, normal) / norm
387- # cos_gamma = np.dot(z_dir, normal) / norm
388-
389- # pitch_rot = np.array(
390- # [[cos_beta, 0, 1 - cos_beta], [0, 1, 0], [-1 - cos_beta, 0, cos_beta]]
391- # )
392-
393- # yaw_rot = np.array(
394- # [[cos_gamma, -1 - cos_gamma, 0], [1 - cos_gamma, cos_gamma, 0], [0, 0, 1]]
395- # )
396-
397- # # The projection of the normal on each plane
398- # xy_proj = np.array([normal[0], normal[1], 0])
399- # yz_proj = np.array([0, normal[1], normal[2]])
400- # xz_proj = np.array([normal[0], 0, normal[2]])
401-
402- # xy_perp = np.array([-normal[1], normal[0], 0])
403- # yz_perp = np.array([0, normal[2], -normal[1]])
404- # xz_perp = np.array([normal[2], 0, -normal[0]])
405-
406- # # Go "down" to the mid-point of the bottom edge of the rectangle
407- # bot_mid_point = (
408- # center
409- # - (
410- # yz_perp / np.linalg.norm(yz_perp) if np.sum(yz_perp) != 0 else np.zeros(3)
411- # + xz_perp / np.linalg.norm(xz_perp) if np.sum(xz_perp) != 0 else np.zeros(3)
412- # ) / 2**0.5 * d/2
413- # )
414- # # Then go "left" to the bottom-left corner of the rectangle for the "A" point
415- # A_point = bot_mid_point - (xy_perp / np.linalg.norm(xy_perp) if np.sum(xy_perp) != 0 else np.zeros(3)) * b/2
416-
417- # # Go "up" to the mid-poitn of the top edge of the rectangle
418- # top_mid_point = (
419- # center
420- # + (
421- # yz_perp / np.linalg.norm(yz_perp) if np.sum(yz_perp) != 0 else np.zeros(3)
422- # + xz_perp / np.linalg.norm(xz_perp) if np.sum(xz_perp) != 0 else np.zeros(3)
423- # ) / 2**0.5 * d/2
424- # )
425- # print(bot_mid_point, top_mid_point)
426- # # Then go "right" to the top-right corner of the rectangle for the "B" point
427- # B_point = top_mid_point + (xy_perp / np.linalg.norm(xy_perp) if np.sum(xy_perp) != 0 else np.zeros(3)) * b/2
428- # hypot_length = np.sqrt((b)**2 + (d)**2)
429-
430- # print(hypot_length)
431- # print(np.linalg.norm(B_point - A_point))
432-
433- # Plane equation
434- "normal[0] * x + normal[1] * y + normal[2] * z = np.dot(center, normal)"
435-
436- # Distance from center to "min" point
437- "sqrt((b/2 - center[0])**2 + (d/2 - center[1])**2 + (0 - center[2])**2)"
438-
439- # A is "min" point, B is "max" point
440- "tan(alpha) = d / b"
441-
442- # Assumption, the bottom edge of the rect will be parallel with the xy plane
443- # Therefore vector of the bottom edge will be the -ve reciprocal of the xy projection of the vector normal [1, 2, 3] => [1, 2, 0]
444- # So the bottom edge will be [-2, 1, 0]
445-
446- # triangles
447- for j in range (rows ):
448- mod_co = cols + 1
449- for i in range (cols ):
450- mod_ro = rows + 1
451- rect_index = i + j * mod_co
452- anchor_node = rect_index + j
453-
454- tri_1 = [anchor_node , anchor_node + mod_ro , anchor_node + mod_ro + 1 ]
455- tri_2 = [anchor_node , anchor_node + 1 , anchor_node + mod_ro + 1 ]
456-
457341
458342# From Pyvista
459343def reorient (direction = (1.0 , 0.0 , 0.0 )):
0 commit comments