Skip to content

Commit d62d54a

Browse files
committed
FIX: add camera distance functions
1 parent f36c415 commit d62d54a

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ def __init__(self, x, y, z, dxy=0.8, z0=0, shade=True, lightsource=None, **kws):
11661166
self._lightsource = lightsource
11671167

11681168
# rectangle polygon vertices
1169-
verts = self._compute_bar3d_verts()
1169+
verts = self._compute_verts()
11701170

11711171
# init Poly3DCollection
11721172
if (no_cmap := {'color', 'facecolor', 'facecolors'}.intersection(kws)):
@@ -1316,7 +1316,7 @@ def _resolve_colors(self, xyzlist, lightsource):
13161316

13171317
def _compute_zorder(self):
13181318
# sort by depth (furthest drawn first)
1319-
zorder = camera.distance(self.axes, *self.xy)
1319+
zorder = camera_distance(self.axes, *self.xy)
13201320
zorder = (zorder - zorder.min()) / zorder.ptp()
13211321
zorder = zorder.ravel() * len(zorder)
13221322
panel_order = get_cube_face_zorder(self.axes)
@@ -1470,7 +1470,36 @@ def norm(x):
14701470
return colors
14711471

14721472

1473-
def _compute__bar3d_verts(x, y, z, dx, dy, dz):
1473+
def camera_distance(ax, x, y, z=None):
1474+
z = np.zeros_like(x) if z is None else z
1475+
# camera = xyz(ax)
1476+
# print(camera)
1477+
return np.sqrt(np.square(
1478+
# location of points
1479+
[x, y, z] -
1480+
# camera position in xyz
1481+
np.array(sph2cart(*_camera_position(ax)), ndmin=3).T
1482+
).sum(0))
1483+
1484+
1485+
def sph2cart(r, theta, phi):
1486+
r_sinθ = r * np.sin(theta)
1487+
return (r_sinθ * np.cos(phi),
1488+
r_sinθ * np.sin(phi),
1489+
r * np.cos(theta))
1490+
1491+
1492+
def _camera_position(ax):
1493+
"""
1494+
Returns the camera position for 3D axes in spherical coordinates.
1495+
"""
1496+
r = np.square(np.max([ax.get_xlim(),
1497+
ax.get_ylim()], 1)).sum()
1498+
theta, phi = np.radians((90 - ax.elev, ax.azim))
1499+
return r, theta, phi
1500+
1501+
1502+
def _compute_bar3d_verts(x, y, z, dx, dy, dz):
14741503
# indexed by [bar, face, vertex, coord]
14751504

14761505
# handle each coordinate separately

0 commit comments

Comments
 (0)