Skip to content

Commit 0f70a92

Browse files
committed
fix: incorrectly generated spherical coordinates
1 parent 87c4786 commit 0f70a92

File tree

3 files changed

+720
-4
lines changed

3 files changed

+720
-4
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ test = ["pytest"]
2020

2121
[project.urls]
2222
Home = "https://github.com/structuralpython/plotly_3d_primitives"
23+
24+
[dependency-groups]
25+
dev = [
26+
"ipykernel>=6.29.5",
27+
"nbformat>=5.10.4",
28+
]

src/plotly_3d_primitives/shapes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def cone(
114114
def 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
)
@@ -326,6 +326,7 @@ def transform_points(
326326
collection (which is originally oriented toward (1, 0, 0)).
327327
"""
328328
transform_matrix = reorient(direction=new_direction)
329+
# print(transform_matrix)
329330
oriented_point_matrix = transform_matrix @ point_matrix
330331
oriented_point_matrix_3 = oriented_point_matrix[0:3]
331332
if not np.allclose(new_center, [0.0, 0.0, 0.0]):

0 commit comments

Comments
 (0)