2025-06-09 @ 01:25
Gave Scout her first bath ever today.
Gave Scout her first bath ever today.
Worked out a short proof of the quadrilaterial inequality of metric spaces while studying: $$ \boxed{ \abs{d(x, w) - d(w, y)} \leq d(x, z) - d(z, y) } $$
Just goofing off with the canvas element.
Canvas essentially exposes the svg rasterization backend.
It can only draw rectangles (e.g. pixels) and curves in 2d.
I'll build up a 3d library for the Computer Graphics section.
Refraction of light at a material interface depends, among other things, on the normal of the interface. A surface can be represented by an atlas of coordinate patches. The surface normal of a coordinate patch is straightforward to compute with the associated parameterization. This will be used as part of the demonstration that the perterbative paraxial ray equation through an inhomogeneous medium is approximated by a finite number of bumpy refracting layers with uniform refractive index in a background medium.
Suppose you have a real-valued function of two parameters, i.e. a surface $f: \setR^2 \rightarrow \setR$. Monge patch $$ \vec{a}(x, y) = \ux x + \uy y + \uz f(x, y) $$ Coordinate curves $$ \vec{a}(x, y_0) = \ux x + \uy y_0 + \uz f(x, y_0) $$ $$ \vec{a}(x_0, y) = \ux x_0 + \uy y + \uz f(x_0, y) $$ Tangent vectors $$ \pd{\vec{a}}{x} = \pd{}{x} \bb{\ux x + \uy y + \uz f(x, y)} = \ux + \uz \pd{f}{x} $$ $$ \pd{\vec{a}}{y} = \uy + \uz \pd{f}{y} $$ Normal vector $$ \vec{n} = \pd{\vec{a}}{x} \cross \pd{\vec{a}}{y} $$ \begin{equation} \begin{split} \vec{n} &= \bb{\ux + \uz \pd{f}{x}} \cross \bb{\uy + \uz \pd{f}{y}} \\ &= \ux \cross \uy + \ux \cross \uz \pd{f}{y} + \uz \cross \uy \pd{f}{x} + \uz \cross \uz \pd{f}{x} \pd{f}{y} \\ &= \uz - \uy \pd{f}{y} - \ux \pd{f}{x} + \vec{0} \pd{f}{x} \pd{f}{y} \end{split} \end{equation} The coordinate vector of the normal vector w.r.t the standard basis is then $$ \vec{n} = \bb{-\pd{f}{x}, -\pd{f}{y}, 1}^T $$
The speed of light in a material depends on the index of refraction $n(\r)$ as $$ v = \q{c}{n} $$ where $c$ is the speed of light in vacuum. Fermat's Principle is the phenomenological statement that light takes the path of least time when traveling from one point to another. This is formulated as a variational problem $$ \delta S(\r) = 0 $$ $$ \v = \od{\r}{s} $$ $$ \norm{\v} = 1 $$ for length-parameterized paths. The Lagrangian has the form $$ L(s, \r, \v) = n(\r) \norm{\v} $$ where the constraint $\norm{\v} = 1$ is exploited to cleverly incorporate it into the Lagrangian. Apply the Euler-Lagrange equation to the Lagrangian $$ \pd{L}{\r} - \od{}{s} \pd{L}{\v} = 0 $$ $$ \grad n = \od{}{s} \bb{n \od{}{\v} \norm{\v}} $$ $$ \pd{}{\v} \norm{\v} = \uvec{v} = \v = \pd{\r}{s} $$ $$ \boxed{ \od{}{s} \bb{n \od{\vec{r}}{s}} = \grad n } $$
$$ \od{}{s} \bb{n \od{\r}{s}} = \grad n $$ Invoke paraxial approximation $$ \od{}{z} \bb{n \od{\r}{z}} = \grad n $$ Integrate over parameter interval $$ \int_{z_a}^{z_b} \od{}{z} \bb{n \od{\r}{z}} dz = \int_{z_a}^{z_b} \bb{\ux \pd{n}{x} + \uy \pd{n}{y} + \uz \pd{n}{z}} dz $$ $$ n \od{}{z} \bb{\ux z + \uy y + \uz z} \bigg|_{z = z_a}^{z_b} = \ux \pd{}{x} \int_{z_a}^{z_b} n dz + \uy \pd{}{y} \int_{z_a}^{z_b} n dz + \uz n \bigg|_{z = z_a}^{z_b} $$ $$ n \bb{\ux \pd{x}{z} + \uy \pd{y}{z}} = \grad_\perp OPL $$ $n(\r) = n_0 + \Delta n(\r)$ $$ \bb{n_0 + \Delta n} \bb{\ux \pd{x}{z} + \uy \pd{y}{z}} = \grad_\perp \int_{z_a}^{z_b} \bb{n_0 + \Delta n} dz $$ $$ \bb{n_0 + \Delta n} \bb{\ux \pd{x}{z} + \uy \pd{y}{z}} = \grad_\perp \int_{z_a}^{z_b} \Delta n dz $$ $$ \bb{n_0 + \Delta n} \bb{\ux \pd{x}{z} + \uy \pd{y}{z}} = \grad_\perp \Delta OPL $$ when the perturbation is small $n_0 \gg \Delta n$, then this is approximated by $$ n_0 \bb{\ux \pd{x}{z} + \uy \pd{y}{z}} \approx \grad_\perp \Delta OPL $$ when the background medium has a refractive index close to unity, this simplifies further $$ \ux \pd{x}{z} + \uy \pd{y}{z} \approx \grad_\perp \Delta OPL $$
The refraction model is formulated as a optimization problem that, given a refractive index distribution, seeks the path between a starting and ending point that minimizes the amount of time it takes a light ray to travel. This is a problem in the calculus of variation. Formulating and solving the optimization problem in general terms results in the the Euler-Lagrange equation.
Consider a functional $S$ that maps a position function $\r(t)$ to some real number $$ S(\r) \equiv \int_{t_a}^{t_b} L(t, \r(t), \v(t)) dt $$ where $\v = d\r / dt$. Although $\r$ and $\v$ are functions of $t$, they are treated as independent variables in this analysis. Suppose one seeks a path $\r(t)$ from $\r(t_a) = \r_a$ to $\r(t_b) = \r_b$ that optimizes $S$. How can this be done? Consider an arbitrary path $\r'(t)$ from $\r_a$ to $\r_b$. Decompose $\r'$ in terms of an (unknown) optimal path $\r$ and a displacement vector $\vec{d}(t)$ scaled by some scalar $\alpha \in \setR$ $$ \r'(t, \alpha) = \r(t) + \vec{d}(t) \alpha $$ where $\vec{d}(t_a) = \vec{d}(t_b) = \vec{0}$ to ensure that the paths' endpoints coincide. The functional can be evaluated for this arbitrary path $$ S(\r'(\alpha)) = \int_{t_a}^{t_b} L(t, \r', \v') dt . $$ TODO: Develop this as a power expansion w.r.t. $\alpha$ with higher order terms!! To optimize $S$, take the derivative w.r.t. $\alpha$ and set it to zero \begin{equation} \begin{split} \od{}{\alpha} S(\r'(\alpha)) &= \od{}{\alpha} \int_{t_a}^{t_b} L(t, \r', \v') dt \\ &= \int_{t_a}^{t_b} \pd{}{\alpha} L(t, \r', \v') dt \\ &= \int_{t_a}^{t_b} \bb{\pd{L'}{t} \pd{t}{\alpha} + \pd{L'}{\r'} \dot \pd{\r'}{\alpha} + \pd{L'}{\v'} \dot \pd{\v'}{\alpha}} dt \\ &= \int_{t_a}^{t_b} \bb{\pd{L'}{\r'} \dot \vec{d} + \pd{L'}{\v'} \dot \od{\vec{d}}{t}} dt \\ &= \int_{t_a}^{t_b} \bb{\pd{L'}{\r'} \dot \vec{d} - \bb{\od{}{t} \pd{L'}{\v'}} \dot \vec{d} + \od{}{t} \bb{\pd{L'}{\v'} \dot \vec{d}}} dt \\ &= \int_{t_a}^{t_b} \bb{\pd{L'}{\r'} - \od{}{t} \pd{L'}{\v'}} \dot \vec{d} dt + \pd{L'}{\v'} \dot \vec{d} \bigg|_{t=t_a}^{t_b} \\ &= \int_{t_a}^{t_b} \bb{\pd{L'}{\r'} - \od{}{t} \pd{L'}{\v'}} \dot \vec{d} dt \\ &= 0 \end{split} \end{equation} where $L' = L(t, \r', \v')$. The path is optimized when $\alpha = 0$ by construction of the decomposition, so $\r'(t, 0) = \r(t)$, $\v'(t, 0) = \v(t)$, and $L(t, \r'(t, 0), \v'(t, 0)) = L(t, \r, \v)$ $$ \od{}{\alpha} S(\r'(\alpha)) \bigg|_{\alpha = 0} = \int_{t_a}^{t_b} \bb{\pd{L}{\r} - \od{}{t} \pd{L}{\v}} \dot \vec{d} dt = 0 $$ This integral equation applies to all valid choices of $\vec{d}(t)$, so it must be the case that the bracketed term is exactly zero. $$ \boxed{ \pd{L}{\r} - \od{}{t} \pd{L}{\v} = 0 } . $$ This differential equation represents a constraint on optimal paths, and can be solved to yield an optimal path. It is called the Euler-Lagrange equation (for 1 path). This needs to introduce the variation notation, where $\delta S = 0$.
Can I insert $\int_a^b f(x) dx$ into blogs? Ok!
I've been meaning to work on my website for ages, but keep fretting over some website formating updates. Well, I can worry about that later, I am going to start typing up some notes of random subjects that have been piling up. I'll start with modeling atmospheric seeing using ray tracing, as I derived a lot of mysterious diffraction integrals that are widely applicable to electromagnetic theory.
Green's second identity Start with the divergence theorem $$ \int_V \div \vec{F} dV = \oint_S \vec{F} \dot d\vec{S} $$ where $d\vec{S} = \un dS$. Apply the divergence theorem to a vector-valued function $\vec{F}_1$ constructed from scalar functions $u(\r) : \setR^3 \rightarrow \setR$ and $v(\r) : \setR^3 \rightarrow \setR$ as $$ \vec{F}_1 = u \grad v \Rightarrow \int_V \bb{\grad u \dot \grad v + u \grad^2 v} dV = \oint_S u \pd{v}{n} dS $$ where $\de v / \de n = \grad v \dot \un$. Next, apply the divergence theorem to the vector-valued function $\vec{F}_2$ with the special form $$ \vec{F}_2 = v \grad u \Rightarrow \int_V \bb{\grad v \dot \grad u + v \grad^2 u} dV = \oint_S v \pd{u}{n} dS $$ subtracting these equations we get Green's second identity $$ \boxed{ \int_V \bb{u \grad^2 v - v \grad^2 u} dV = \oint_S \bb{u \pd{v}{n} - v \pd{u}{n}} dS } $$
Let $u$ and $v$ satisfy Helmholtz equations with the same wavenumber $k$, so $$ \grad^2 u + k^2 u = 0 $$ and $$ \grad^2 v + k^2 v = 0 $$ insert these into Green's second identity $$ \int_V \bb{u \bb{-k^2 v} - v \bb{-k^2 u}} dV = \oint_S \bb{u \pd{v}{n} - v \pd{u}{n}} dS $$ $$ \oint_S \bb{u \pd{v}{n} - v \pd{u}{n}} dS = 0 $$
Apply to a spherical wave $$ v = \q{e^{i k r}}{4 \pi r} $$ $$ \grad^2 v + k^2 v =0 $$ $$ \pd{v}{n} = \pd{}{r} \bb{\q{e^{i k r}}{4 \pi r}} = \bb{i k - \q{1}{r}} \q{e^{i k r}}{4 \pi r} $$ $$ \oint_S \bb{u \pd{v}{n} - v \pd{u}{n}} dS = 0 $$ $$ \oint_{S'} \bb{u \pd{}{n'} \bb{\q{e^{i k r'}}{4 \pi r'}} - \bb{\q{e^{i k r'}}{4 \pi r'}} \pd{u}{n'}} dS' + \oint_{S''} \bb{u \bb{i k - \q{1}{r''}} \q{e^{i k r''}}{4 \pi r''} - \bb{\q{e^{i k r''}}{4 \pi r''}} \pd{u}{n''}} dS'' = 0 $$ $$ \lim_{a \rightarrow 0} \oint_{S''} \bb{u \bb{i k - \q{1}{r''}} \q{e^{i k r''}}{4 \pi r''} - \bb{\q{e^{i k r''}}{4 \pi r''}} \pd{u}{n''}} dS'' = \lim_{a \rightarrow 0} -\oint_{S''} u \q{e^{i k r''}}{4 \pi r''^2} dS'' = -u(\vec{0}) \q{e^{i k 0}}{4 \pi a^2} 4 \pi a^2 = -u(\vec{0}) $$ $$ u(\vec{0}) = \oint_{S'} \bb{u \pd{}{n'} \bb{\q{e^{i k r'}}{4 \pi r'}} - \bb{\q{e^{i k r'}}{4 \pi r'}} \pd{u}{n'}} dS' $$ $$ \boxed{ u(\r) = \oint_{S'} \bb{u \pd{}{n'} \bb{\q{e^{i k R}}{4 \pi R}} - \bb{\q{e^{i k R}}{4 \pi R}} \pd{u}{n'}} dS' } $$ where $\R \equiv \r - \r'$ and $R = \norm{\R}$
Apply Helmholtz-Kirchoff integral to infinite plane $$ u(\r) = \oint_{S'} \bb{u \pd{}{n'} \bb{\q{e^{i k R}}{4 \pi R}} - \bb{\q{e^{i k R}}{4 \pi R}} \pd{u}{n'}} dS' $$ $$ u(\r) = \int_{S'} \bb{u \pd{}{z'} \bb{\q{e^{i k R}}{4 \pi R}} - \bb{\q{e^{i k R}}{4 \pi R}} \pd{u}{z'}} dS' $$ $$ \pd{}{z'} \bb{\q{e^{i k R}}{4 \pi R}} = \q{1}{4 \pi} \bb{\q{1}{R^3} \bb{z - z'} e^{i k R} - \q{1}{R} e^{i k R} i k \q{1}{R} \bb{z - z'}} = \q{e^{i k R}}{4 \pi R} \bb{\q{1}{R} - i k} \q{z - z'}{R} $$ $$ \pd{}{z'} \bb{\q{e^{i k R}}{4 \pi R}} \approx -i k \q{e^{i k R}}{4 \pi R} \q{z - z'}{R} $$ for $z \gg \q{1}{k}$ and $R \gg \q{1}{k}$. $$ u(\r) \approx \int_{S'} \bb{-i k u \q{e^{i k R}}{4 \pi R} \q{z - z'}{R} - \bb{\q{e^{i k R}}{4 \pi R}} \pd{u}{z'}} dS' $$ $$ u(\r) \approx -\int_{S'} \q{e^{i k R}}{4 \pi R} \bb{i k u \q{z - z'}{R} + \pd{u}{z'}} dS' $$ use the approximation $\de u / \de z' \approx i k u$ (under the assumptions of $z$ and $R$, $u$ is almost a plane wave) $$ \boxed{ u(\r) \approx -i k \int_{S'} u \q{e^{i k R}}{4 \pi R} \bb{\q{z - z'}{R} + 1} dS' } $$ note, the following lemma was used \begin{equation} \begin{split} \pd{}{z'} R^n &= n R^{n - 1} \pd{}{z'} \bb{\bb{x - x'}^2 + \bb{y - y'}^2 + \bb{z - z'}^2}^\q{1}{2} \\ &= n R^{n - 1} \q{1}{2 R} \pd{}{z'} \bb{\bb{x - x'}^2 + \bb{y - y'}^2 + \bb{z - z'}^2} \\ &= -n R^{n - 1} \q{1}{2 R} 2 \bb{z - z'} \\ &= -n R^{n - 2} \bb{z - z'} \end{split} \end{equation}
Decompose Kirchoff approximation into two parts $$ u(\r) = \int_{S'} \bb{u \pd{}{z'} \bb{\q{e^{i k R}}{4 \pi R}} - \bb{\q{e^{i k R}}{4 \pi R}} \pd{u}{z'}} dS' $$ $$ \boxed{ u(\r) = \q{1}{2} \bb{u_{I} + u_{II}} } $$ where $$ u_{I}(\r) \equiv 2 \int_{S'} u \pd{}{z'} \bb{\q{e^{i k R}}{4 \pi R}} dS' $$ and $$ u_{II}(\r) \equiv -2 \int_{S'} \bb{\q{e^{i k R}}{4 \pi R}} \pd{u}{z'} dS' $$ expand the derivatives to get $$ u(\r) \approx -i k \int_{S'} u \q{e^{i k R}}{4 \pi R} \bb{\q{z - z'}{R} + 1} dS' $$ $$ \boxed{ u_{I}(\r) \approx -2 i k \int_{S'} u \q{e^{i k R}}{4 \pi R} \q{z - z'}{R} dS' } $$ $$ \boxed{ u_{II}(\r) \approx -2 i k \int_{S'} u \q{e^{i k R}}{4 \pi R} dS' } $$
\begin{equation} \begin{split} u_{I}(\r) &\approx -2 i k \int_{S'} u \q{e^{i k R}}{4 \pi R} \q{z - z'}{R} dS' \\ &\approx -2 i k \int_{S'} u \q{e^{i k R}}{4 \pi R} dS' \quad\text{for}\quad z' = 0,\quad R \approx 0,\quad z \gg x, y \\ &\approx -2 i k \int_{S'} u \bb{\q{e^{i k \bb{z + \q{1}{2} \q{\bb{x - x'}^2 + \bb{y - y'}^2}{z}}}}{4 \pi \bb{z + \q{1}{2} \q{\bb{x - x'}^2 + \bb{y - y'}^2}{z}}}} dS' \end{split} \end{equation} $$ \boxed{ u(\r) \approx -\q{i k e^{i k z}}{2 \pi z} \int_{S'} u e^{\q{i k}{2 z} \bb{\bb{x - x'}^2 + \bb{y - y'}^2}} dS' } $$ where the following power expansion of $R$ and approximation was used \begin{equation} \begin{split} R &= \bb{\bb{x - x'}^2 + \bb{y - y'}^2 + \bb{z - z'}^2}^\q{1}{2} \\ &= \bb{\bb{x - x'}^2 + \bb{y - y'}^2 + \bb{z}^2}^\q{1}{2} \quad\text{for}\quad z' = 0 \\ &= z \bb{\q{\bb{x - x'}^2 + \bb{y - y'}^2}{z^2} + 1}^\q{1}{2} \\ &= z \bb{1 + \epsilon}^\q{1}{2} \quad\text{where}\quad \epsilon = \q{\bb{x - x'}^2 + \bb{y - y'}^2}{z^2} \\ &\approx z \bb{1 + \q{1}{2} \epsilon} \\ &= z + \q{1}{2} \q{\bb{x - x'}^2 + \bb{y - y}^2}{z} \end{split} \end{equation}
As a sanity check, we can compare these results against those quoted on wikipedia $$ u_{I}(\r) \approx -2 i k \int_{S'} u \q{e^{i k R}}{4 \pi R} \q{z - z'}{R} dS' $$ with $E = u$ and $z' = 0$ becomes $$ E(x, y, z) = \q{1}{i \lambda} \int_{-\infty}^\infty \int_{-\infty}^\infty E(x', y', 0) \q{e^{i k r}}{r} \q{z}{r} dx' dy' $$ which checks out with the Rayleigh Sommerfeld Diffraction Integral page. Also, $$ u(\r) \approx -\q{i k e^{i k z}}{2 \pi z} \int_{S'} u e^{\q{i k}{2 z} \bb{\bb{x - x'}^2 + \bb{y - y'}^2}} dS' $$ with $E = u$, $k = 2 \pi / \lambda$, and $-i = 1 / i$ becomes $$ E(x, y, z) = \q{e^{i k z}}{i \lambda z} \int_{-\infty}^\infty \int_{-\infty}^\infty E(x', y', 0) e^{\q{i k}{2 z} \bb{\bb{x - x'}^2 + \bb{y - y'}^2}} dx' dy' $$ which also matches the wikipedia page on the Fresnel Diffraction Integral.
Of course, I used none of this for the refraction model at the end of the day! But this stuff is still good to have in one's back pocket. I'll transcribe the variational approach I used in another post. I'll also cheat and lightly edit this post at another time.
Roughly imported and formatted equations for several more Study topics. These pages need a lot of work, both in selecting and organizing topics, and adding a significant amount of explanatory text.
I've been adding things to the Study pages recently. A lot of the subjects are under construction, and therefore incomplete, but this will improve over time
This evening I started adding information about Computer Graphics.
I need to adjust the CSS, and decide how best to break up long subjects into smaller pieces.
Updated website.