vector fundamental (David Hill slide)
direction
definition | math | case example | |
---|---|---|---|
math | C++ example | ||
defining vector \(\overrightarrow{a}\) | $$ \overrightarrow{a} = (\color{red}{a_x}, \color{green}{a_y}, \color{blue}{a_z}) $$ | $$ \overrightarrow{a} = (\color{red}{0}, \color{green}{1}, \color{blue}{2}) $$ |
FVector A = FVector(0.f, 1.f, 2.f);
|
vector length of \(\overrightarrow{a}\) | $$ ||a|| = \sqrt{\color{red}{a_x}^2 + \color{green}{a_y}^2 + \color{blue}{a_z}^2} $$ | $$ ||a|| = \sqrt{\color{red}{0}^2 + \color{green}{1}^2 + \color{blue}{2}^2} $$ $$ ||a|| = \sqrt 5 $$ |
float ALength;
|
normal / direction of \(\overrightarrow{a}\) | $$ \overrightarrow{n_a} = \frac{\overrightarrow{a}}{||a||} $$ | $$ \overrightarrow{n_a} = \frac{(\color{red}{0} , \color{green}{1} , \color{blue}{2})}{\sqrt 5} $$ $$ \overrightarrow{n_a} = (\color{red}{0} , \color{green}{\frac{1}{\sqrt 5}} , \color{blue}{\frac{2}{\sqrt 5}}) $$ |
FVector ANormal;
|
normal vector will always have 1 vector length |
$$ ||n_a|| = \sqrt{\color{red}{n_x}^2 + \color{green}{n_y}^2 + \color{blue}{n_z}^2} = 1 $$ | $$ ||n_a|| = \sqrt{\color{red}{0}^2 + (\color{green}{\frac{1}{\sqrt 5}})^2 + (\color{blue}{\frac{2}{\sqrt 5}})^2 } $$ $$ ||n_a|| = \sqrt{ \color{red}{0} + \color{green}{\frac{1}{5}} + \color{blue}{\frac{4}{5}} } $$ $$ ||n_a|| = 1 $$ |
ANormal.Size();
// 1.f
|
so vector contains normal and length | $$ \overrightarrow{a} = (\color{red}{n_x}, \color{green}{n_y}, \color{blue}{n_z}) . ||a||$$ |
example:
direction and magnitude
FVector a, n_a;
a = FVector(0.0f, 1.0f, 2.0f);
n_a = a / a.VectorLength();
addition
example:
substraction
example:
reflection vector
Wyeth method
dot product trick
reflection vector: $$ \overrightarrow{v} - 2 (\overrightarrow{v} . \overrightarrow{n}) \overrightarrow{n} $$