首页 > 其他分享 >manim学习笔记04:使用manim,表示向量和加法。

manim学习笔记04:使用manim,表示向量和加法。

时间:2024-07-12 23:28:49浏览次数:14  
标签:end 04 color vec Arrow 加法 buff dot manim

manim学习笔记04:使用manim,表示向量和加法。

一,相关定义

1.有向线段:

规定若线段 AB的端点为起点为A,B为终点,则线段就具有了从起点 A到终点 B的方向和长度。具有方向和长度的线段叫做有向线段。

接下来我们体会一下相关的代码:

class VectorArrow(Scene):
    def construct(self):
        colorA = "#87c2a5"
        colorB = "#525893"
        colorC = "#e07a5f"
        dot = Dot(ORIGIN,color=RED)
        self.camera.background_color = WHITE
        arrow01 = Arrow(dot, [2, 1.2, 0], buff=0,color=colorA)
        arrow02 = Arrow(dot, [3.5, 1, 0], buff=0,color=colorB)
        arrow03 = Arrow(dot, [3, 3.4, 0], buff=0,color=colorC)
        arrow04 = Arrow(dot, [-2, 4, 0], buff=0,color=colorA)
        arrow05 = Arrow(dot, [-3.5, 1, 0], buff=0,color=colorB)
        arrow06 = Arrow(dot, [-0.6, 3.4, 0], buff=0,color=colorC)
        arrow07 = Arrow(dot, [2, -4, 0], buff=0,color=colorA)
        arrow08 = Arrow(dot, [3.5, -1, 0], buff=0,color=colorB)
        arrow09 = Arrow(dot, [0.6, -3.4, 0], buff=0,color=colorC)
        arrow10 = Arrow(dot, [-2, -3, 0], buff=0,color=colorA)
        arrow11 = Arrow(dot, [-3.5, -1, 0], buff=0,color=colorB)
        arrow12 = Arrow(dot, [-3, -3.4, 0], buff=0,color=colorC)
        
        
        #numberplane = NumberPlane()
        #origin_text = Text('(0, 0)').next_to(dot, DOWN)
        #tip_text = Text('(2, 2)').next_to(arrow.get_end(), RIGHT)
        self.add(dot,arrow01,arrow02,arrow03,arrow04,arrow05,arrow06,arrow07,
                    arrow08,arrow09,arrow10,arrow11,arrow12)

结果如下:

2.向量的模

向量的大小,也就是向量的长度(或称模)。向量a的模记作|a|。向量的模是非负实数,向量的模是可以比较大小的。如向量\vec{a}的起点为远点,重点为(x,y),则|a|=\sqrt{x^{2}+y^{2}}

可视化代码为:

from manim import *

class VectorArrow03(Scene):
    def construct(self):
        dot = Dot(ORIGIN)
        arrow = Arrow(dot, [2, 2, 0], buff=0)
        numberplane = NumberPlane()
        t0 = MathTex(r"\begin{bmatrix}0\\0\end{bmatrix}")
        t1= MathTex(r"\begin{bmatrix}X(2)\\Y(2)\end{bmatrix}")
        t2=MathTex(r"\begin{bmatrix}0 & 0 \\ 2 & 2\end{bmatrix}")
        t3=MathTex(r"\overrightarrow{a}") 
        vec=t2.next_to([1,2,0],UP)
        origin_text = t0.next_to(dot, LEFT+DOWN)
        tip_text = t1.next_to(arrow.get_end(), RIGHT+DOWN)
        tip_text01 = t3.next_to(arrow.get_end(),3*LEFT+DOWN)
        AA=MathTex(r"\left | \overrightarrow{a}  \right | =\sqrt{x^{2}+y^{2} } ")
        t4=AA.next_to([5,-1,0],3*LEFT+DOWN)
        
        
        self.add(numberplane,t2,t4, dot,vec, arrow, origin_text, tip_text,tip_text01)
%manim -qm -v WARNING VectorArrow03

结果为:

 3.向量的加法:

可视化代码为:

from manim import *

class ParallelogramRule(Scene):
    def construct(self):
        numberplane = NumberPlane()
        dot = Dot(ORIGIN)
        # Create vectors
        vec_a = Arrow(start=dot, end=[2, 1, 0],buff=0,  color=BLUE)
        vec_b = Arrow(start=dot, end=[1, 2, 0],buff=0, color=RED)

        # Create parallelogram
        parallelogram = Polygon(ORIGIN, vec_a.get_end(), vec_a.get_end() + vec_b.get_end(), vec_b.get_end(), color=GREEN, fill_color=GREEN, fill_opacity=0.5)
        self.add(numberplane,dot)
        # Display vectors and parallelogram
        self.play(Create(vec_a), Create(vec_b))
        self.play(Create(parallelogram))

        self.wait(1)

class TriangleRule(Scene):
    def construct(self):
        # Create vectors
        numberplane = NumberPlane()
        dot = Dot(ORIGIN)
        vec_a = Arrow(start=ORIGIN, end=[2, 1, 0],buff=0 ,color=BLUE)
        vec_b = Arrow(start=ORIGIN, end=[1, 2, 0],buff=0, color=RED)

        # Create triangle
        triangle = Polygon(ORIGIN, vec_a.get_end(), vec_a.get_end() + vec_b.get_end(), color=PURPLE)
        self.add(numberplane,dot)
        # Display vectors and triangle
        self.play(Create(vec_a), Create(vec_b))
        self.play(Create(triangle))

        self.wait(1)

 运行结果为:

标签:end,04,color,vec,Arrow,加法,buff,dot,manim
From: https://blog.csdn.net/qq_45449625/article/details/134868710

相关文章

  • leetcode简单题21 N.104 二叉树的最大深度 rust描述
     //[3,9,20,null,null,15,7]3//[1,null,2]2usestd::rc::Rc;usestd::cell::RefCell;//Definitionforabinarytreenode.#[derive(Debug,PartialEq,Eq)]pubstructTreeNode{pubval:i32,publeft:Option<Rc<RefCell<TreeNode>>......
  • 04OLED简介和调试方法
    OLED简介和调试方法调试方式串口调试显示屏调试其他调试方法总结:OLED简介硬件电路OLED驱动函数keil调试模式进入方法keil调试界面窗口简单功能说明更加强大的功能调试方式电脑想看什么变量可以直接打印到屏幕,但是单片机很多时候由于成本和电路结构的限制,就不会有......
  • 运维系列:数据库服务器 重启mysql服务出现 ERROR 1045: Access denied for user: ‘roo
    @[TOC](数据库服务器重启mysql服务出现ERROR1045:Accessdeniedforuser:‘root@localhost’(Usingpassword:NO)怎么)数据库服务器重启mysql服务出现ERROR1045:Accessdeniedforuser:‘root@localhost’(Usingpassword:NO)怎么解决?系统是ubuntuse......
  • Nessus Professional 10.7 Auto Installer for Ubuntu 24.04 (updated Jul 2024)
    NessusProfessional10.7AutoInstallerforUbuntu24.04(updatedJul2024)发布Nessus试用版自动化安装程序,支持macOSSonoma、RHEL9和Ubuntu24.04请访问原文链接:https://sysin.org/blog/nessus-auto-install-for-ubuntu/,查看最新版。原创作品,转载请保留出处。Ness......
  • 解决Tomcat 8.5在浏览器输入localhost:8080出现404报错的全面指南
    当你在浏览器中输入http://localhost:8080时,期望看到部署在ApacheTomcat8.5上的应用,但却遭遇404错误,这无疑是一件令人沮丧的事情。404错误通常表示服务器无法找到你请求的资源。本文将详细探讨导致此问题的各种原因以及相应的解决策略,帮助你排除故障,让应用正常运行。1.确认......
  • 雨晨 Windows 10 IOT 企业版 2021 长期服务版 19044.4651
    文件:YC19044.4561_iotltsc2021_x64_VIP3in1_install.wim同时支持直接激活以专业版为基础的所有虚拟版本大小:2653323398字节修改时间:2024年7月12日,15:39:54MD5:52565BC0E1DC7F205353E25CBE0AA2F7SHA1:E327D67581FD86DDF6F816870DA4C8EFEE589825CRC32:DAFC1D2......
  • 【YashanDB知识库】yasql登录报错:YAS-00413
    【问题分类】错误码处理【关键字】yasql,00413【问题描述】使用工具设置不同并发迁移数据的过程中,导致yasql登录报错:YAS-00413【问题原因分析】工具使用与数据库使用资源超过了操作系统配置参数设置【解决/规避方法】●查看操作系统yashan用户当前打开文件文件数SQLlsof|......
  • Day9(栈与队列) | **232.用栈实现队列** **225. 用队列实现栈** **20. 有效的括号**
    232.用栈实现队列请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty):实现MyQueue类:voidpush(intx)将元素x推到队列的末尾intpop()从队列的开头移除并返回元素intpeek()返回队列开头的元素booleanempty()如果队列为......
  • ubuntu 18.04 安装 腾讯原生微信
    使用终端命令行安装铜豌豆软件源。注意需要用到sudo权限。```textwget-c-Oatzlinux-v12-archive-keyring_lastest_all.debhttps://www.atzlinux.com/atzlinux/pool/main/a/atzlinux-archive-keyring/atzlinux-v12-archive-keyring_lastest_all.debsudoapt-yinstall./......
  • 【Mutilism用74ls192和与非门设计3进制24进制加法计数器2荔枝】2022-5-10
    缘由【数电数字逻辑】如何用74ls192和与非门设计任意进制加法计数器?-嵌入式-CSDN问答 ......