fennec
Loading...
Searching...
No Matches
geometric.h File Reference

Geometric More...

Go to the source code of this file.

Detailed Description

Author
Medusa Slockbower

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.
 

Function Documentation

◆ dot()

template<typename genType , size_t... i>
constexpr genType fennec::dot ( const vector< genType, i... > &  x,
const vector< genType, i... > &  y 
)
constexpr
Returns
the dot product of \(x\) and \(y\), i.e., \(x_0 \cdot y_0 + x_0 \cdot y_0 + \ldots\)

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\)

Parameters
xfirst vector
ysecond vector

◆ length2()

template<typename genType , size_t... i>
constexpr genType fennec::length2 ( const vector< genType, i... > &  x)
constexpr
Returns
the squared length of vector \(x\), i.e., \(x_0^2 + x_1^2 + \ldots\)

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\)

Parameters
xthe vector

◆ length()

template<typename genType , size_t... i>
constexpr genType fennec::length ( const vector< genType, i... > &  x)
constexpr
Returns
the length of vector \(x\), i.e., \(\sqrt{x_0^2 + x_1^2 + \ldots}\)

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|\)

Parameters
xthe vector

◆ distance()

template<typename genType , size_t... i>
constexpr genType fennec::distance ( const vector< genType, i... > &  p0,
const vector< genType, i... > &  p1 
)
constexpr
Returns
the distance between \(p_0\) and \(p_1\), i.e., \(\left|{p_1-p_0}\right|\)

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|\)

Parameters
p0first vector
p1second vector

◆ cross()

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 
)
constexpr
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)\)

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\)

Parameters
xfirst vector
ysecond vector

◆ normalize()

template<typename genType , size_t... i>
constexpr vector< genType, i... > fennec::normalize ( const vector< genType, i... > &  x)
constexpr
Returns
a vector in the same direction as \(x\), but with a length of \(1\), i.e. \(\frac{x}{||x||}\)

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|}\)

Parameters
x

◆ faceforward()

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 
)
constexpr
Returns
\(N\) if \(\text{dot}(Nref,I)<0\), otherwise, returns \(-N\).

Parameters
Nthe vector
Ithe incident
Nrefthe reference

◆ reflect()

template<typename genType , size_t... i>
constexpr vector< genType, i... > fennec::reflect ( const vector< genType, i... > &  I,
const vector< genType, i... > &  N 
)
constexpr
Returns
The reflection direction, given the incident vector \(I\) and surface orientation \(N\)

We can express this as,

\(\text{reflect}(I, N) = I - 2 N \cdot \text{dot}(N, I)\)

Parameters
Ithe incident
Nthe surface orientation

◆ refract()

template<typename genType , size_t... i>
constexpr vector< genType, i... > fennec::refract ( const vector< genType, i... > &  I,
const vector< genType, i... > &  N,
genType  eta 
)
constexpr
Returns
The refraction vector, given the incident vector \(I\), surface normal \(N\), and ratio \(eta\).

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}\)

Parameters
Ithe incident
Nthe surface normal
etathe ratio of indices of refraction