Hermes
vector.h File Reference

Geometric vector classes. More...

Go to the source code of this file.

Classes

class  hermes::Vector2< T >
 Geometric 2-dimensional vector (x, y) More...
 
class  hermes::Vector3< T >
 Geometric 3-dimensional vector (x, y, z) More...
 
class  hermes::Vector4< T >
 Geometric 4-dimensional point (x, y, z, w) More...
 
struct  std::hash< hermes::Vector2< T > >
 Hash support for vector2. More...
 
struct  std::hash< hermes::Vector3< T > >
 Hash support for vector3. More...
 

Macros

#define ARITHMETIC_OP(OP)
 
#define RELATIONAL_OP(OP, CO)
 
#define ARITHMETIC_OP(OP)
 
#define DOP2(OP)   f OP v.x, f OP v.y
 
#define DOP3(OP)   f OP v.x, f OP v.y, f OP v.z
 
#define MATH_OP(D, OP)
 
#define DOP2(OP)   OP(a.x, b.x), OP(a.y, b.y)
 
#define DOP3(OP)   OP(a.x, b.x), OP(a.y, b.y), OP(a.z, b.z)
 
#define MATH_OP(D, NAME, OP)
 
#define DOP2(OP)   OP(v.x), OP(v.y)
 
#define DOP3(OP)   OP(v.x), OP(v.y), OP(v.z)
 
#define MATH_OP(NAME, OP, D)
 

Typedefs

using hermes::vec2 = Vector2< real_t >
 
using hermes::vec3 = Vector3< real_t >
 
using hermes::vec4 = Vector4< real_t >
 
using hermes::vec3d = Vector3< double >
 
using hermes::vec3f = Vector3< float >
 
using hermes::vec2f = Vector2< float >
 
using hermes::vec2i = Vector2< Interval< real_t > >
 
using hermes::vec3i = Vector3< Interval< real_t > >
 

Functions

template<typename T >
HERMES_DEVICE_CALLABLEhermes::dot (const Vector2< T > &a, const Vector2< T > &b)
 Computes the dot product between two vectors. More...
 
template<typename T >
HERMES_DEVICE_CALLABLEhermes::dot (const Vector3< T > &a, const Vector3< T > &b)
 Computes the dot product between two vectors. More...
 
template<typename T >
HERMES_DEVICE_CALLABLEhermes::cross (const Vector2< T > &a, const Vector2< T > &b)
 Computes the cross product between two vectors. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector3< T > hermes::cross (const Vector3< T > &a, const Vector3< T > &b)
 Computes the cross product between two vectors. More...
 
template<typename T >
HERMES_DEVICE_CALLABLEhermes::triple (const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
 Computes the triple product between 3 vectors. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector2< T > hermes::normalize (const Vector2< T > &v)
 Computes normalized copy from vector. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector3< T > hermes::normalize (const Vector3< T > &v)
 Computes normalized copy from vector. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector2< T > hermes::orthonormal (const Vector2< T > &v, bool first=true)
 Computes vector orthonormal to given vector. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector2< T > hermes::project (const Vector2< T > &a, const Vector2< T > &b)
 Projects a vector onto another. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector3< T > hermes::project (const Vector3< T > &a, const Vector3< T > &b)
 Projects one vector into another. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE Vector3< T > hermes::reject (const Vector3< T > &a, const Vector3< T > &b)
 Rejects one vector on another. More...
 
template<typename T >
HERMES_DEVICE_CALLABLE void hermes::tangential (const Vector3< T > &a, Vector3< T > &b, Vector3< T > &c)
 compute the two orthogonal-tangential vectors from a More...
 
template<typename T >
std::ostream & hermes::operator<< (std::ostream &os, const Vector2< T > &v)
 
template<typename T >
std::ostream & hermes::operator<< (std::ostream &os, const Vector3< T > &v)
 
template<typename T >
std::ostream & hermes::operator<< (std::ostream &os, const Vector4< T > &v)
 

Detailed Description

Geometric vector classes.

Copyright (c) 2017, FilipeCN.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
FilipeCN (filip.nosp@m.edec.nosp@m.n@gma.nosp@m.il.c.nosp@m.om)
Date
2017-08-19

Macro Definition Documentation

◆ ARITHMETIC_OP [1/2]

#define ARITHMETIC_OP (   OP)
Value:
HERMES_DEVICE_CALLABLE Vector2 &operator OP##= (const Vector2 &v) { \
x OP##= v.x; y OP##= v.y; return *this; } \
HERMES_DEVICE_CALLABLE Vector2 &operator OP##= (real_t f) { \
x OP##= f; y OP##= f; return *this; } \
HERMES_DEVICE_CALLABLE Vector2 operator OP (const Vector2<T> &b) const { \
return {x OP b.x, y OP b.y}; } \
HERMES_DEVICE_CALLABLE Vector2 operator OP (real_t f) const { \
return {x OP f, y OP f}; }
float real_t
default floating point type
Definition: defs.h:75
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45

◆ ARITHMETIC_OP [2/2]

#define ARITHMETIC_OP (   OP)
Value:
HERMES_DEVICE_CALLABLE Vector3 &operator OP##= (const Vector3 &v) { \
x OP##= v.x; y OP##= v.y; z OP##= v.z; return *this; } \
HERMES_DEVICE_CALLABLE Vector3 &operator OP##= (real_t f) { \
x OP##= f; y OP##= f; z OP##= f; return *this; } \
HERMES_DEVICE_CALLABLE Vector3 operator OP (const Vector3<T> &b) const { \
return {x OP b.x, y OP b.y, z OP b.z}; } \
HERMES_DEVICE_CALLABLE Vector3 operator OP (T f) const { \
return {x OP f, y OP f, z OP f}; }

◆ MATH_OP [1/3]

#define MATH_OP (   D,
  NAME,
  OP 
)
Value:
template<typename T> \
HERMES_DEVICE_CALLABLE Vector##D<T> NAME(const Vector##D<T> &a, const Vector##D<T> &b) { \
return Vector##D<T>(DOP##D(OP)); }

◆ MATH_OP [2/3]

#define MATH_OP (   D,
  OP 
)
Value:
template<typename T> \
HERMES_DEVICE_CALLABLE Vector##D<T> operator OP(T f, const Vector##D<T> &v) { \
return Vector##D<T>(DOP##D(OP)); }

◆ MATH_OP [3/3]

#define MATH_OP (   NAME,
  OP,
 
)
Value:
template<typename T> \
HERMES_DEVICE_CALLABLE Vector##D<T> NAME(const Vector##D<T>& v) { \
return Vector##D<T>(DOP##D(OP)); }

◆ RELATIONAL_OP

#define RELATIONAL_OP (   OP,
  CO 
)
Value:
HERMES_DEVICE_CALLABLE bool operator OP (const Vector2 &b) const { \
return x OP b.x CO y OP b.y; }

Function Documentation

◆ cross() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE T hermes::cross ( const Vector2< T > &  a,
const Vector2< T > &  b 
)

Computes the cross product between two vectors.

Template Parameters
T
Parameters
a
b
Returns

◆ cross() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE Vector3<T> hermes::cross ( const Vector3< T > &  a,
const Vector3< T > &  b 
)

Computes the cross product between two vectors.

Template Parameters
T
Parameters
a
b
Returns

◆ dot() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE T hermes::dot ( const Vector2< T > &  a,
const Vector2< T > &  b 
)

Computes the dot product between two vectors.

Template Parameters
T
Parameters
a
b
Returns

◆ dot() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE T hermes::dot ( const Vector3< T > &  a,
const Vector3< T > &  b 
)

Computes the dot product between two vectors.

Template Parameters
T
Parameters
a
b
Returns

◆ normalize() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE Vector2<T> hermes::normalize ( const Vector2< T > &  v)

Computes normalized copy from vector.

Template Parameters
T
Parameters
v
Returns

◆ normalize() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE Vector3<T> hermes::normalize ( const Vector3< T > &  v)

Computes normalized copy from vector.

Template Parameters
T
Parameters
v
Returns

◆ orthonormal()

template<typename T >
HERMES_DEVICE_CALLABLE Vector2<T> hermes::orthonormal ( const Vector2< T > &  v,
bool  first = true 
)

Computes vector orthonormal to given vector.

Template Parameters
T
Parameters
v
first
Returns

◆ project() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE Vector2<T> hermes::project ( const Vector2< T > &  a,
const Vector2< T > &  b 
)

Projects a vector onto another.

Parameters
a[in]
b[in]
Returns
the projection of a onto b

◆ project() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE Vector3<T> hermes::project ( const Vector3< T > &  a,
const Vector3< T > &  b 
)

Projects one vector into another.

Note
b * dot(a,b) / ||b||
Template Parameters
T
Parameters
a
b
Returns
projection of a onto b

◆ reject()

template<typename T >
HERMES_DEVICE_CALLABLE Vector3<T> hermes::reject ( const Vector3< T > &  a,
const Vector3< T > &  b 
)

Rejects one vector on another.

Template Parameters
T
Parameters
a
b
Returns
rejection of a onto b

◆ tangential()

template<typename T >
HERMES_DEVICE_CALLABLE void hermes::tangential ( const Vector3< T > &  a,
Vector3< T > &  b,
Vector3< T > &  c 
)

compute the two orthogonal-tangential vectors from a

Parameters
a[in] normal
b[out] first tangent
c[out] second tangent

◆ triple()

template<typename T >
HERMES_DEVICE_CALLABLE T hermes::triple ( const Vector3< T > &  a,
const Vector3< T > &  b,
const Vector3< T > &  c 
)

Computes the triple product between 3 vectors.

Template Parameters
T
Parameters
a
b
c
Returns