mantaflow  0.10
A framework for fluid simulation
Classes | Macros | Typedefs | Functions
vectorbase.h File Reference
#include <stdio.h>
#include <string>
#include <limits>
#include <iostream>
#include "general.h"

Go to the source code of this file.

Classes

class  Manta::Vector3D< S >
 Basic inlined vector class. More...
 

Macros

#define _VECTORBASE_H
 
#define VECTOR_EPSILON   (1e-6f)
 
#define FLOATINGPOINT_PRECISION   1
 
#define VECTOR_EPSILON   (1e-6f)
 
#define M_PI   3.1415926536
 
#define M_E   2.7182818284
 

Typedefs

typedef float Real
 
typedef Vector3D< Real > Manta::Vec3
 3D vector class of type Real (typically float)
 
typedef Vector3D< int > Manta::Vec3i
 3D vector class of type int
 

Functions

template<class S >
Vector3D< S > Manta::operator+ (const Vector3D< S > &v1, const Vector3D< S > &v2)
 Addition operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator+ (const Vector3D< S > &v, S2 s)
 Addition operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator+ (S2 s, const Vector3D< S > &v)
 Addition operator.
 
template<class S >
Vector3D< S > Manta::operator- (const Vector3D< S > &v1, const Vector3D< S > &v2)
 Subtraction operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator- (const Vector3D< S > &v, S2 s)
 Subtraction operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator- (S2 s, const Vector3D< S > &v)
 Subtraction operator.
 
template<class S >
Vector3D< S > Manta::operator* (const Vector3D< S > &v1, const Vector3D< S > &v2)
 Multiplication operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator* (const Vector3D< S > &v, S2 s)
 Multiplication operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator* (S2 s, const Vector3D< S > &v)
 Multiplication operator.
 
template<class S >
Vector3D< S > Manta::operator/ (const Vector3D< S > &v1, const Vector3D< S > &v2)
 Division operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator/ (const Vector3D< S > &v, S2 s)
 Division operator.
 
template<class S , class S2 >
Vector3D< S > Manta::operator/ (S2 s, const Vector3D< S > &v)
 Division operator.
 
template<class S >
bool Manta::operator== (const Vector3D< S > &s1, const Vector3D< S > &s2)
 Comparison operator.
 
template<class S >
bool Manta::operator!= (const Vector3D< S > &s1, const Vector3D< S > &s2)
 Comparison operator.
 
template<class S >
Vector3D< S > Manta::vmin (const Vector3D< S > &s1, const Vector3D< S > &s2)
 Min operator.
 
template<class S , class S2 >
Vector3D< S > Manta::vmin (const Vector3D< S > &s1, S2 s2)
 Min operator.
 
template<class S1 , class S >
Vector3D< S > Manta::vmin (S1 s1, const Vector3D< S > &s2)
 Min operator.
 
template<class S >
Vector3D< S > Manta::vmax (const Vector3D< S > &s1, const Vector3D< S > &s2)
 Max operator.
 
template<class S , class S2 >
Vector3D< S > Manta::vmax (const Vector3D< S > &s1, S2 s2)
 Max operator.
 
template<class S1 , class S >
Vector3D< S > Manta::vmax (S1 s1, const Vector3D< S > &s2)
 Max operator.
 
template<class S >
Manta::dot (const Vector3D< S > &t, const Vector3D< S > &v)
 Dot product.
 
template<class S >
Vector3D< S > Manta::cross (const Vector3D< S > &t, const Vector3D< S > &v)
 Cross product.
 
template<class S >
const Vector3D< S > & Manta::projectNormalTo (const Vector3D< S > &v, const Vector3D< S > &n)
 Project a vector into a plane, defined by its normal. More...
 
template<class S >
Manta::norm (const Vector3D< S > &v)
 
template<class S >
Manta::normSquare (const Vector3D< S > &v)
 Compute squared magnitude.
 
Real Manta::norm (const Real v)
 compatibility, allow use of int, Real and Vec inputs with norm/normSquare
 
Real Manta::normSquare (const Real v)
 
Real Manta::norm (const int v)
 
Real Manta::normSquare (const int v)
 
template<class S >
Vector3D< S > Manta::getNormalized (const Vector3D< S > &v)
 Returns a normalized vector.
 
template<class S >
Manta::normalize (Vector3D< S > &v)
 Compute the norm of the vector and normalize it. More...
 
template<class S >
Vector3D< S > Manta::getOrthogonalVector (const Vector3D< S > &v)
 Obtain an orthogonal vector. More...
 
template<class S >
void Manta::vecToAngle (const Vector3D< S > &v, S &phi, S &theta)
 Convert vector to polar coordinates. More...
 
template<class S >
Vector3D< S > Manta::reflectVector (const Vector3D< S > &t, const Vector3D< S > &n)
 Compute vector reflected at a surface. More...
 
template<class S >
Vector3D< S > Manta::refractVector (const Vector3D< S > &t, const Vector3D< S > &normal, S nt, S nair, int &refRefl)
 Compute vector refracted at a surface. More...
 
template<class S >
std::ostream & Manta::operator<< (std::ostream &os, const Vector3D< S > &i)
 Outputs the object in human readable form to stream. More...
 
template<class S >
std::istream & Manta::operator>> (std::istream &is, Vector3D< S > &i)
 Reads the contents of the object from a stream. More...
 
template<class T >
Vec3 Manta::toVec3 (T v)
 convert to Real Vector
 
template<class T >
Vec3i Manta::toVec3i (T v)
 convert to int Vector
 
template<class T >
Vec3i Manta::toVec3i (T v0, T v1, T v2)
 convert to int Vector
 
template<class T >
Vec3i Manta::toVec3iRound (T v)
 round, and convert to int Vector
 
template<class T >
Vec3i Manta::toVec3iChecked (T v)
 convert to int Vector if values are close enough to an int
 
template<class T >
Vector3D< double > Manta::toVec3d (T v)
 convert to double Vector
 
template<class T >
Vector3D< float > Manta::toVec3f (T v)
 convert to float Vector
 
template<>
Vec3 Manta::clamp< Vec3 > (const Vec3 &a, const Vec3 &b, const Vec3 &c)
 
template<>
Vec3 Manta::safeDivide< Vec3 > (const Vec3 &a, const Vec3 &b)
 
template<>
Vec3 Manta::nmod< Vec3 > (const Vec3 &a, const Vec3 &b)
 

Function Documentation

◆ getOrthogonalVector()

template<class S >
Vector3D<S> Manta::getOrthogonalVector ( const Vector3D< S > &  v)

Obtain an orthogonal vector.

Compute a vector that is orthonormal to the given vector. Nothing else can be assumed for the direction of the new vector.

Returns
The orthonormal vector

◆ norm()

template<class S >
S Manta::norm ( const Vector3D< S > &  v)
inline

Compute the magnitude (length) of the vector (clamps to 0 and 1 with VECTOR_EPSILON)

◆ normalize()

template<class S >
S Manta::normalize ( Vector3D< S > &  v)
inline

Compute the norm of the vector and normalize it.

Returns
The value of the norm

◆ operator<<()

template<class S >
std::ostream& Manta::operator<< ( std::ostream &  os,
const Vector3D< S > &  i 
)

Outputs the object in human readable form to stream.

Output format [x,y,z]

◆ operator>>()

template<class S >
std::istream& Manta::operator>> ( std::istream &  is,
Vector3D< S > &  i 
)

Reads the contents of the object from a stream.

Input format [x,y,z]

◆ projectNormalTo()

template<class S >
const Vector3D<S>& Manta::projectNormalTo ( const Vector3D< S > &  v,
const Vector3D< S > &  n 
)
inline

Project a vector into a plane, defined by its normal.

Projects a vector into a plane normal to the given vector, which must have unit length. Self is modified.

Parameters
vThe vector to project
nThe plane normal
Returns
The projected vector

◆ reflectVector()

template<class S >
Vector3D<S> Manta::reflectVector ( const Vector3D< S > &  t,
const Vector3D< S > &  n 
)
inline

Compute vector reflected at a surface.

Compute a vector, that is self (as an incoming vector) reflected at a surface with a distinct normal vector. Note that the normal is reversed, if the scalar product with it is positive.

Parameters
tThe incoming vector
nThe surface normal
Returns
The new reflected vector

◆ refractVector()

template<class S >
Vector3D<S> Manta::refractVector ( const Vector3D< S > &  t,
const Vector3D< S > &  normal,
nt,
nair,
int &  refRefl 
)
inline

Compute vector refracted at a surface.

Parameters
tThe incoming vector
nThe surface normal
ntThe "inside" refraction index
nairThe "outside" refraction index
refReflSet to 1 on total reflection
Returns
The refracted vector

◆ vecToAngle()

template<class S >
void Manta::vecToAngle ( const Vector3D< S > &  v,
S &  phi,
S &  theta 
)
inline

Convert vector to polar coordinates.

Stable vector to angle conversion

Parameters
vvector to convert
phiunique angle [0,2PI]
thetaunique angle [0,PI]