Ocean
Ocean::VectorT3< T > Class Template Reference

This class implements a vector with three elements. More...

Inheritance diagram for Ocean::VectorT3< T >:

Public Types

typedef T Type
 Definition of the used data type. More...
 

Public Member Functions

 VectorT3 () noexcept
 Creates a new 3D vector with undefined elements. More...
 
 VectorT3 (const bool setToHomogeneous) noexcept
 Creates a new 3D vector. More...
 
 VectorT3 (const T &x, const T &y, const T &z) noexcept
 Creates a new 3D vector with three given elements. More...
 
 VectorT3 (const T *valueArray) noexcept
 Creates a new 3D vector with a given array of elements. More...
 
 VectorT3 (const VectorT2< T > &vector, const T &z=0) noexcept
 Creates a new 3D vector with a given 2D vector defining the first two elements and a single value defining the third element. More...
 
 VectorT3 (const VectorT3< T > &vector) noexcept
 Copies a vector. More...
 
template<typename U >
 VectorT3 (const VectorT3< U > &vector) noexcept
 Copies a vector with different element data type than T. More...
 
VectorT3< T > cross (const VectorT3< T > &vector) const
 Returns the cross product of two vectors. More...
 
VectorT3< T > normalized () const
 Returns the normalized vector. More...
 
VectorT3< T > normalizedOrZero () const
 Returns the normalized vector. More...
 
VectorT3< T > normalizedOrValue (const VectorT3< T > &value) const
 Returns the normalized vector. More...
 
bool normalize ()
 Normalizes this vector. More...
 
length () const
 Returns the length of the vector. More...
 
sqr () const
 Returns the square of the vector length. More...
 
distance (const VectorT3< T > &right) const
 Returns the distance between this 3D position and a second 3D position. More...
 
sqrDistance (const VectorT3< T > &right) const
 Returns the square distance between this 3D position and a second 3D position. More...
 
angle (const VectorT3< T > &right) const
 Returns the angle between this vector and a second vectors. More...
 
VectorT3< T > reflect (const VectorT3< T > &normal) const
 Returns the reflected vector of this vector corresponding to a given normal vector. More...
 
VectorT3< T > refract (const VectorT3< T > &normal, const T index) const
 Returns the refracted vector of this vector corresponding to a given normal vector. More...
 
VectorT3< T > perpendicular () const
 Returns a vector that is perpendicular to this vector. More...
 
bool isParallel (const VectorT3< T > &right) const
 Returns whether two vectors are parallel. More...
 
bool isOrthogonal (const VectorT3< T > &right) const
 Returns whether two vectors are orthogonal. More...
 
const T & x () const noexcept
 Returns the x value. More...
 
T & x () noexcept
 Returns the x value. More...
 
const T & y () const noexcept
 Returns the y value. More...
 
T & y () noexcept
 Returns the y value. More...
 
const T & z () const noexcept
 Returns the z value. More...
 
T & z () noexcept
 Returns the z value. More...
 
VectorT2< T > xy () const noexcept
 Returns the x and y component of the vector as new 2D vector. More...
 
const T * data () const noexcept
 Returns an pointer to the vector elements. More...
 
T * data () noexcept
 Returns an pointer to the vector elements. More...
 
bool isNull () const
 Returns whether this vector is a null vector up to a small epsilon. More...
 
bool isUnit (const T eps=NumericT< T >::eps()) const
 Returns whether this vector is a unit vector (whether the vector has the length 1). More...
 
bool isEqual (const VectorT3< T > &vector, const T eps) const
 Returns whether two vectors are equal up to a specified epsilon. More...
 
VectorT3operator= (const VectorT3< T > &vector)
 Copy assigns a vector. More...
 
bool operator== (const VectorT3< T > &vector) const
 Returns whether two vectors are identical up to a small epsilon. More...
 
bool operator!= (const VectorT3< T > &vector) const
 Returns whether two vectors are not identical up to a small epsilon. More...
 
VectorT3< T > operator+ (const VectorT3< T > &vector) const
 Adds two vectors. More...
 
VectorT3< T > & operator+= (const VectorT3< T > &vector)
 Adds and assigns two vectors. More...
 
VectorT3< T > operator- (const VectorT3< T > &vector) const
 Subtracts two vectors. More...
 
VectorT3< T > & operator-= (const VectorT3< T > &vector)
 Subtracts and assigns two vectors. More...
 
VectorT3< T > operator- () const
 Returns the negated vector. More...
 
operator* (const VectorT3< T > &vector) const
 Returns the dot product of two vectors. More...
 
VectorT3< T > operator* (const T &value) const
 Multiplies this vector with a scalar. More...
 
VectorT3< T > & operator*= (const T &value)
 Multiplies and assigns this vector with a scalar. More...
 
VectorT3< T > operator/ (const T &value) const
 Divides this vector by a scalar. More...
 
VectorT3< T > & operator/= (const T &value)
 Divides and assigns this vector by a scalar. More...
 
bool operator< (const VectorT3< T > &vector) const
 Compares two vector objects and returns whether the left vector represents a smaller value than the right vector. More...
 
const T & operator[] (const unsigned int index) const noexcept
 Element access operator. More...
 
T & operator[] (const unsigned int index) noexcept
 Element access operator. More...
 
const T & operator() (const unsigned int index) const noexcept
 Element access operator. More...
 
T & operator() (const unsigned int index) noexcept
 Element access operator. More...
 
const T * operator() () const noexcept
 Access operator. More...
 
T * operator() () noexcept
 Access operator. More...
 
size_t operator() (const VectorT3< T > &vector) const
 Hash function. More...
 
std::vector< VectorT3< float > > vectors2vectors (std::vector< VectorT3< float >> &&vectors)
 
std::vector< VectorT3< double > > vectors2vectors (std::vector< VectorT3< double >> &&vectors)
 
std::vector< VectorT3< float > > vectors2vectors (const std::vector< VectorT3< float >> &vectors)
 
std::vector< VectorT3< double > > vectors2vectors (const std::vector< VectorT3< double >> &vectors)
 

Static Public Member Functions

template<typename U >
static std::vector< VectorT3< T > > vectors2vectors (std::vector< VectorT3< U >> &&vectors)
 Converts vectors with specific data type to vectors with different data type. More...
 
template<typename U >
static std::vector< VectorT3< T > > vectors2vectors (const std::vector< VectorT3< U >> &vectors)
 Converts vectors with specific data type to vectors with different data type. More...
 
template<typename U >
static std::vector< VectorT3< T > > vectors2vectors (const VectorT3< U > *vectors, const size_t size)
 Converts vectors with specific data type to vectors with different data type. More...
 

Protected Attributes

values_ [3]
 The three values of the vector, with element order x, y, z. More...
 

Detailed Description

template<typename T>
class Ocean::VectorT3< T >

This class implements a vector with three elements.

The element order is: (x, y, z).

Template Parameters
TData type of the vector elements.
See also
Vector3, VectorF3, VectorD3.

Member Typedef Documentation

◆ Type

template<typename T >
typedef T Ocean::VectorT3< T >::Type

Definition of the used data type.

Constructor & Destructor Documentation

◆ VectorT3() [1/7]

template<typename T >
Ocean::VectorT3< T >::VectorT3
inlinenoexcept

Creates a new 3D vector with undefined elements.

Beware: The elements are neither zero nor a specific value! This is useful in situations where VectorT3 objects are created (e.g, by a large array or vector) and their values are assigned in a function afterwards.

◆ VectorT3() [2/7]

template<typename T >
Ocean::VectorT3< T >::VectorT3 ( const bool  setToHomogeneous)
inlineexplicitnoexcept

Creates a new 3D vector.

Parameters
setToHomogeneousDetermines whether a homogeneous vector (0, 0, 1) will be created, otherwise the vector is initialized with zeros

◆ VectorT3() [3/7]

template<typename T >
Ocean::VectorT3< T >::VectorT3 ( const T &  x,
const T &  y,
const T &  z 
)
inlinenoexcept

Creates a new 3D vector with three given elements.

Parameters
xX value
yY value
zZ value

◆ VectorT3() [4/7]

template<typename T >
Ocean::VectorT3< T >::VectorT3 ( const T *  valueArray)
inlineexplicitnoexcept

Creates a new 3D vector with a given array of elements.

Parameters
valueArrayArray with at least three elements

◆ VectorT3() [5/7]

template<typename T >
Ocean::VectorT3< T >::VectorT3 ( const VectorT2< T > &  vector,
const T &  z = 0 
)
inlineexplicitnoexcept

Creates a new 3D vector with a given 2D vector defining the first two elements and a single value defining the third element.

Parameters
vector2D vector defining the first two elements (X and Y value)
zZ value defining the third element

◆ VectorT3() [6/7]

template<typename T >
Ocean::VectorT3< T >::VectorT3 ( const VectorT3< T > &  vector)
inlinenoexcept

Copies a vector.

Parameters
vector3D vector that is copied

◆ VectorT3() [7/7]

template<typename T >
template<typename U >
Ocean::VectorT3< T >::VectorT3 ( const VectorT3< U > &  vector)
inlineexplicitnoexcept

Copies a vector with different element data type than T.

Parameters
vectorThe 3D vector to copy
Template Parameters
UThe element data type of the second vector

Member Function Documentation

◆ angle()

template<typename T >
T Ocean::VectorT3< T >::angle ( const VectorT3< T > &  right) const

Returns the angle between this vector and a second vectors.

Beware: This vector must not be zero.
Beware: This function does not throw an exception if one or both vectors are zero.
In case, the angle cannot be determined -1 will be returned.

Parameters
rightSecond vector, must not be zero
Returns
Angle between both vectors in radian, with range [0, PI], -1 in case of an error

◆ cross()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::cross ( const VectorT3< T > &  vector) const
inline

Returns the cross product of two vectors.

The cross product of two parallel vectors (or of at least one zero vector) results in a zero vector.

Parameters
vectorThe right vector
Returns
The resulting cross product of both vectors
See also
isParallel().

◆ data() [1/2]

template<typename T >
const T * Ocean::VectorT3< T >::data
inlinenoexcept

Returns an pointer to the vector elements.

Returns
Pointer to elements

◆ data() [2/2]

template<typename T >
T * Ocean::VectorT3< T >::data
inlinenoexcept

Returns an pointer to the vector elements.

Returns
Pointer to elements

◆ distance()

template<typename T >
T Ocean::VectorT3< T >::distance ( const VectorT3< T > &  right) const
inline

Returns the distance between this 3D position and a second 3D position.

Parameters
rightSecond 3D position
Returns
Distance between the two points

◆ isEqual()

template<typename T >
bool Ocean::VectorT3< T >::isEqual ( const VectorT3< T > &  vector,
const T  eps 
) const
inline

Returns whether two vectors are equal up to a specified epsilon.

Parameters
vectorSecond vector
epsEpsilon to be used
Returns
True, if so

◆ isNull()

template<typename T >
bool Ocean::VectorT3< T >::isNull
inline

Returns whether this vector is a null vector up to a small epsilon.

Returns
True, if so

◆ isOrthogonal()

template<typename T >
bool Ocean::VectorT3< T >::isOrthogonal ( const VectorT3< T > &  right) const
inline

Returns whether two vectors are orthogonal.

A zero vector will not be orthogonal.

Parameters
rightThe right vector
Returns
True, if so

◆ isParallel()

template<typename T >
bool Ocean::VectorT3< T >::isParallel ( const VectorT3< T > &  right) const

Returns whether two vectors are parallel.

A zero vector will not be parallel.

Parameters
rightThe right vector
Returns
True, if so
See also
cross().

◆ isUnit()

template<typename T >
bool Ocean::VectorT3< T >::isUnit ( const T  eps = NumericT<T>::eps()) const
inline

Returns whether this vector is a unit vector (whether the vector has the length 1).

Parameters
epsEpsilon to be used, with range [0, infinity)
Returns
True, if so

◆ length()

template<typename T >
T Ocean::VectorT3< T >::length
inline

Returns the length of the vector.

Returns
Vector length

◆ normalize()

template<typename T >
bool Ocean::VectorT3< T >::normalize
inline

Normalizes this vector.

Returns
True, if the vector could be normalized

◆ normalized()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::normalized
inline

Returns the normalized vector.

Beware: This function does not throw an exception if this vector cannot be normalized.
Thus, ensure that this vector is not zero before calling this function.
Or even better, use different normalization functions like: normalizedOrZero(), normalizedOrValue(), or normalize().
In case, the vector cannot be normalized, an uninitialized vector will be returned (due to performance reasons).

Returns
This vector as unit vector (vector with length 1)
See also
normalizedOrZero(), normalizedOrValue(), normalize().

◆ normalizedOrValue()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::normalizedOrValue ( const VectorT3< T > &  value) const
inline

Returns the normalized vector.

If this vector cannot be normalized the given vector is returned.

Parameters
valueVector that will be returned if the vector cannot be normalized
Returns
Vector with length 1

◆ normalizedOrZero()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::normalizedOrZero
inline

Returns the normalized vector.

If this vector cannot be normalized the zero vector is returned.

Returns
Vector with length 1

◆ operator!=()

template<typename T >
bool Ocean::VectorT3< T >::operator!= ( const VectorT3< T > &  vector) const
inline

Returns whether two vectors are not identical up to a small epsilon.

Parameters
vectorRight vector
Returns
True, if so

◆ operator()() [1/5]

template<typename T >
const T * Ocean::VectorT3< T >::operator()
inlinenoexcept

Access operator.

Returns
Pointer to the elements

◆ operator()() [2/5]

template<typename T >
T * Ocean::VectorT3< T >::operator()
inlinenoexcept

Access operator.

Returns
Pointer to the elements

◆ operator()() [3/5]

template<typename T >
const T & Ocean::VectorT3< T >::operator() ( const unsigned int  index) const
inlinenoexcept

Element access operator.

Parameters
indexThe index of the element to access, with range [0, 2]
Returns
Element of the vector

◆ operator()() [4/5]

template<typename T >
T & Ocean::VectorT3< T >::operator() ( const unsigned int  index)
inlinenoexcept

Element access operator.

Parameters
indexThe index of the element to access, with range [0, 2]
Returns
Element of the vector

◆ operator()() [5/5]

template<typename T >
size_t Ocean::VectorT3< T >::operator() ( const VectorT3< T > &  vector) const
inline

Hash function.

Parameters
vectorThe vector for which the hash value will be determined
Returns
The resulting hash value

◆ operator*() [1/2]

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::operator* ( const T &  value) const
inline

Multiplies this vector with a scalar.

Parameters
valueScalar value
Returns
Resulting vector

◆ operator*() [2/2]

template<typename T >
T Ocean::VectorT3< T >::operator* ( const VectorT3< T > &  vector) const
inline

Returns the dot product of two vectors.

Parameters
vectorRight vector
Returns
Dot product

◆ operator*=()

template<typename T >
VectorT3< T > & Ocean::VectorT3< T >::operator*= ( const T &  value)
inline

Multiplies and assigns this vector with a scalar.

Parameters
valueScalar value
Returns
Reference to this vector

◆ operator+()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::operator+ ( const VectorT3< T > &  vector) const
inline

Adds two vectors.

Parameters
vectorRight vector
Returns
Sum vector

◆ operator+=()

template<typename T >
VectorT3< T > & Ocean::VectorT3< T >::operator+= ( const VectorT3< T > &  vector)
inline

Adds and assigns two vectors.

Parameters
vectorRight vector
Returns
Reference to this vector

◆ operator-() [1/2]

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::operator-
inline

Returns the negated vector.

Returns
Negated vector

◆ operator-() [2/2]

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::operator- ( const VectorT3< T > &  vector) const
inline

Subtracts two vectors.

Parameters
vectorRight vector
Returns
Difference vector

◆ operator-=()

template<typename T >
VectorT3< T > & Ocean::VectorT3< T >::operator-= ( const VectorT3< T > &  vector)
inline

Subtracts and assigns two vectors.

Parameters
vectorRight vector
Returns
Reference to this vector

◆ operator/()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::operator/ ( const T &  value) const
inline

Divides this vector by a scalar.

Beware: This function does not throw an exception if the given value is zero.
Thus, ensure that given value is not zero before calling this function.
In case, the given value is zero, the result is undefined.

Parameters
valueScalar value to be used as denominator, must not be zero
Returns
Resulting vector

◆ operator/=()

template<typename T >
VectorT3< T > & Ocean::VectorT3< T >::operator/= ( const T &  value)
inline

Divides and assigns this vector by a scalar.

Beware: This function does not throw an exception if the given value is zero.
Thus, ensure that given value is not zero before calling this function.
In case, the given value is zero, the result is undefined.

Parameters
valueScalar value to be used as denominator, must not be zero
Returns
Reference to this vector

◆ operator<()

template<typename T >
bool Ocean::VectorT3< T >::operator< ( const VectorT3< T > &  vector) const
inline

Compares two vector objects and returns whether the left vector represents a smaller value than the right vector.

First the first component of both vectors are compared, if these values are equal then the next components are compares and so on.

Parameters
vectorThe second vector to compare
Returns
True, if so

◆ operator=()

template<typename T >
VectorT3< T > & Ocean::VectorT3< T >::operator= ( const VectorT3< T > &  vector)
inline

Copy assigns a vector.

Parameters
vector3D vector that is copied

◆ operator==()

template<typename T >
bool Ocean::VectorT3< T >::operator== ( const VectorT3< T > &  vector) const
inline

Returns whether two vectors are identical up to a small epsilon.

Parameters
vectorRight vector
Returns
True, if so

◆ operator[]() [1/2]

template<typename T >
const T & Ocean::VectorT3< T >::operator[] ( const unsigned int  index) const
inlinenoexcept

Element access operator.

Parameters
indexThe index of the element to access, with range [0, 2]
Returns
Element of the vector

◆ operator[]() [2/2]

template<typename T >
T & Ocean::VectorT3< T >::operator[] ( const unsigned int  index)
inlinenoexcept

Element access operator.

Parameters
indexThe index of the element to access, with range [0, 2]
Returns
Element of the vector

◆ perpendicular()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::perpendicular

Returns a vector that is perpendicular to this vector.

If this vector is a zero vector, than the resulting vector will be arbitrary.

Returns
Resulting perpendicular vector, a unity vector is not guaranteed

◆ reflect()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::reflect ( const VectorT3< T > &  normal) const

Returns the reflected vector of this vector corresponding to a given normal vector.

The dot product between this vector and the normal vector must be positive.

Parameters
normalThe normal vector used to determine the reflection vector for
Returns
Resulting reflection vector

◆ refract()

template<typename T >
VectorT3< T > Ocean::VectorT3< T >::refract ( const VectorT3< T > &  normal,
const T  index 
) const

Returns the refracted vector of this vector corresponding to a given normal vector.

The dot product between this vector and the normal vector must be positive.

Parameters
normalThe normal vector used to determine the refracted vector for
indexRefraction index that is the ratio between the leaving and the entering refraction index, an index lower than 1 describes the transition from a thin into a thick medium, with range (0, infinity)
Returns
Resulting refracted vector

◆ sqr()

template<typename T >
T Ocean::VectorT3< T >::sqr
inline

Returns the square of the vector length.

Returns
Square of vector length

◆ sqrDistance()

template<typename T >
T Ocean::VectorT3< T >::sqrDistance ( const VectorT3< T > &  right) const
inline

Returns the square distance between this 3D position and a second 3D position.

Parameters
rightSecond 3D position
Returns
Square distance between the two points

◆ vectors2vectors() [1/7]

std::vector< VectorT3< double > > Ocean::VectorT3< double >::vectors2vectors ( const std::vector< VectorT3< double >> &  vectors)
inline

◆ vectors2vectors() [2/7]

std::vector< VectorT3< float > > Ocean::VectorT3< float >::vectors2vectors ( const std::vector< VectorT3< float >> &  vectors)
inline

◆ vectors2vectors() [3/7]

template<typename T >
template<typename U >
std::vector< VectorT3< T > > Ocean::VectorT3< T >::vectors2vectors ( const std::vector< VectorT3< U >> &  vectors)
inlinestatic

Converts vectors with specific data type to vectors with different data type.

Parameters
vectorsThe vectors to convert
Returns
The converted vectors
Template Parameters
UThe element data type of the vectors to convert

◆ vectors2vectors() [4/7]

template<typename T >
template<typename U >
std::vector< VectorT3< T > > Ocean::VectorT3< T >::vectors2vectors ( const VectorT3< U > *  vectors,
const size_t  size 
)
inlinestatic

Converts vectors with specific data type to vectors with different data type.

Parameters
vectorsThe vectors to convert
sizeThe number of vector to convert
Returns
The converted vectors
Template Parameters
UThe element data type of the vectors to convert

◆ vectors2vectors() [5/7]

std::vector< VectorT3< double > > Ocean::VectorT3< double >::vectors2vectors ( std::vector< VectorT3< double >> &&  vectors)
inline

◆ vectors2vectors() [6/7]

std::vector< VectorT3< float > > Ocean::VectorT3< float >::vectors2vectors ( std::vector< VectorT3< float >> &&  vectors)
inline

◆ vectors2vectors() [7/7]

template<typename T >
template<typename U >
std::vector< VectorT3< T > > Ocean::VectorT3< T >::vectors2vectors ( std::vector< VectorT3< U >> &&  vectors)
inlinestatic

Converts vectors with specific data type to vectors with different data type.

Parameters
vectorsThe vectors to convert
Returns
The converted vectors
Template Parameters
UThe element data type of the vectors to convert

◆ x() [1/2]

template<typename T >
const T & Ocean::VectorT3< T >::x
inlinenoexcept

Returns the x value.

Returns
X value

◆ x() [2/2]

template<typename T >
T & Ocean::VectorT3< T >::x
inlinenoexcept

Returns the x value.

Returns
X value

◆ xy()

template<typename T >
VectorT2< T > Ocean::VectorT3< T >::xy
inlinenoexcept

Returns the x and y component of the vector as new 2D vector.

Returns
New 2D vector

◆ y() [1/2]

template<typename T >
const T & Ocean::VectorT3< T >::y
inlinenoexcept

Returns the y value.

Returns
Y value

◆ y() [2/2]

template<typename T >
T & Ocean::VectorT3< T >::y
inlinenoexcept

Returns the y value.

Returns
Y value

◆ z() [1/2]

template<typename T >
const T & Ocean::VectorT3< T >::z
inlinenoexcept

Returns the z value.

Returns
Z value

◆ z() [2/2]

template<typename T >
T & Ocean::VectorT3< T >::z
inlinenoexcept

Returns the z value.

Returns
Z value

Field Documentation

◆ values_

template<typename T >
T Ocean::VectorT3< T >::values_[3]
protected

The three values of the vector, with element order x, y, z.


The documentation for this class was generated from the following file: