나의 작은 valley

[시각화 기술] Vector, linear transformation 본문

그래픽스(graphics)/시각화 기술(visualization)

[시각화 기술] Vector, linear transformation

붕옥 아이젠 2022. 11. 29. 19:34
728x90

import section)

from manim import *
import random
config.media_width = "50%"
config.verbosity = "WARNING"

 

 

How to make Vectors)

As you now first line is magic spell. ALWAYS %% LINE HAS TO GO FIRST(<< SO IMPORTANT)

%%manim -qh Vectors

class Vectors (VectorScene):
    def construct(self):
        plane = self.add_plane(animate =True).add_coordinates() #좌표계
        vector = self.add_vector([-3,2],color = GREEN_C)

        #basis = self.get_basis_vectors()
        #self.add(basis)
        self.vector_to_coords(vector = vector)

        vector2 = self.add_vector([2,2], color = WHITE)
        self.write_vector_coordinates(vector = vector2)

 

 

How to make linear transformation(선형변환))

There is class named VectorScene.

if you want to learn more visit Manim Commnity. 

%%manim -qh  Matrix

from manim import *
import random


class Matrix(LinearTransformationScene):
    def __init__(self):
        LinearTransformationScene.__init__(
            self,
            show_coordinates=True,
            leave_ghost_vectors=True,
            show_basis_vectors=True,
        )

    def construct(self):

        matrix = [[1, 2], [2, 1]]

        matrix_tex = (
            MathTex("A = \\begin{bmatrix} 1 & 2 \\\ 2 & 1 \\end{bmatrix}")
            .to_edge(UL)
            .add_background_rectangle()
        )

        unit_square = self.get_unit_square()
        text = always_redraw(
            lambda: Tex("Det(A)").set(width=0.7).move_to(unit_square.get_center())
        )

        vect = self.get_vector([1, -2], color=PURPLE_B)

        rect1 = Rectangle(
            height=2, width=1, stroke_color=BLUE_A, fill_color=BLUE_D, fill_opacity=0.6
        ).shift(UP * 2 + LEFT * 2)

        circ1 = Circle(
            radius=1, stroke_color=BLUE_A, fill_color=BLUE_D, fill_opacity=0.6
        ).shift(DOWN * 2 + RIGHT * 1)

        self.add_transformable_mobject(vect, unit_square, rect1, circ1)
        self.add_background_mobject(matrix_tex, text)
        self.apply_matrix(matrix)

        self.wait()

magic spells are only avaliable when you're using Jupyter. and in jupyter you can import things in the another cells. 

 

p.s) I don't know why we have to import random libaray 

728x90
Comments