用manim创建坐标系

用manim创建坐标系

1.Axes._update_default_configs()的使用

 构造函数:

static _update_default_configs(default_configs, passed_configs)

 

manim 是一个用于创建数学动画的 Python 库。static _update_default_configs(default_configs, passed_configs) 是 manim 中的一个静态方法,用于更新默认的配置参数。下面是对该函数及其参数的解释。

函数的目的

_update_default_configs 函数的主要目的是将用户传入的配置(passed_configs)合并到默认配置(default_configs)中。通过这种方式,用户可以覆盖默认的配置而不必完全重写它们。

参数说明

  1. default_configs:

    • 类型: 字典
    • 说明: 这是一个包含默认配置的字典。在 manim 中,许多对象和类都有一些默认的配置选项,例如颜色、大小、动画持续时间等。这个参数代表了这些默认值。
  2. passed_configs:

    • 类型: 字典
    • 说明: 这是用户传入的配置字典。用户可以通过这个字典提供自定义的配置选项,这些选项将会覆盖 default_configs 中对应的值。

函数的工作原理

  • 函数首先接收这两个字典。
  • 然后,它会遍历 passed_configs 中的每一个键值对。
  • 如果 passed_configs 中的键在 default_configs 中存在,那么 default_configs 对应的值将被更新为 passed_configs 中的值。
  • 如果某个键在 passed_configs 中存在但在 default_configs 中不存在,通常会将其添加到 default_configs 中。
  • 最终,函数返回更新后的 default_configs 字典。

2.Axes.coords_to_point()的使用

在 Manim 中,coords_to_point(*coords) 函数用于将给定的坐标转换为场景中的点。这个函数通常在 3D 场景中使用,它将 (x, y, z) 坐标直接转换为 Manim 可以处理的点。

下面是一个简单的 Manim 项目示例,展示如何使用 coords_to_point 函数来创建一个三维场景。在这个场景中,我们将绘制几个立方体,展示它们在不同坐标位置的效果。

示例1: 

class CoordsToPointExample(Scene):
    def construct(self):
        ax = Axes().add_coordinates()

        # a dot with respect to the axes
        dot_axes = Dot(ax.coords_to_point(2, 2,2), color=GREEN)
        lines = ax.get_lines_to_point(ax.c2p(2,2))

        # a dot with respect to the scene
        # the default plane corresponds to the coordinates of the scene.
        plane = NumberPlane()
        dot_scene = Dot((2,2,0), color=RED)

        self.add(plane, dot_scene, ax, dot_axes, lines)

 运行结果:

 示例2:

from manim import *  
import numpy as np  

class CoordsToPointScene0111(ThreeDScene):  
    def construct(self):  
        # 定义一些 3D 坐标  
        coords = [  
            (2, 1, 0),  
            (1, -2, 1),  
            (0, 0, 2),  
            (-1, 1, -1),  
            (-2, -1, 0),  
        ]  

        # 创建立方体并将其放置在指定坐标  
        cubes = []  
        for coord in coords:  
            cube = Cube(side_length=0.5, fill_color=BLUE, fill_opacity=1)  
            # 使用 np.array 将坐标转换为点  
            cube.move_to(np.array(coord))  
            cubes.append(cube)  

        # 将立方体添加到场景中  
        self.play(*[Create(cube) for cube in cubes])  
        self.wait(1)  

        # 旋转场景以观察立方体  
        self.move_camera(phi=60 * DEGREES, theta=60 * DEGREES, run_time=3)  
        self.wait(2)  

        # 转动立方体  
        self.play(*[Rotate(cube, angle=PI, axis=UP) for cube in cubes])  
        self.wait(2)  

 运行结果:

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Yasen.M

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

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

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

打赏作者

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

抵扣说明:

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

余额充值