def setup(self): if hasattr(self, "has_already_setup"): return self.has_already_setup = True self.background_mobjects = [] self.foreground_mobjects = [] self.transformable_mobjects = [] self.moving_vectors = [] self.transformable_labels = [] self.moving_mobjects = [] self.t_matrix = np.array(self.t_matrix) self.background_plane = ThreeDAxes() if self.show_coordinates: self.background_plane.add_3d_pieces() if self.include_background_plane: self.add_background_mobject(self.background_plane) if self.include_foreground_plane: self.plane = ThreeDAxes() self.add_transformable_mobject(self.plane) if self.show_basis_vectors: self.basis_vectors = self.get_basis_vectors( i_hat_color=self.i_hat_color, j_hat_color=self.j_hat_color, k_hat_color=self.k_hat_color, ) self.moving_vectors += list(self.basis_vectors) self.i_hat, self.j_hat, self.k_hat = self.basis_vectors self.add(self.basis_vectors) self.set_camera_orientation( **self.default_angled_camera_orientation_kwargs)
def get_axes(self): """ Returns a set of 3D Axes. Returns ------- ThreeDAxes object """ axes = ThreeDAxes(**self.three_d_axes_config) for axis in axes: if self.cut_axes_at_radius: p0 = axis.get_start() p1 = axis.number_to_point(-1) p2 = axis.number_to_point(1) p3 = axis.get_end() new_pieces = VGroup( Line(p0, p1), Line(p1, p2), Line(p2, p3), ) for piece in new_pieces: piece.shade_in_3d = True new_pieces.match_style(axis.pieces) axis.pieces.submobjects = new_pieces.submobjects for tick in axis.tick_marks: tick.add(VectorizedPoint(1.5 * tick.get_center(), )) return axes
def construct(self): axes = ThreeDAxes() circle = Circle() self.set_camera_orientation(phi=0 * DEGREES) self.play(ShowCreation(circle), ShowCreation(axes)) self.wait()
class LinearTransformationScene3D(ThreeDScene, LinearTransformationScene): """ This a 3D scene, and it contains special methods that make it especially suitable for showing Linear Transformations. """ CONFIG = { "camera_class": ThreeDCamera, "ambient_camera_rotation": None, "default_angled_camera_orientation_kwargs": { "phi": 70 * DEGREES, "theta": -135 * DEGREES, }, "include_background_plane": True, "include_foreground_plane": True, "foreground_plane_kwargs": { "x_max": FRAME_WIDTH / 2, "x_min": -FRAME_WIDTH / 2, "y_max": FRAME_WIDTH / 2, "y_min": -FRAME_WIDTH / 2, "faded_line_ratio": 0 }, "background_plane_kwargs": { "color": GREY, "axis_config": { "stroke_color": LIGHT_GREY, }, "axis_config": { "color": GREY, }, "background_line_style": { "stroke_color": GREY, "stroke_width": 1, }, }, "show_coordinates": False, "show_basis_vectors": False, "basis_vector_stroke_width": 6, "i_hat_color": X_COLOR, "j_hat_color": Y_COLOR, "k_hat_color": Z_COLOR, "leave_ghost_vectors": False, "t_matrix": [[1, 0, 0], [0, 1, 0], [0, 0, 1]], } def setup(self): if hasattr(self, "has_already_setup"): return self.has_already_setup = True self.background_mobjects = [] self.foreground_mobjects = [] self.transformable_mobjects = [] self.moving_vectors = [] self.transformable_labels = [] self.moving_mobjects = [] self.t_matrix = np.array(self.t_matrix) self.background_plane = ThreeDAxes() if self.show_coordinates: self.background_plane.add_3d_pieces() if self.include_background_plane: self.add_background_mobject(self.background_plane) if self.include_foreground_plane: self.plane = ThreeDAxes() self.add_transformable_mobject(self.plane) if self.show_basis_vectors: self.basis_vectors = self.get_basis_vectors( i_hat_color=self.i_hat_color, j_hat_color=self.j_hat_color, k_hat_color=self.k_hat_color, ) self.moving_vectors += list(self.basis_vectors) self.i_hat, self.j_hat, self.k_hat = self.basis_vectors self.add(self.basis_vectors) self.set_camera_orientation( **self.default_angled_camera_orientation_kwargs) def get_basis_vectors(self, i_hat_color=X_COLOR, j_hat_color=Y_COLOR, k_hat_color=Z_COLOR): """ Returns a VGroup of the Basis Vectors (1,0,0)、(0,1,0) and (0,0,1) Parameters ---------- i_hat_color (str) The hex colour to use for the basis vector in the x direction j_hat_color (str) The hex colour to use for the basis vector in the z direction k_hat_color (str) The hex colour to use for the basis vector in the y direction Returns ------- VGroup VGroup of the Vector Mobjects representing the basis vectors. """ return VGroup(*[ Vector( vect, color=color, stroke_width=self.basis_vector_stroke_width) for vect, color in [ ([1, 0, 0], i_hat_color), ([0, 1, 0], j_hat_color), ([0, 0, 1], k_hat_color), ] ]) def get_transposed_matrix_transformation(self, transposed_matrix): """ Returns a function corresponding to the linear transformation represented by the transposed matrix passed. Parameters ---------- matrix (np.ndarray, list, tuple) The matrix. """ transposed_matrix = np.array(transposed_matrix) return lambda point: np.dot(point, transposed_matrix)