Skip to content
Jungkwuen An edited this page Aug 31, 2022 · 22 revisions

Welcome to the OTO wiki!

Code architecture:

  1. init rays
  2. init objects
  3. run ray-tracing
  4. display objects
  5. display ray paths

Pseudo-code for Ray-tracing

class Rays

  Properties (geometric):
    position [x,y,z]
    direction [dx,dy,dz]
    OPL [#]
    generation [0,1,2,3...]
    traced [true/false]
    next_position [x,y,z]
    *next_ray [*Rays]

  Properties (optical):
    wavelength [nm]
    power [W]

  Properties (graphical):
    linecolor [RRGGBB]
    linewidth [#]
    linetype [solid, dashed, dotted]
    alpha [100%]
    visible [true/false]

  Methods:

function ray_tracing()

  for each #ray in #ray_bundle
    [#reflect_ray,#refract_ray,#terminated] = find_next_ray(#ray)
    unless (#terminated)
      #ray_bundle.add_rays(#reflect_ray)
      #ray_bundle.add_rays(#refract_ray)
    end
  end

function find_next_ray(#ray)

  #terminated = true
  for each #optics in #optics_list
    for each #surface in #optics
      [#distance, #missed] = hit_test(#ray, #surface)
      unless (#missed)
        #candidate.add([#surface, #distance])
        #terminated = false
      end
    end
  end
  #closest_surface = find_shortest(#candidate)
  unless (#terminated)
    #reflect_ray = do_reflect(#ray, #closest_surface)
    #refract_ray = do_refract(#ray, #closest_surface)
  end
  return [#reflect_ray ,#reflect_ray, #terminated]

     [#normal_vector] = get_normal(#hit_position, #surface)
     #reflect_ray = refract(#ray, #normal_vector)

whitepapers for the basic knowledge on geometry and optics.