Reflection from a spherical mirror

A spherical mirror intersects the optical axis at $(x=0,y=0)$. The mirror has a radius $R$ centered at $C$. For $R>0$ the interface is convex and for $R<0$ the interface is concave. Light rays leave an object $o$ on the left of the interface and are reflected at the interface at point $P$. to approximate a flat mirror.

Light Source

$x_o = $ [cm]
$y_o = $ [cm]
$\phi = $ [deg]

 

Mirror

$R = $ [cm]
Your browser does not support the canvas element.

The condition that a light ray starting at position $\vec{r}_o$ and travelling in the direction given by the unit vector $\hat{n}$ intersects a sphere of radius $R$ that is centered at position $\vec{C}$ is,

$$R=|\vec{r}_o + d\hat{n} - \vec{C}|.$$

Here $d$ is the length of the vector that starts at $\vec{r}_o$ and ends at $\vec{r}_o + d\hat{n}$. Squaring both sides yields,

$$R^2 = (\vec{r}_o + d\hat{n} - \vec{C})\cdot (\vec{r}_o + d\hat{n} - \vec{C}).$$

Calculating the inner product, we have,

$$d^2\hat{n}\cdot\hat{n} + 2d\hat{n}\cdot (\vec{r}_o - \vec{C}) + (\vec{r}_o - \vec{C})\cdot (\vec{r}_o - \vec{C}) -R^2 =0.$$

This can be solved for $d$ using the quadratic equation,

$$ d = -\hat{n}\cdot (\vec{r}_o - \vec{C}) \pm \sqrt{|\hat{n}\cdot (\vec{r}_o - \vec{C})|^2 - |(\vec{r}_o - \vec{C})|^2 -R^2 }.$$

The function that performs this calculation is,

function intersect_line_sphere(ro,n,R,C) { //find the intersection of a line and a sphere
  // ro is the initial point on the line, n is the unit vector in the direction of the line
  // R is the radius of the sphere, C is the center point of the sphere
  let b = dot(n,vsub(ro,C));
  let q  = dot(vsub(ro,C),vsub(ro,C)) - R*R;
  let Delta = b*b - q;
  if (Delta > 0) {
    let d1 = -b + Math.sqrt(Delta);
    let d2 = -b - Math.sqrt(Delta); 
    return [d1,d2];
  }
  else {
    return null;
  }
}

The form below will calculate the intercepts of a line and a sphere.

Line:
$\vec{r}_o$ = $\hat{x}$ + $\hat{y}$ + $\hat{z}$
$\hat{n}$ = $\hat{x}$ + $\hat{y}$ + $\hat{z}$

Sphere:
$R$ =
$\vec{C}$ = $\hat{x}$ + $\hat{y}$ + $\hat{z}$




Question