LinearTransformationScene¶
Qualified name: manim.scene.vector\_space\_scene.LinearTransformationScene
- class LinearTransformationScene(include_background_plane=True, include_foreground_plane=True, background_plane_kwargs=None, foreground_plane_kwargs=None, show_coordinates=False, show_basis_vectors=True, basis_vector_stroke_width=6, i_hat_color=ManimColor('#83C167'), j_hat_color=ManimColor('#FC6255'), leave_ghost_vectors=False, **kwargs)[source]¶
Bases:
VectorSceneThis scene contains special methods that make it especially suitable for showing linear transformations.
- Parameters:
include_background_plane (bool) – Whether or not to include the background plane in the scene.
include_foreground_plane (bool) – Whether or not to include the foreground plane in the scene.
background_plane_kwargs (dict[str, Any] | None) – Parameters to be passed to
NumberPlaneto adjust the background plane.foreground_plane_kwargs (dict[str, Any] | None) – Parameters to be passed to
NumberPlaneto adjust the foreground plane.show_coordinates (bool) – Whether or not to include the coordinates for the background plane.
show_basis_vectors (bool) – Whether to show the basis x_axis ->
i_hatand y_axis ->j_hatvectors.basis_vector_stroke_width (float) – The
stroke_widthof the basis vectors.i_hat_color (ParsableManimColor) – The color of the
i_hatvector.j_hat_color (ParsableManimColor) – The color of the
j_hatvector.leave_ghost_vectors (bool) – Indicates the previous position of the basis vectors following a transformation.
kwargs (Any)
Examples
Example: LinearTransformationSceneExample ¶
from manim import * class LinearTransformationSceneExample(LinearTransformationScene): def __init__(self, **kwargs): LinearTransformationScene.__init__( self, show_coordinates=True, leave_ghost_vectors=True, **kwargs ) def construct(self): matrix = [[1, 1], [0, 1]] self.apply_matrix(matrix) self.wait()
class LinearTransformationSceneExample(LinearTransformationScene): def __init__(self, **kwargs): LinearTransformationScene.__init__( self, show_coordinates=True, leave_ghost_vectors=True, **kwargs ) def construct(self): matrix = [[1, 1], [0, 1]] self.apply_matrix(matrix) self.wait()Methods
Adds the mobjects to the special list self.background_mobjects.
Adds the mobjects to the special list self.foreground_mobjects.
Adds the mobject to the special list self.moving_mobject, and adds a property to the mobject called mobject.target, which keeps track of what the mobject will move to or become etc.
Adds mobjects to a separate list that can be tracked, if these mobjects have some extra importance.
Adds a title, after scaling it, adding a background rectangle, moving it to the top and adding it to foreground_mobjects adding it as a local variable of self.
Method for creating, and animating the addition of a transformable label for the vector.
Adds the mobjects to the special list self.transformable_mobjects.
Adds a unit square to the scene via self.get_unit_square.
Adds a vector to the scene, and puts it in the special list self.moving_vectors.
Applies the given function to each of the mobjects in self.transformable_mobjects, and plays the animation showing this.
This method applies the linear transformation represented by the inverse of the passed matrix to the number plane, and each vector/similar mobject on it.
Applies the inverse of the transformation represented by the given transposed matrix to the number plane and each vector/similar mobject on it.
Applies the transformation represented by the given matrix to the number plane, and each vector/similar mobject on it.
Applies the non-linear transformation represented by the given function to the number plane and each vector/similar mobject on it.
Applies the transformation represented by the given transposed matrix to the number plane, and each vector/similar mobject on it.
Returns all ghost vectors ever added to
self.Returns a function corresponding to the linear transformation represented by the matrix passed.
This method returns an animation that moves a mobject in "self.moving_mobjects" to its corresponding .target value.
This method returns an animation that moves an arbitrary mobject in "pieces" to its corresponding .target value.
This method returns an animation that moves all labels in "self.transformable_labels" to its corresponding .target .
Returns a function corresponding to the linear transformation represented by the transposed matrix passed.
Returns a unit square for the current NumberPlane.
This method returns an animation that moves a mobject in "self.moving_vectors" to its corresponding .target value.
This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called.
update_default_configsReturns a column matrix indicating the vector coordinates, after writing them to the screen, and adding them to the special list self.foreground_mobjects
Attributes
cameratimeThe time since the start of the scene.
- add_background_mobject(*mobjects)[source]¶
Adds the mobjects to the special list self.background_mobjects.
- Parameters:
*mobjects (Mobject) – The mobjects to add to the list.
- Return type:
None
- add_foreground_mobject(*mobjects)[source]¶
Adds the mobjects to the special list self.foreground_mobjects.
- Parameters:
*mobjects (Mobject) – The mobjects to add to the list
- Return type:
None
- add_moving_mobject(mobject, target_mobject=None)[source]¶
Adds the mobject to the special list self.moving_mobject, and adds a property to the mobject called mobject.target, which keeps track of what the mobject will move to or become etc.
- add_special_mobjects(mob_list, *mobs_to_add)[source]¶
Adds mobjects to a separate list that can be tracked, if these mobjects have some extra importance.
- add_title(title, scale_factor=1.5, animate=False)[source]¶
Adds a title, after scaling it, adding a background rectangle, moving it to the top and adding it to foreground_mobjects adding it as a local variable of self. Returns the Scene.
- Parameters:
- Returns:
The scene with the title added to it.
- Return type:
- add_transformable_label(vector, label, transformation_name='L', new_label=None, **kwargs)[source]¶
Method for creating, and animating the addition of a transformable label for the vector.
- Parameters:
vector (Vector) – The vector for which the label must be added.
label (MathTex | str) – The MathTex/string of the label.
transformation_name (str | MathTex) – The name to give the transformation as a label.
new_label (str | MathTex | None) – What the label should display after a Linear Transformation
**kwargs (Any) – Any valid keyword argument of get_vector_label
- Returns:
The MathTex of the label.
- Return type:
- add_transformable_mobject(*mobjects)[source]¶
Adds the mobjects to the special list self.transformable_mobjects.
- Parameters:
*mobjects (Mobject) – The mobjects to add to the list.
- Return type:
None
- add_unit_square(animate=False, **kwargs)[source]¶
Adds a unit square to the scene via self.get_unit_square.
- Parameters:
animate (bool) – Whether or not to animate the addition with DrawBorderThenFill.
**kwargs (Any) – Any valid keyword arguments of self.get_unit_square()
- Returns:
The unit square.
- Return type:
- add_vector(vector, color=ManimColor('#FFFF00'), animate=False, **kwargs)[source]¶
Adds a vector to the scene, and puts it in the special list self.moving_vectors.
- Parameters:
vector (Arrow | list | tuple | ndarray) – It can be a pre-made graphical vector, or the coordinates of one.
color (ParsableManimColor) – The string of the hex color of the vector. This is only taken into consideration if ‘vector’ is not an Arrow. Defaults to YELLOW.
**kwargs (Any) – Any valid keyword argument of VectorScene.add_vector.
animate (bool)
**kwargs
- Returns:
The arrow representing the vector.
- Return type:
- apply_function(function, added_anims=[], **kwargs)[source]¶
Applies the given function to each of the mobjects in self.transformable_mobjects, and plays the animation showing this.
- Parameters:
function (MappingFunction) – The function that affects each point of each mobject in self.transformable_mobjects.
added_anims (list[Animation]) – Any other animations that need to be played simultaneously with this.
**kwargs (Any) – Any valid keyword argument of a self.play() call.
- Return type:
None
- apply_inverse(matrix, **kwargs)[source]¶
This method applies the linear transformation represented by the inverse of the passed matrix to the number plane, and each vector/similar mobject on it.
- Parameters:
matrix (ndarray | list | tuple) – The matrix whose inverse is to be applied.
**kwargs (Any) – Any valid keyword argument of self.apply_matrix()
- Return type:
None
- apply_inverse_transpose(t_matrix, **kwargs)[source]¶
Applies the inverse of the transformation represented by the given transposed matrix to the number plane and each vector/similar mobject on it.
- Parameters:
t_matrix (ndarray | list | tuple) – The matrix.
**kwargs (Any) – Any valid keyword argument of self.apply_transposed_matrix()
- Return type:
None
- apply_matrix(matrix, **kwargs)[source]¶
Applies the transformation represented by the given matrix to the number plane, and each vector/similar mobject on it.
- Parameters:
matrix (ndarray | list | tuple) – The matrix.
**kwargs (Any) – Any valid keyword argument of self.apply_transposed_matrix()
- Return type:
None
- apply_nonlinear_transformation(function, **kwargs)[source]¶
Applies the non-linear transformation represented by the given function to the number plane and each vector/similar mobject on it.
- Parameters:
function (Callable[[ndarray], ndarray]) – The function.
**kwargs (Any) – Any valid keyword argument of self.apply_function()
- Return type:
None
- apply_transposed_matrix(transposed_matrix, **kwargs)[source]¶
Applies the transformation represented by the given transposed matrix to the number plane, and each vector/similar mobject on it.
- Parameters:
transposed_matrix (ndarray | list | tuple) – The matrix.
**kwargs (Any) – Any valid keyword argument of self.apply_function()
- Return type:
None
- get_ghost_vectors()[source]¶
Returns all ghost vectors ever added to
self. Each element is aVGroupof two ghost vectors.- Return type:
- get_matrix_transformation(matrix)[source]¶
Returns a function corresponding to the linear transformation represented by the matrix passed.
- Parameters:
matrix (ndarray | list | tuple) – The matrix.
- Return type:
Callable[[TypeAliasForwardRef(‘~manim.typing.Point3D’)], TypeAliasForwardRef(‘~manim.typing.Point3D’)]
- get_moving_mobject_movement(func)[source]¶
This method returns an animation that moves a mobject in “self.moving_mobjects” to its corresponding .target value. func is a function that determines where the .target goes.
- Parameters:
func (MappingFunction) – The function that determines where the .target of the moving mobject goes.
- Returns:
The animation of the movement.
- Return type:
- get_piece_movement(pieces)[source]¶
This method returns an animation that moves an arbitrary mobject in “pieces” to its corresponding .target value. If self.leave_ghost_vectors is True, ghosts of the original positions/mobjects are left on screen
- get_transformable_label_movement()[source]¶
This method returns an animation that moves all labels in “self.transformable_labels” to its corresponding .target .
- Returns:
The animation of the movement.
- Return type:
- get_transposed_matrix_transformation(transposed_matrix)[source]¶
Returns a function corresponding to the linear transformation represented by the transposed matrix passed.
- Parameters:
transposed_matrix (ndarray | list | tuple) – The matrix.
- Return type:
Callable[[TypeAliasForwardRef(‘~manim.typing.Point3D’)], TypeAliasForwardRef(‘~manim.typing.Point3D’)]
- get_unit_square(color=ManimColor('#FFFF00'), opacity=0.3, stroke_width=3)[source]¶
Returns a unit square for the current NumberPlane.
- Parameters:
color (TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor') | Iterable[TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor')]) – The string of the hex color code of the color wanted.
opacity (float) – The opacity of the square
stroke_width (float) – The stroke_width in pixels of the border of the square
- Return type:
- get_vector_movement(func)[source]¶
This method returns an animation that moves a mobject in “self.moving_vectors” to its corresponding .target value. func is a function that determines where the .target goes.
- Parameters:
func (MappingFunction) – The function that determines where the .target of the moving mobject goes.
- Returns:
The animation of the movement.
- Return type:
- setup()[source]¶
This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called.
- Return type:
None