Semester 1, Week 05‐06 Development - 62firelight/manimRT-490 GitHub Wiki

Trying out a different style of post to see what works...

What's been done so far...

  • Added draw_ray method for drawing through pixels (AKA center of grid cell) -- used coords2points method in NumberPlane class to accomplish this
  • Added focal length parameter
  • Parameterized for grid width and height (i.e., camera resolution)
  • Added draw_ray function for drawing rays anywhere (the current method is based on a ray equation which takes start point, direction and distance as parameters)
  • Can now keep track of ray properties (start point, direction and distance for now)

The image below was rendered using the draw_ray method. See the figure description below for more details.

Proof of Concept

RayObjectIntersectionsPoC_ManimCE_v0 18 0

Figure 1: A proof-of-concept image (source code here) produced using the Camera, Ray, FreeRay, and Helper source files.

The camera is generated with a start point of [0, 0, 6], focal_length of 5, width of 16 and height of 9.

The red ray is created using camera_obj.draw_ray(9, 5, 2, RED) and shoots through the center of (9, 5) on the camera's image plane. It has a distance of 2.

The green ray is created by initializing a FreeRay object with a starting point of [0, 0, 6], direction of [1, 0, 0], and distance of 1.5 units.

The blue ray uses the same method call as the red ray and shoots through (15, 2).

The sphere is generated by calling a method on the red ray's object -- sphere_along_ray = red_ray_obj.generate_sphere(1.5) where 1.5 is the distance from the start of the ray to the sphere's center.

Issues

ManimRT as a Wrapper

The source code currently functions like a "wrapper" which makes Python objects that contain their own Manim objects rather than behaving like an internal Manim mobject. Since this is just a proof-of-concept, it's probably fine for now, but a decision should be made as to whether ManimRT should continue being developed in this way or if it should hook into Manim's internal code.

Maybe it would be better to not use Python objects and instead rely purely on functions (especially if the objects are going to be immutable)?

Coordinate Frame Confusion

The camera's NumberPlane mobject has a different coordinate frame than the Manim camera's coordinate frame, which makes things really confusing. The green ray is pointing in the positive X direction, but the NumberPlane's X direction is perpendicular to the green ray's direction. Perhaps the camera orientation in the image might be a key factor. It probably doesn't help that the camera has also been rotated 90 degrees anticlockwise.

To make it easier to orient the camera, the camera object could be aligned with a different axis. Right now, it's aligned with the Z axis.

NumberPlane grid lines overlaid over other objects

The grid lines on the camera's NumberPlane mobject are overlaid over the camera lines, likely due to NumberPlane is descended from the Axes mobject. Not the worst issue, but it's something to consider for later on.

To-Do List

From highest priority to lowest priority:

  • Perform automatic intersections between rays and spheres at the origin
    • Automatically figure out the normal (easy for spheres)
  • Perform automatic intersections between rays and transformed spheres
    • Automatically figure out the inverse of the linear transformation (use a matrix library like NumPy??)
    • Apply the inverse linear transformation to the ray (start point of the ray + direction of the ray)
    • Then apply the transformation to the hit point to find the actual intersection
    • Also apply the transposed inverse transformation to the normal to find the actual normal
  • Determine if ray objects should be immutable (currently, they are partially mutable as the direction can be changed)
  • Determine if the Camera's draw_ray should be normalizing the vector's magnitude (currently, 1 unit of the ray drawn with the draw_ray method is equivalent to the camera's focal length)
  • Generate spheres that intersect the ray at different points (2 intersection points + 1 intersection + no intersection)
  • Add a method that prints LaTeX equations for rays
  • Add docstrings for better documentation
  • Add option to initialize camera grid with x value and aspect ratio
  • Investigate if indeterminate rotations happen with other objects