|
fennec
|
#include <fennec/math/vector.h>#include <fennec/math/common.h>#include <fennec/math/exponential.h>Go to the source code of this file.
Functions | |
| template<typename genType , size_t... i> | |
| constexpr genType | fennec::dot (const vector< genType, i... > &x, const vector< genType, i... > &y) |
| Returns the dot product of \(x\) and \(y\), i.e., \(x_0 \cdot y_0 + x_1 \cdot y_1 + \ldots\). | |
| template<typename genType , size_t... i> | |
| constexpr genType | fennec::length2 (const vector< genType, i... > &x) |
| Returns the squared length of vector \(x\), i.e., \(x_0^2 + x_1^2 + \ldots\). | |
| template<typename genType , size_t... i> | |
| constexpr genType | fennec::length (const vector< genType, i... > &x) |
| Returns the length of vector \(x\), i.e., \(\sqrt{x_0^2 + x_1^2 + \ldots}\). | |
| template<typename genType , size_t... i> | |
| constexpr genType | fennec::distance (const vector< genType, i... > &p0, const vector< genType, i... > &p1) |
| Returns the length of vector \(x\), i.e., \(\sqrt{x_0^2 + x_1^2 + \ldots}\). | |
| template<typename genType , size_t... i> requires (sizeof...(i) == 3) | |
| constexpr vector< genType, i... > | fennec::cross (const vector< genType, i... > &x, const vector< genType, i... > &y) |
| Returns the cross product of \(x\) and \(y\), i.e., \(\left({x_1 \cdot y_2 - y_1 \cdot x_2, x_2 \cdot y_0 - y_2 \cdot x_0, x_0 \cdot y_1 - y_0 \cdot x_1}\right)\). | |
| template<typename genType , size_t... i> | |
| constexpr vector< genType, i... > | fennec::normalize (const vector< genType, i... > &x) |
| Returns a vector in the same direction as \(x\), but with a length of \(1\), i.e. | |
| template<typename genType , size_t... i> | |
| constexpr vector< genType, i... > | fennec::faceforward (const vector< genType, i... > &N, const vector< genType, i... > &I, const vector< genType, i... > &Nref) |
| If \(\text{dot}(Nref, I)<0\) return \(N\), otherwise return \(-N\). | |
| template<typename genType , size_t... i> | |
| constexpr vector< genType, i... > | fennec::reflect (const vector< genType, i... > &I, const vector< genType, i... > &N) |
| For the incident vector \(I\) and surface orientation \(N\), returns the reflection direction. | |
| template<typename genType , size_t... i> | |
| constexpr vector< genType, i... > | fennec::refract (const vector< genType, i... > &I, const vector< genType, i... > &N, genType eta) |
| For the incident vector \(I\) and surface normal \(N\), and the ratio of indices of refraction \(eta\), return the refraction vector. | |
|
constexpr |
we can represent this in linear algebra as the following,
let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
let \(Y=\left[\begin{array}\\ y_0 \\ y_1 \\ \vdots \\ y_N \end{array}\right]\)
then \(\text{dot}(X, Y)=X \cdot Y^T\)
| x | first vector |
| y | second vector |
|
constexpr |
we can represent this in linear algebra as the following,
let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
then \(\text{length2}(X)=X \cdot X^T\)
| x | the vector |
|
constexpr |
we can represent this in linear algebra as the following,
let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
then, \(\text{length}(X)=\left|\left|X\right|\right|\)
| x | the vector |
|
constexpr |
we can represent this in linear algebra as the following,
let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
let \(Y=\left[\begin{array}\\ y_0 \\ y_1 \\ \vdots \\ y_N \end{array}\right]\)
then \(\text{distance}(X, Y)=\left|\left|Y-X\right|\right|\)
| p0 | first vector |
| p1 | second vector |
|
constexpr |
we can represent this in linear algebra as the following,
let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
let \(Y=\left[\begin{array}\\ y_0 \\ y_1 \\ \vdots \\ y_N \end{array}\right]\)
then \(\text{cross}(X, Y)=X \times Y\)
| x | first vector |
| y | second vector |
|
constexpr |
we can represent this in linear algebra as the following,
let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
then, \(\text{length}(X)=\frac{X}{\left|\left|X\right|\right|}\)
| x |
|
constexpr |
| N | the vector |
| I | the incident |
| Nref | the reference |
|
constexpr |
We can express this as,
\(\text{reflect}(I, N) = I - 2 N \cdot \text{dot}(N, I)\)
| I | the incident |
| N | the surface orientation |
|
constexpr |
The result is computed by the refraction equation,
let \(k=1.0-eta^2 \cdot (1.0 - \text{dot}(N, I)^2)\)
then, \(\text{refract}(I, N, eta)=\begin{cases} 0.0 & k<0.0, \\ eta \cdot I - N \cdot (eta \cdot \text{dot}(N, I) + \sqrt{k}) \end{cases}\)
| I | the incident |
| N | the surface normal |
| eta | the ratio of indices of refraction |