# Mathematical Background
---
## Dot Product
$ \begin{align*}a\cdot b &= b\cdot a=\Vert a \Vert \Vert b \Vert\cos \phi =a^Tb=b^Ta\\
\phi &= \cos^{-1}(\frac{a\cdot b}{\Vert a \Vert \Vert b \Vert}) \\
a\cdot(b+c) &=a\cdot b+a\cdot c \\
(ka)\cdot b &=a\cdot(kb)=k(a\cdot b) \\
\end{align*}$
**Application**: Projection of $b$ onto $a$ ([tutorial](https://matthew-brett.github.io/teaching/vector_projection.html))
$\begin{align*}
\Vert proj_{a}b \Vert &= \Vert b \Vert \cos \phi = \frac{a\cdot b}{\Vert a \Vert} \\
proj_{a}b &= \Vert proj_{a}b \Vert \frac{a}{\Vert a \Vert} = \frac{a\cdot b}{\Vert a \Vert^2} a
\end{align*}$
## Cross Product
The magnitude of cross product of two vectors $\mathbf{a\times b}$ corresponds to the area of the parallelogram formed by $\mathbf{a,b}$.
$\text{Area} = \Vert\mathbf{a\times b}\Vert$
---
## Coordinate Frames
Any set of 3 vectors $\in \mathbb{R}^3$ (say ${u,v,w}$) such that:
$\begin{align*}\Vert u\Vert&=\Vert v\Vert=\Vert w\Vert = 1 \\
u\cdot v &= v\cdot w = u\cdot w = 0 \\
w &= u\times v \\
p &= (p\cdot u)u+(p\cdot v)v + (p\cdot w)w
\end{align*}$
Construct a **coordinate frame** (i.e. a basis) **from 1 vector**: 1) normalize $w$, 2) choose any vector $t$ that's not collinear with $w$ to cross-multiply with $w$ to get $u$, 3) Get $v$ as $u\times v$
$\begin{align*} w = \frac{a}{\Vert a \Vert}, \; u=\frac{t\times w}{\Vert t\times w\Vert}, \; v=w\times v
\end{align*}$
Construct a **coordinate frame** (i.e. a basis) **from 2 vectors**:
- Goal: Given a vector $a$ (e.g. ***viewing direction***), construct an ***orthonormal basis***
- Need a 2nd vector $b$ (e.g. ***camera up direction***). Problem: $a,b$ are neither orthogonal nor unit-norm
$\begin{align*} w = \frac{a}{\Vert a \Vert}, \; u=\frac{b\times w}{\Vert b\times w\Vert}, \; v=w\times v
\end{align*}$
## Matrix
**Matrix multiplication** ([wiki](https://en.wikipedia.org/wiki/Matrix_multiplication)): Associative, distributive, but **NOT commutative**
$\begin{align*}A(B+C)=AB+AC; \;\; (A+B)C=AC+BC\end{align*}$
**Identity** & **Transpose**
$\begin{align*}AA^{-1} &=A^{-1}A=I_{n} ;\;\; (AB)^{-1}=B^{-1}A^{-1}\\
I_3 &= \begin{bmatrix}1&0&0\\0&1&0\\1&0&1\end{bmatrix}
\end{align*}$
Dot product as matrix multiplication $a\cdot b=a^Tb=(a_1b_1+a_2b_x+a_3b_3)$
Cross product as matrix mult (***skew-symmetric matrix*** (aka dual matrix)):
$\begin{align*} a\times b = [a]b= \begin{bmatrix}0&-a_3&a_2\\a_3&0&-a_1\\-a_2&a_1&0\end{bmatrix} \begin{bmatrix}b_1\\b_2\\b_3\end{bmatrix}
\end{align*}$
---
## Line and Plane
Checkout this awesome [post on nagwa](https://www.nagwa.com/en/explainers/373101390857/).
![[Pasted image 20221228103323.png]]
Lets first review how we define a line:
$\begin{align*}
\text{General form: } &Ax+By+C=0\\\\
\text{Two-point form: } & A(x-x_0)+B(y-y_0)=0\\
&\text{where } (x_0,y_0), (x,y) \text{ are 2 given points on the line}\\\\
\text{Vector form: } &\mathbf{n}\cdot(\mathbf{r-r_0})=0\;\equiv\; \mathbf{n\cdot r}=\mathbf{n\cdot r_0}\\
&\text{where }\mathbf{n}=\begin{bmatrix}A\\B\end{bmatrix}, \mathbf{r_0}=\begin{bmatrix}x_0\\y_0\end{bmatrix}, \mathbf{r}=\begin{bmatrix}x\\y\end{bmatrix}\\
\end{align*}$
Note that by the property of dot product, the normal vector $\mathbf{n}$ is perpendicular to the line. The geometric intuition of the vector form is that <mark style="background: #FFF3A3A6;">we can define a hyperplane with one point and a normal vector</mark>.
When generalizing to a plane in 3D, $\mathbf{n}$ is perpendicular to the plane:
$\begin{align*}
\text{General form: } &ax+by+cz+d=0\\\\
\text{Two-point form: } & a(x-x_0)+b(y-y_0)+c(z-z_0)=0\\
&\text{where } (x_0,y_0,z_0), (x,y,z) \text{ are 2 given points on the plane}\\\\
\text{Vector form: } &\mathbf{n}\cdot(\mathbf{r-r_0})=0 \;\equiv\; \mathbf{n\cdot r}=\mathbf{n\cdot r_0}\\\
&\text{where }\mathbf{n}=\begin{bmatrix}a\\b\\c\end{bmatrix}, \mathbf{r_0}=\begin{bmatrix}x_0\\y_0\\z_0\end{bmatrix}, \mathbf{r}=\begin{bmatrix}x\\y\\z\end{bmatrix}\\
\end{align*}$
To recap, we've seen 3 ways of describing a line: 1) general form, 2) two-point form, and 3) vector form. Notice that they are all in the form of '$\text{something}=0