manim-3D场景

设置角度

class CameraPosition4(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        circle=Circle()
        self.set_camera_orientation(phi=80 * DEGREES,theta=20*DEGREES,gamma=30*DEGREES,distance=6)
        self.play(ShowCreation(circle),ShowCreation(axes))
        self.wait()

在这里插入图片描述
其中phi表示摄像头从z轴顶部向下旋转的角度,theta表示摄像头绕z轴逆时针旋转的角度(假设坐标轴是静止不动的),整体上来说,phi和theta可以将摄像机移动到球坐标系的某一个特定点上。gamma表示摄像头绕自身的视线轴顺时针旋转的角度(由于运动的相对性,此时图像表现为逆时针旋转)。

ShowCreat和设置摄像头角度时的默认角度

在这里要特别注意的是,在默认创建3D坐标时,Y轴方向向上,X轴方向向右,Z轴方向与纸面垂直向外(指向摄像机方向)。当定义摄像位置时,Y轴的0位置是向右,X轴的0位置是向下。例如:当我们延时移动摄像头的操作时,将所有参数设为0:

class MoveCamera1(ThreeDScene):
    
    def get_axis(self, min_val, max_val, axis_config):
        new_config = merge_config([
            axis_config,
            {
   "x_min": min_val, "x_max": max_val},
            self.number_line_config,
        ])
        return NumberLine(**new_config)

    def construct(self):
        
        axes = ThreeDAxes()
        circle=Circle()
        self.play(ShowCreation(circle),ShowCreation(axes))
        self.move_camera(phi=0*DEGREES,theta=0*DEGREES,gamma=0*DEGREES,run_time=3)
        self.wait()

在这里插入图片描述
该坐标系依旧发生90°的转动。

接下来,我们尝试将摄像头设置成默认的方向。这样坐标就不会发生移动。

class MoveCamera1(ThreeDScene):
    
    def get_axis(self, min_val, max_val, axis_config):
        new_config = merge_config([
            axis_config,
            {
   "x_min": min_val, "x_max": max_val},
            self.number_line_config,
        ])
        return NumberLine(**new_config)

    def construct(self):
        
        axes = ThreeDAxes()
        circle=Circle()
        self.play(ShowCreation(circle),ShowCreation(axes))
        self.move_camera(phi=0*DEGREES,theta=0*DEGREES,gamma=90*DEGREES,run_time=1)
        self.wait()

在这里插入图片描述
另外,我也不知道为什么一定要加上def get_axis()代码才能运行。

class MoveCamera1(ThreeDScene):
    
    def get_axis(self, min_val, max_val, axis_config):
        new_config = merge_config([
            axis_config,
            {
   "x_min": min_val, "x_max": max_val},
            self.number_line_config,
        ])
        return NumberLine(**new_config)

    def construct(self):
        
        axes = ThreeDAxes()
        circle=Circle()
        self.play(ShowCreation(circle),ShowCreation(axes))
        self.move_camera(phi=80*DEGREES,theta=20*DEGREES,gamma=20*DEGREES,run_time=1)
        self.wait()

在这里插入图片描述

class MoveCamera2(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        circle=Circle()
        self.set_camera_orientation(phi=80 * DEGREES)           
        self.play(ShowCreation(circle),ShowCreation(axes))
        self.begin_ambient_camera_rotation(rate=0.1)            #Start move camera
        self.wait(5)
        self.stop_ambient_camera_rotation()                     #Stop move camera
        self.move_camera(phi=80*DEGREES,theta=-PI/2)            #Return the position of the camera
        self.wait()

在这里插入图片描述

3D场景中划线

class ParametricCurve1(ThreeDScene):
    def construct(self):
        curve1=ParametricFunction(
                lambda u : np.array([
                1.2
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值