Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83dde01

Browse files
committed
FIX: add camera distance functions
1 parent afbf6e4 commit 83dde01

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ def __init__(self, x, y, z, dxy=0.8, z0=0, shade=True, lightsource=None, **kws):
12101210
self._lightsource = lightsource
12111211

12121212
# rectangle polygon vertices
1213-
verts = self._compute_bar3d_verts()
1213+
verts = self._compute_verts()
12141214

12151215
# init Poly3DCollection
12161216
if (no_cmap := {'color', 'facecolor', 'facecolors'}.intersection(kws)):
@@ -1360,7 +1360,7 @@ def _resolve_colors(self, xyzlist, lightsource):
13601360

13611361
def _compute_zorder(self):
13621362
# sort by depth (furthest drawn first)
1363-
zorder = camera.distance(self.axes, *self.xy)
1363+
zorder = camera_distance(self.axes, *self.xy)
13641364
zorder = (zorder - zorder.min()) / zorder.ptp()
13651365
zorder = zorder.ravel() * len(zorder)
13661366
panel_order = get_cube_face_zorder(self.axes)
@@ -1516,7 +1516,36 @@ def norm(x):
15161516
return colors
15171517

15181518

1519-
def _compute__bar3d_verts(x, y, z, dx, dy, dz):
1519+
def camera_distance(ax, x, y, z=None):
1520+
z = np.zeros_like(x) if z is None else z
1521+
# camera = xyz(ax)
1522+
# print(camera)
1523+
return np.sqrt(np.square(
1524+
# location of points
1525+
[x, y, z] -
1526+
# camera position in xyz
1527+
np.array(sph2cart(*_camera_position(ax)), ndmin=3).T
1528+
).sum(0))
1529+
1530+
1531+
def sph2cart(r, theta, phi):
1532+
r_sinθ = r * np.sin(theta)
1533+
return (r_sinθ * np.cos(phi),
1534+
r_sinθ * np.sin(phi),
1535+
r * np.cos(theta))
1536+
1537+
1538+
def _camera_position(ax):
1539+
"""
1540+
Returns the camera position for 3D axes in spherical coordinates.
1541+
"""
1542+
r = np.square(np.max([ax.get_xlim(),
1543+
ax.get_ylim()], 1)).sum()
1544+
theta, phi = np.radians((90 - ax.elev, ax.azim))
1545+
return r, theta, phi
1546+
1547+
1548+
def _compute_bar3d_verts(x, y, z, dx, dy, dz):
15201549
# indexed by [bar, face, vertex, coord]
15211550

15221551
# handle each coordinate separately

0 commit comments

Comments
 (0)