Location>code7788 >text

Three-dimensional view in manim

Popularity:498 ℃/2024-08-18 09:44:58

Today I looked into ThreeDAxes and set_camera_orientation in manim.

Here's a record of perspective.

The 3D coordinate system in manim is a Cartesian 3D coordinate system, which belongs to the right-handed coordinate system, i.e., the thumb, index finger, and middle finger of the right hand are perpendicular, with the thumb pointing to the x-axis, the index finger to the y-axis, and the middle finger to the z-axis.

While initializing the 3D coordinate system, the x-axis points to the bottom of the screen, the y-axis is pointing to the left of the screen, and the z-axis is pointing to the outside of the screen (pointing to the user's position), as in the following directions.

     / z
     /
  Origin /_____ y
       |
       |
     | x

In the meantime, we need to set the camera position.

self.set_camera_orientation(phi=0 *DEGREES, theta=-90 * DEGREES, gamma = 0 * DEGREE, focal_distance = 5)

Here the position of the camera several parameters

  • phi: represents the angle of the line from the origin to the camera position in the positive direction of the z-axis. A value of 0 means that the camera position is on a line extending positively from the z-axis. A value of 30 means that the camera is on a tapered surface centered on the z-axis.
  • focal_distance: represents the distance between the camera position and the origin, combining focal_distance and phi defines the camera position on some curve of the cone.
  • theta: represents the angle at which the camera position is rotated around the z-axis on the curve. When rotating, it is also important to consider that the camera itself is directly above it, which also changes with the rotation angle. A value of 0 means that the position is in the positive direction of the x-axis, directly above the camera towards the origin. A value of 30 means that the camera is rotated 30 degrees to the right of the z-axis, with the top of the camera facing the origin.
  • gamma: represents the rotation angle directly above the camera. 90 means 90 degrees of spin to the right.

Here are some examples that need to be understood to really understand these parameters.

Example 1:
self.set_camera_orientation(phi=0 * DEGREES, theta=-90 * DEGREES, gamma = 0 * DEGREE, focal_distance = 5) What does this look like in the form seen?

Answer:
The camera position is on the positive side of the z-axis, and the camera was originally facing up towards the negative side of the x-axis, so if you turn 90 degrees to the left around the z-axis, then the camera is facing up towards the positive side of the y-axis, the x-axis is on the right side of the camera, and the z-axis is not visible at all.
This is our normal 2D perspective. You see the x-axis to the right and the y-axis up.
Example 2:
self.set_camera_orientation(phi=0 * DEGREES, theta=0 * DEGREES, gamma = 0 * DEGREE, focal_distance = 5) What does this look like in the form seen?

Answer:
The camera position is on the positive z-axis, the camera is directly above it facing the negative x-axis, and it doesn't have any spin of its own.
Here you will also see a 2D perspective, but with the x-axis down and the y-axis to the right.
Example 3:
self.set_camera_orientation(phi=0 * DEGREES, theta=0 * DEGREES, gamma = 90 * DEGREE, focal_distance = 5) What does this look like in the form seen?

Answer:
The camera position is on the positive z-axis, and the camera was originally facing directly up towards the negative x-axis, although it did not rotate around the z-axis. However, the camera rotates on its own, spinning 90 degrees to the right, and the top of the camera is now facing the y-axis.
As in Example 1, we now have a 2D view with the x-axis to the right and the y-axis up.
Example 4:
self.set_camera_orientation(phi=70 * DEGREES, theta=30 * DEGREES, gamma = 0 * DEGREE, focal_distance = 5) What does this look like in the form seen?

Answer:
The camera position is on a circular orbit 70 degrees forward of the z-axis and at a distance of 5. The initial position is on the x-axis and rotated 30 degrees around the z-axis, and the camera position is a positive value of x, y, and z in three-dimensional space. The camera position is positive in x, y, and z in three-dimensional space, and the camera is oriented directly above it toward the origin.
This creates a top-down and oblique view of the z-axis. There is a sense of globalization.