Manim系列——创建并使用坐标系统

到目前为止,我们一直在研究表单的功能y=f(x)具有一个自变量和一个因变量。这些函数可以在二维空间中表示,使用两个数值轴,使我们能够用两个数字识别平面中的每个点。我们现在想谈谈三维空间;为了识别三维空间中的每个点,我们需要三个数值。建立这种关联的明显方法是添加一个新轴,垂直于xy我们已经明白的轴。例如,我们可以添加第三个轴,即z轴, 与正z轴直接从页面中出来,而负极则zz轴从页面的背面伸出。这在打印页面上很难处理,因此我们通常从一个角度绘制三个轴的视图:

 示例1:

from manim import *  

class CoordSysExample(Scene):  
    def construct(self):  
        grid = Axes(  
            x_range=[0, 1, 0.1],  
            y_range=[0, 1, 0.1],  
            x_length=9,  
            y_length=5.5,  
            axis_config={  
                "numbers_to_include": np.arange(0, 1 + 0.1, 0.1),  
                "font_size": 24,  
            },  
            tips=False,  
            color=GREEN  
        )  

        # Labels for the x-axis and y-axis  
        y_label = grid.get_y_axis_label("y", edge=LEFT, direction=LEFT, buff=0.4)  
        x_label = grid.get_x_axis_label("x")  
        grid_labels = VGroup(x_label, y_label)  

        graphs = VGroup()  
        for n in np.arange(1.5, 10.5, 0.5):  # Adjusting the range step  
            graphs += grid.plot(lambda x: x ** n, color=YELLOW)  
            graphs += grid.plot(lambda x: x ** (1 / n), color=RED_B, use_smoothing=False)  

        # Create a dashed line for y = x  
        A12 = DashedLine(start=grid.c2p(0, 0), end=grid.c2p(1, 1), color=WHITE)  
        self.add(A12)  
        
        # Extra lines and labels for point (1,1)  
        graphs += grid.get_horizontal_line(grid.c2p(1, 1, 0), color=BLUE)  
        graphs += grid.get_vertical_line(grid.c2p(1, 1, 0), color=BLUE)  
        graphs += Dot(point=grid.c2p(1, 1, 0), color=YELLOW)  
        graphs += Tex("(1,1)").scale(0.75).next_to(grid.c2p(1, 1, 0))  

        # Title of the scene  
        title = Title(  
            r"Graphs of $y=x^{ {1}\over{n} }$ and $y=x^n (n=1,2,3,...,10)$",  
            include_underline=False,  
            font_size=40,  
        )  

        # Display all elements  
        self.add(title, graphs, grid, grid_labels)

 运行结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yasen.M

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值