Semester 1, Week 11 Development - 62firelight/manimRT-490 GitHub Wiki

What's New

Finished Features

  • As a user I want to find the intersection point between a ray and a plane so I can demonstrate ray-plane intersections
  • As a developer I want to add a new object (other than spheres) that rays can intersect so that I can teach ray-tracing for different objects in my scene
  • (maybe) As a user I want to get a refracted ray as it passes through another surface with a different refractive index so I can illustrate refraction and how it uses Snell's Law

Tutorial - Adding a new object to ManimRT

https://github.com/62firelight/manimRT-490/wiki/Adding-a-new-object-to-ManimRT

Script Update for Ray-Object Intersections

  • Added a simple example that aims to calculates the intersection(s) between a ray and a transformed sphere

https://docs.google.com/document/d/1j2JA1Lx1HTZdF_F1Iu-l4CO_TiWdxt9ipMog1pYYnRw/edit#heading=h.vjxy6y5dgdf

Feature Showcase

Plane Implementation

Intersections between a ray and a plane (transformed in every possible way) can now be calculated.

RTPlaneTest_ManimCE_v0 18 0

Code (click to reveal)
from manim import *

from manim_rt.RTPlane import RTPlane
from manim_rt.Ray3D import Ray3D

class RTPlaneTest(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=45*DEGREES, theta=45*DEGREES)
        
        axes = ThreeDAxes()
        labels = axes.get_axis_labels()
    
        plane_centre = [0.5, 0.5, -0.5]
        plane = RTPlane(plane_centre, 2, 4, 6, 45 * DEGREES, 45 * DEGREES, 45 * DEGREES)
        
        ray_start = [1, -1, 1]
        ray = Ray3D(ray_start, np.subtract(plane_centre, ray_start), 5, color=RED)
        
        hit_points = plane.get_intersection(ray)
        
        first_hit_point = hit_points[0]
        self.add(Dot3D(first_hit_point))
        
        unit_normal = Ray3D(first_hit_point, ray.get_unit_normal(0), color=GREEN)
        
        self.add(axes, labels, plane, ray, unit_normal)

Refraction with a Plane

It looks right... right? I think I'll need to do some more testing to confirm that refraction is working as intended.

RefractedRayTest_ManimCE_v0 18 0

Code (click to reveal)
from manim import *

from manim_rt.Arc3D import Arc3D
from manim_rt.RTPlane import RTPlane
from manim_rt.RTSphere import RTSphere
from manim_rt.Ray3D import Ray3D

class RefractedRayTest(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=89 * DEGREES, theta=-180 * DEGREES, zoom=1.75)
        
        axes = ThreeDAxes()
        labels = axes.get_axis_labels()
        
        plane = RTPlane()
        
        ray_start = [-1, 1, 0.5]
        ray = Ray3D(ray_start, ORIGIN - ray_start, 1, color=RED)
        
        hit_points = plane.get_intersection(ray)
        
        unit_normal_n1 = Ray3D(hit_points[0], ray.get_unit_normal(0), color=GREEN)
        
        angle_n1 = Arc3D(ray, unit_normal_n1)
        angle_n1_text = MathTex("\\theta_1").next_to(angle_n1.get_center() + 0.1 * UP, OUT)
        
        unit_normal_n2 = Ray3D(hit_points[0], [0, 0, -1], color=ORANGE)
        
        refracted_ray = ray.get_refracted_ray(plane, color=BLUE)
        
        angle_n2 = Arc3D(refracted_ray, unit_normal_n2)
        angle_n2_text = MathTex("\\theta_2").next_to(angle_n2.get_center() + 0.2 * DOWN, IN)
        
        n1_text = MathTex("n_1 = 1").next_to(unit_normal_n1.get_end() + 0.375 * OUT + 0.05 * DOWN, DOWN)
        n2_text = MathTex("n_2 = 1.33").next_to(unit_normal_n2.get_end() + 0.375 * IN + 0.25 * DOWN, DOWN)
        
        self.add(plane, ray, refracted_ray, unit_normal_n1, unit_normal_n2, angle_n1, angle_n2)
        
        self.add_fixed_orientation_mobjects(angle_n1_text, angle_n2_text, n1_text, n2_text)

Test Footage Progress

I'm planning to create some brief test footage (possibly 30 seconds long) that will go over just the basic ray-tracing algorithm from the script on Ray-Object Intersections.

I'm currently making the scene, but I ran into an issue where I wasn't able to get the ray to start at the right point.

The main issue I encountered was that the RTCamera is not rotating about its projection point, causing any rays drawn with that camera to start from the wrong point whenever the camera is rotated.

You can see the issue visualized here:

BasicRayTracingAlgorithm_ManimCE_v0 18 0

Fortunately, this was a quick fix. I made the ray's start point reliant on the projection point mobject's location rather than the projection point coordinates that initially get passed in to create the RTCamera. This way, the ray's start point can change whenever the camera gets transformed in some way.

Below is my progress so far. I would like to animate parts of this so that I can create some brief test footage and get a feel for what the process would be like for creating an animation with ManimRT.

BasicRayTracingAlgorithm_ManimCE_v0 18 0

Questions

  1. When it comes to writing the bulk of the interim/final report, should I introduce the ray-tracing concepts as I go along? For example, should I explain the equation of a ray and its components (point + direction) then cite the appropriate reference (like Glassner's book)?
  2. A broad question -- how to recognize what questions I should be asking myself and what questions I should be asking someone more knowledgable?

What's Next

To-Do List

From highest to lowest priority:

  • Create some narrated test footage for demonstrating the basic ray-tracing algorithm
  • Develop full animation video for illustrating ray-object intersections
  • Check TODO comments in code and potentially make changes based on those
  • Start on interim report/presentation
  • Add docstrings to created classes and their methods
  • Add option to initialize camera grid with x value and aspect ratio
  • Generate spheres that intersect the ray at different points (2 intersection points + 1 intersection + no intersection)
⚠️ **GitHub.com Fallback** ⚠️