Headlight Ray Tracer

This is some output from my ray tracer that simulates headlight patterns. At present, reflector design is hardcoded. The initial goal of this project has been to model the effects of modifying a simple parabolic reflector with a flat mirror placed inside the parabolic reflector to provide some cutoff of light to prevent glare for oncoming traffic. Red tick marks in images are 10 degree increments. For each pixel in the image, the open end of the light head is sampled over 200 times at more or less evenly spaced points, to measure the total output of the light that falls on that pixel. The light is measured at a distance of 10 meters from the headlight (this is not to take into account atmospheric fading, but because the shape of the beam will change with distance, especially very close to the light).

The output is by default auto-white balanced, but it can be tweaked by hand. The next two images are set at what is essentially the same exposure, so the brightness can be compared between the two images.

Here is the C source code that produced this output. Requires X11. Compile with "-lX11 -lm"

Command-line options:
-m bool - do we have a flat mirror added to our parabola?
-j bool - do we jitter our ray tracing (or stay in a fixed grid)?
-i bool - accept interactive commands after tracing?
-w int - image width
-h int - image height
-vd int - viewing distance
-mr int - maxreflect - maximum recursion level?
-rd float - reflector depth from led center to widest
-rr float - reflector radius at widest
-ro float - reflector offset from led center to base of parabola
-ms float - slope of flat mirror
-mi float - y-intercept of flat mirror (height at led position)
-debug bool - provide debugging output?
-rescale float - white balance (BROKEN?)
-f filename - output file (GIF image)

Interactive commands
mirror 0/1 - turn mirror off/on
pixel float float - get value for pixel at x,y
rescale - show rescale value
rescale float - show image with different rescale value (BROKEN?)
float,float float,float - trace a single ray, values are viewing x,y and target x,y


This is a simulation of a plain parabolic reflector headlight. Radius is 12.5 mm, depth from center of LED to widest part of parabolic surface is 13mm. Base of the parabolic surface is offset 2mm behind the center of the LED. LED is modelled as a 2.1mm radius sphere.


This is a simulation of the same headlight, with a horizontal mirror placed 2.5 mm above center, facing downward.


This is a simulation of the same headlight, with a horizontal mirror placed 4.5 mm above center, facing downward.


This is a simulation of the same headlight, with two horizontal mirrors placed 2.5 mm above and below center, facing inward. The mirrors effectively ruin the cutoff that the other mirror would provide, and also get rid of almost all of the parabolic part of the mirror.


This table shows different configuratins for the mirror. The columns labelled "y=" show different mirror heights (measured from the LED center). The rows with "m=" represent different slopes for the mirror, with negative numbers getting lower towards the face of the light.

  y=2.5 y=3.5 y=4.5 y=5.5
m=-0.2
m=-0.1
m=0
m=+0.1
m=+0.2


My Home Professional Home TomSaraZac Home
Email Work Email