def _shade_colors(color, normals, lightsource=None): """ Shade *color* using normal vectors given by *normals*. *color* can also be an array of the same length as *normals*. """ if lightsource is None: # chosen for backwards-compatibility lightsource = LightSource(azdeg=225, altdeg=19.4712) shade = np.array([ np.dot(n / proj3d.mod(n), lightsource.direction) if proj3d.mod(n) else np.nan for n in normals ]) mask = ~np.isnan(shade) if mask.any(): norm = Normalize(min(shade[mask]), max(shade[mask])) shade[~mask] = min(shade[mask]) color = mcolors.to_rgba_array(color) # shape of color should be (M, 4) (where M is number of faces) # shape of shade should be (M,) # colors should have final shape of (M, 4) alpha = color[:, 3] colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color colors[:, 3] = alpha else: colors = np.asanyarray(color).copy() return colors
def test_proj3d_deprecated(): with pytest.warns(MatplotlibDeprecationWarning): proj3d.line2d([0, 1], [0, 1]) with pytest.warns(MatplotlibDeprecationWarning): proj3d.line2d_dist([0, 1, 3], [0, 1]) with pytest.warns(MatplotlibDeprecationWarning): proj3d.mod([1, 1, 1]) vec = np.arange(4) M = np.ones((4, 4)) with pytest.warns(MatplotlibDeprecationWarning): proj3d.proj_transform_vec(vec, M) with pytest.warns(MatplotlibDeprecationWarning): proj3d.proj_transform_vec_clip(vec, M) with pytest.warns(MatplotlibDeprecationWarning): proj3d.vec_pad_ones(np.ones(3), np.ones(3), np.ones(3)) with pytest.warns(MatplotlibDeprecationWarning): proj3d.proj_trans_clip_points(np.ones((4, 3)), M)
def get_proj(self): """ Create the projection matrix from the current viewing position. elev stores the elevation angle in the z plane azim stores the azimuth angle in the x,y plane dist is the distance of the eye viewing point from the object point. """ relev, razim = np.pi * self.elev/180, np.pi * self.azim/180 xmin, xmax = self.get_xlim3d()/self.pbaspect[0] ymin, ymax = self.get_ylim3d()/self.pbaspect[1] zmin, zmax = self.get_zlim3d()/self.pbaspect[2] # transform to uniform world coordinates 0-1.0,0-1.0,0-1.0 worldM = proj3d.world_transformation(xmin, xmax, ymin, ymax, zmin, zmax) # look into the middle of the new coordinates R = np.array([0.5, 0.5, 0.5]) xp = R[0] + np.cos(razim) * np.cos(relev) * self.dist yp = R[1] + np.sin(razim) * np.cos(relev) * self.dist zp = R[2] + np.sin(relev) * self.dist E = np.array((xp, yp, zp)) self.eye = E self.vvec = R - E self.vvec = self.vvec / proj3d.mod(self.vvec) if abs(relev) > np.pi/2: # upside down V = np.array((0, 0, -1)) else: V = np.array((0, 0, 1)) zfront, zback = -self.dist, self.dist viewM = proj3d.view_transformation(E, R, V) perspM = proj3d.persp_transformation(zfront, zback) M0 = np.dot(viewM, worldM) M = np.dot(perspM, M0) return M