Spherical Harmonics: Difference between revisions

From David's Wiki
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
Spherical Harmonics are a set of orthonormal basis functions
Spherical Harmonics are a set of orthonormal basis functions defined over a sphere.<br>
<math>f: (\phi, \theta) \mapsto f(\phi, \theta) \in \mathbb{R}</math>


==Background==
==Background==
===Harmonic Function===
===Harmonic Function===
[https://en.wikipedia.org/wiki/Harmonic_function Wikipedia Reference]<br>
{{main | Wikipedia: Harmonic_function}}
A function <math>f: \mathbb{R}^n \rightarrow \mathbb{R}</math> is a harmonic function if it satisfies Laplace's equation:
A function <math>f: \mathbb{R}^n \rightarrow \mathbb{R}</math> is a harmonic function if it satisfies Laplace's equation:
* The Laplacian (or trace of the hessian) is zero.
* The Laplacian (or trace of the hessian) is zero.
* <math>\Delta f = \frac{\partial^2f}{\partial x_1^2} + \frac{\partial^2f}{\partial x_2^2} + \cdots + \frac{\partial^2f}{\partial x_n^2} = 0</math>
* <math>\Delta f = \frac{\partial^2f}{\partial x_1^2} + \frac{\partial^2f}{\partial x_2^2} + \cdots + \frac{\partial^2f}{\partial x_n^2} = 0</math>
===Associated Legendre Polynomials===
{{main | Wikipedia:Associated Legendre polynomials}}
Associated Legendre Polynomials are a set of orthogonal polynomials defined over \([-1, 1]\). 
Each is represented as \(P^m_l\) where \(0 \leq m \leq l\). 
I.e. 
\(P^0_0(x)\) 
\(P^0_1(x), P^1_1(x)\) 
\(P^0_2(x), P^1_2(x), P^2_2(x)\) 
The following 3 recurrance relations define the associated legendre polynomials:
# <math>(l-m)P_l^m = x(2l-1)P_{l-1}^m - (l+1-1) P_{l-2}^m</math>
# <math>P_m^m = (-1)^m(2m-1)!! (1-x^2)^{m/2}</math>
# <math>P^m_{m+1} = x(2m+1)P^m_m</math>
Notes:
* Here <math>
(x)!! =
\begin{cases}
(x)*(x-2)*...*(1) & x\text{ odd}\\
(x)*(x-2)*...*(2) & x\text{ even}
\end{cases}
</math>


==Definition==
==Definition==
Spherical Harmonics are a set of orthonormal basis functions defined on the sphere.<br>
Spherical Harmonics are a set of orthonormal basis functions defined on the sphere.
Below are some explicit formulas for Laplace spherical harmonics stolen from <ref name="stupidsh">Peter-Pike Sloan, [http://www.ppsloan.org/publications/StupidSH36.pdf Stupid Spherical Harmonics (SH) Tricks]</ref><br>
Below are some explicit formulas for Laplace spherical harmonics stolen from Sloan<ref name="stupidsh">Peter-Pike Sloan, [http://www.ppsloan.org/publications/StupidSH36.pdf Stupid Spherical Harmonics (SH) Tricks]</ref>. You can also find alternative equations in DLMF<ref name="dlmf">Digital Library of Mathematical Functions, 14.30. [https://dlmf.nist.gov/14.30 https://dlmf.nist.gov/14.30]</ref>.
There are <math>2l+1</math> functions for each band.<br>
 
There are <math>2l+1</math> functions for each band.


* <math>Y_l^m(\theta, \varphi) = K_l^m e^{i m \varphi} P_l^{|m|} \cos(\theta)</math> for <math>-l \leq m \leq l</math>
* <math>Y_l^m(\theta, \varphi) = K_l^m e^{i m \varphi} P_l^{|m|} \cos(\theta)</math> for <math>-l \leq m \leq l</math>
Line 30: Line 55:
\end{cases}</math>
\end{cases}</math>


===Visualizations===
==Properties==
Copied from Green<ref name="green2003lighting">Robin Green (2003). ''Spherical Harmonic Lighting'' URL: [http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf]</ref>
 
* Orthonormal
* Rotationally Invariant
* Integration of two spherical harmonic functions is a dot product of their coefficients
{{hidden | Proof|
This follows from being orthonormal:<br>
<math>
\begin{align}
\int_{S}\tilde{L}(s)\tilde{t}(s)ds &= \int_{S}\left(\sum_i L_i y_i(s)\right)\left(\sum_j t_j y_j(s)\right)ds \\
&= \sum_i\sum_j L_i t_j \int_{S} y_i(s) y_j(s)ds \\
&= \sum_i^{n^2} L_i t_i \int_{S}( y_i(s) y_i(s))ds\\
&\qquad\text{ because orthogonal}\\
&= \sum_i^{n^2} L_i t_i\\
&\qquad\text{ because orthonormal}
\end{align}
</math>
}}
 
==Operations==
===Addition===
Just add the coefficients
 
===Multiplication===
 
===Rotation===
 
==Visualizations==
Below are distorted sphere visualizations where the radius corresponds to the value at each point.
Below are distorted sphere visualizations where the radius corresponds to the value at each point.
* [https://www.shadertoy.com/view/lsfXWH iq's 0-3]
* [https://www.shadertoy.com/view/lsfXWH iq's 0-3]
Line 36: Line 89:


==Applications==
==Applications==
===Lighting===
See Green<ref name="green2003lighting></ref>.
===Saliency===
===Saliency===
* [http://duruofei.com/Research/SphericalHarmonics Ruofei's Website]
* [http://duruofei.com/Research/SphericalHarmonics Ruofei's Website]
Line 41: Line 97:


==Resources==
==Resources==
* [http://www.ppsloan.org/publications/StupidSH36.pdf Stupid SH]
* [http://www.ppsloan.org/publications/StupidSH36.pdf Stupid SH by Peter-Pike Sloan]
* [https://en.wikipedia.org/wiki/Spherical_harmonics Wikipedia page]
* [http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf Spherical Harmonics Lighting by Robin Green]
* [[Wikipedia:Spherical Harmonics]]


==References==
==References==
<references />
<references />

Latest revision as of 17:02, 10 June 2022

Spherical Harmonics are a set of orthonormal basis functions defined over a sphere.
\(\displaystyle f: (\phi, \theta) \mapsto f(\phi, \theta) \in \mathbb{R}\)

Background

Harmonic Function

A function \(\displaystyle f: \mathbb{R}^n \rightarrow \mathbb{R}\) is a harmonic function if it satisfies Laplace's equation:

  • The Laplacian (or trace of the hessian) is zero.
  • \(\displaystyle \Delta f = \frac{\partial^2f}{\partial x_1^2} + \frac{\partial^2f}{\partial x_2^2} + \cdots + \frac{\partial^2f}{\partial x_n^2} = 0\)

Associated Legendre Polynomials

Associated Legendre Polynomials are a set of orthogonal polynomials defined over \([-1, 1]\).
Each is represented as \(P^m_l\) where \(0 \leq m \leq l\).
I.e.
\(P^0_0(x)\)
\(P^0_1(x), P^1_1(x)\)
\(P^0_2(x), P^1_2(x), P^2_2(x)\)

The following 3 recurrance relations define the associated legendre polynomials:

  1. \(\displaystyle (l-m)P_l^m = x(2l-1)P_{l-1}^m - (l+1-1) P_{l-2}^m\)
  2. \(\displaystyle P_m^m = (-1)^m(2m-1)!! (1-x^2)^{m/2}\)
  3. \(\displaystyle P^m_{m+1} = x(2m+1)P^m_m\)

Notes:

  • Here \(\displaystyle (x)!! = \begin{cases} (x)*(x-2)*...*(1) & x\text{ odd}\\ (x)*(x-2)*...*(2) & x\text{ even} \end{cases} \)

Definition

Spherical Harmonics are a set of orthonormal basis functions defined on the sphere.
Below are some explicit formulas for Laplace spherical harmonics stolen from Sloan[1]. You can also find alternative equations in DLMF[2].

There are \(\displaystyle 2l+1\) functions for each band.

  • \(\displaystyle Y_l^m(\theta, \varphi) = K_l^m e^{i m \varphi} P_l^{|m|} \cos(\theta)\) for \(\displaystyle -l \leq m \leq l\)
where \(\displaystyle P_l^m\) are the associated Legendre Polynomials
and \(\displaystyle K_l^m = \sqrt{\frac{(2l+1)(l-|m|)!}{4 \pi (l+|m|)!}}\)
l is the band, m is the function

For a real valued basis,

  • \(\displaystyle y_l^m = \begin{cases} \sqrt{2}\operatorname{Re}(Y_l^m) & m \gt 0\\ \sqrt{2}\operatorname{Im}(Y_l^m) & m \lt 0\\ Y_l^0 & m = 0 \end{cases} = \begin{cases} \sqrt{2} K_l^m \cos(m \varphi) P_l^m(\cos\theta) & m \gt 0\\ \sqrt{2} K_l^m \sin(|m| \varphi) P_l^{|m|}(\cos\theta) & m \lt 0\\ K_l^0 P_l^0 (\cos \theta) & m = 0\\ \end{cases}\)

Properties

Copied from Green[3]

  • Orthonormal
  • Rotationally Invariant
  • Integration of two spherical harmonic functions is a dot product of their coefficients
Proof

This follows from being orthonormal:
\(\displaystyle \begin{align} \int_{S}\tilde{L}(s)\tilde{t}(s)ds &= \int_{S}\left(\sum_i L_i y_i(s)\right)\left(\sum_j t_j y_j(s)\right)ds \\ &= \sum_i\sum_j L_i t_j \int_{S} y_i(s) y_j(s)ds \\ &= \sum_i^{n^2} L_i t_i \int_{S}( y_i(s) y_i(s))ds\\ &\qquad\text{ because orthogonal}\\ &= \sum_i^{n^2} L_i t_i\\ &\qquad\text{ because orthonormal} \end{align} \)

Operations

Addition

Just add the coefficients

Multiplication

Rotation

Visualizations

Below are distorted sphere visualizations where the radius corresponds to the value at each point.

Applications

Lighting

See Green[3].

Saliency

Ruofei did a project on Saliency using Spherical Harmonics as part of his PhD dissertation.

Resources

References

  1. Peter-Pike Sloan, Stupid Spherical Harmonics (SH) Tricks
  2. Digital Library of Mathematical Functions, 14.30. https://dlmf.nist.gov/14.30
  3. 3.0 3.1 Robin Green (2003). Spherical Harmonic Lighting URL: http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf