设置角度
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