Vector equations for the standard ray tracing diagram for geometric optics and rendering

This note concerns my take on the derivation of the vector equations for a standard ray tracing diagram ubiquitous in geometric optics and computer graphics. The diagram is appropriate for a ray incident on a point on a locally flat interface between two material regions. For non-normal incidence, the vectors of interest lie in the incident plane formed by the ray and the surface normal at the point of incidence. The vector equations are well-known, but we include them as a necessary mathematical tool and starting point for further computational tools and results.

The standard ray tracing diagram is illustrated below.

RayTracingDiagramNew
Ray tracing diagram for geometric optics and rendering

Geometric quantities and material properties are indexed with a subscript indicating the “from” medium having index 1 or the “to” medium having index 2. Definitions for the quantities illustrated in the ray tracing diagram are defined in the table below

\displaystyle \begin{array}{*{20}{l}} {{{\mathbf{s}}_{1}},{{\mathbf{s}}_{2}},} & {\mathsf{Ray\ unit\ vectors,}} \\ {{{\mathbf{a}}_{1}},{{\mathbf{a}}_{2}},} & {\mathsf{Cosine\ vectors,}} \\ {{{\mathbf{b}}_{1}},{{\mathbf{b}}_{2}},} & {\mathsf{Sine\ vectors,}} \\ {{{{\mathbf{\hat{n}}}}_{1}},{{{\mathbf{\hat{n}}}}_{2}},} & {\mathsf{Surface\ normal\ unit\ vectors,}} \\ {{{\theta }_{1}},{{\theta }_{2}},} & {\mathsf{Ray-normal\ angles,}} \\ {{{n}_{1}},{{n}_{2}}} & {\mathsf{Refractive\  indices}\mathsf{.}} \end{array}

Note that the incident and transmitted normal angles must lie between zero and {\pi }/{2}\; radians.  From the ray tracing diagram, the cosine of the incident angle is given as

\displaystyle \cos {{\theta }_{1}}=-{{\mathbf{\hat{n}}}_{1}}\cdot {{\mathbf{s}}_{1}}.

The incident cosine vector can thus be written as

\displaystyle {{\mathbf{a}}_{1}}=-{{\mathbf{\hat{n}}}_{1}}\cos {{\theta }_{1}}={{\mathbf{\hat{n}}}_{1}}\left( {{{\mathbf{s}}_{1}}\cdot {{{\mathbf{\hat{n}}}}_{1}}} \right).

Two vector sums can be inferred directly from the figure

\displaystyle \begin{array}{*{20}{c}} {{{\mathbf{s}}_{1}}+{{\mathbf{s}}_{R}}=2{{\mathbf{b}}_{1}},} & {{{\mathbf{s}}_{1}}={{\mathbf{a}}_{1}}+{{\mathbf{b}}_{1}}} \end{array}.

Solving for {{\mathbf{s}}_{R}} and substituting in the representation of {{\mathbf{a}}_{1}} gives

\displaystyle {{\mathbf{s}}_{R}}=2{{\mathbf{b}}_{1}}-{{\mathbf{s}}_{1}}=2\left( {{{\mathbf{s}}_{1}}-{{\mathbf{a}}_{1}}} \right)-{{\mathbf{s}}_{1}}={{\mathbf{s}}_{1}}-2{{\mathbf{\hat{n}}}_{1}}\left( {{{\mathbf{s}}_{1}}\cdot {{{\mathbf{\hat{n}}}}_{1}}} \right).

It can likewise be shown that

\displaystyle {{\mathbf{s}}_{R}}={{\mathbf{s}}_{1}}-2{{\mathbf{\hat{n}}}_{2}}\left( {{{\mathbf{s}}_{1}}\cdot {{{\mathbf{\hat{n}}}}_{2}}} \right)

and we write

\displaystyle {{\mathbf{s}}_{R}}={{\mathbf{s}}_{1}}-2\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right).

Note that this representation for the reflected ray is invariant under the transformation \mathbf{n}\to -\mathbf{n} and does not depend on which side the of the interface the surface normal vector is taken.

Computation of the transmitted direction requires Snell’s law

\displaystyle {{n}_{1}}\sin {{\theta }_{1}}={{n}_{2}}\sin {{\theta }_{2}}.

Since the incident and transmitted vectors are unit vectors it follows that

\displaystyle \begin{array}{*{20}{c}} {\left| {{{\mathbf{b}}_{1}}} \right|=\sin {{\theta }_{1}},} & {\left| {{{\mathbf{b}}_{2}}} \right|=\sin {{\theta }_{2}}} \end{array}.

The sine vectors for the incident and transmitted rays have different magnitudes but point in the same direction \mathbf{b}

\displaystyle \mathbf{b}=\frac{{{{\mathbf{b}}_{1}}}}{{\left| {{{\mathbf{b}}_{1}}} \right|}}=\frac{{{{\mathbf{b}}_{2}}}}{{\left| {{{\mathbf{b}}_{2}}} \right|}}.

It is therefore possible to write the sine vector for the transmitted direction as

\displaystyle {{\mathbf{b}}_{2}}=\left| {{{\mathbf{b}}_{2}}} \right|\mathbf{b}=\sin {{\theta }_{2}}\frac{{{{\mathbf{b}}_{1}}}}{{\left| {{{\mathbf{b}}_{1}}} \right|}}=\frac{{\sin {{\theta }_{2}}}}{{\sin {{\theta }_{1}}}}{{\mathbf{b}}_{1}}=\frac{{{{n}_{1}}}}{{{{n}_{2}}}}{{\mathbf{b}}_{1}}={{N}_{R}}{{\mathbf{b}}_{1}},

where the parameter {{N}_{R}} is the index ratio.

Total internal reflection, or TIR, occurs when

\displaystyle \sin {{\theta }_{2}}=\frac{{{{n}_{1}}}}{{{{n}_{2}}}}\left| {{{\mathbf{b}}_{1}}} \right|={{N}_{R}}\left| {{{\mathbf{b}}_{1}}} \right|>1.

Based on the ray tracing diagram, it is straightforward to write the vector sum

\displaystyle 2{{\mathbf{b}}_{1}}={{\mathbf{s}}_{1}}+{{\mathbf{s}}_{R}}.

Putting this in the TIR inequality test above gives

\displaystyle {{N}_{R}}\left| {{{\mathbf{s}}_{1}}-\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)} \right|>1.

This requires no computation of trigonometric functions or square roots.  If the index ratio is pre-computed then the TIR test also requires no division operations.

From the ray tracing diagram, the cosine vector  for the incident ray can be written as

\displaystyle {{\mathbf{a}}_{1}}={{\mathbf{s}}_{1}}-{{\mathbf{b}}_{1}}=\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right).

The cosine vector for the transmitted ray points in the same direction as the incident ray but has a different magnitude

 \displaystyle {{\mathbf{a}}_{2}}=\frac{{{{\mathbf{a}}_{2}}}}{{\left| {{{\mathbf{a}}_{2}}} \right|}}\left| {{{\mathbf{a}}_{2}}} \right|=\frac{{{{\mathbf{a}}_{1}}}}{{\left| {{{\mathbf{a}}_{1}}} \right|}}\left| {{{\mathbf{a}}_{2}}} \right|=\frac{{{{\mathbf{a}}_{1}}}}{{\left| {{{\mathbf{a}}_{1}}} \right|}}\cos {{\theta }_{2}}=\frac{{\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)}}{{\left| {\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)} \right|}}\cos {{\theta }_{2}}=\mathbf{\hat{n}}\ \text{sgn} \left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)\cos {{\theta }_{2}}

where \text{sgn}  \left( x \right) is the sign or signum function

\displaystyle \text{sgn} \left( x \right)=\left\{ {\begin{array}{*{20}{c}} {+1,} & {x\ge 0,} \\ {-1,} & {x<0.} \end{array}} \right.

Noting that the incident and transmitted angles must be on the interval \displaystyle \left[ {0,{\pi }/{2}\;} \right] it is possible to write

\displaystyle \cos {{\theta }_{2}}=\sqrt{{1-{{{\sin }}^{2}}{{\theta }_{2}}}}=\sqrt{{1-N_{R}^{2}{{{\sin }}^{2}}{{\theta }_{1}}}}=\sqrt{{1-N_{R}^{2}{{{\left| {{{\mathbf{b}}_{1}}} \right|}}^{2}}}}=\sqrt{{1-N_{R}^{2}{{{\left| {{{\mathbf{s}}_{1}}-\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)} \right|}}^{2}}}}.

Putting this together, the transmitted ray is

\displaystyle {{\mathbf{s}}_{2}}={{\mathbf{a}}_{2}}+{{\mathbf{b}}_{2}}=\mathbf{\hat{n}}\ \text{sgn} \left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)\sqrt{{1-N_{R}^{2}{{{\left| {{{\mathbf{s}}_{1}}-\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)} \right|}}^{2}}}}+{{N}_{R}}\left[ {{{\mathbf{s}}_{1}}-\mathbf{\hat{n}}\left( {{{\mathbf{s}}_{1}}\cdot \mathbf{\hat{n}}} \right)} \right].

It is easy to see that the representation for the transmitted ray is invariant under the transformation \mathbf{n}\to -\mathbf{n} and does not depend on which side the of the interface the surface normal vector is taken.

 

 

 

4 thoughts on “Vector equations for the standard ray tracing diagram for geometric optics and rendering

Leave a comment