8#ifndef META_OCEAN_MATH_VECTOR3_H
9#define META_OCEAN_MATH_VECTOR3_H
22template <
typename T>
class VectorT3;
119 inline explicit
VectorT3(const
bool setToHomogeneous) noexcept;
133 inline explicit
VectorT3(const T* valueArray) noexcept;
153 template <typename U>
278 inline const T&
x() const noexcept;
284 inline T&
x() noexcept;
290 inline const T&
y() const noexcept;
296 inline T&
y() noexcept;
302 inline const T&
z() const noexcept;
308 inline T&
z() noexcept;
320 inline const T*
data() const noexcept;
360 inline
bool operator==(const
VectorT3<T>& vector) const;
367 inline
bool operator!=(const
VectorT3<T>& vector) const;
408 inline T operator*(const
VectorT3<T>& vector) const;
415 inline
VectorT3<T> operator*(const T& value) const;
432 inline
VectorT3<T> operator/(const T& value) const;
450 inline
bool operator<(const
VectorT3<T>& vector) const;
457 inline const T& operator[](const
unsigned int index) const noexcept;
464 inline T& operator[](const
unsigned int index) noexcept;
471 inline const T& operator()(const
unsigned int index) const noexcept;
478 inline T& operator()(const
unsigned int index) noexcept;
484 inline const T* operator()() const noexcept;
490 inline T* operator()() noexcept;
497 inline
size_t operator()(const
VectorT3<T>& vector) const;
517 template <typename U>
526 template <typename U>
536 template <typename U>
548 static_assert(std::is_arithmetic<T>::value,
"VectorT3 only supports arithmetic types");
555 if (setToHomogeneous)
580 memcpy(
values_, valueArray,
sizeof(T) * 3);
614 ocean_assert(
false &&
"Division by zero!");
618 const T factor = T(1) / len;
632 const T factor = T(1) / len;
646 const T factor = T(1) / len;
659 const T factor = T(1) / len;
698 const T thisLength =
length();
699 const T rightLength = right.
length();
703 ocean_assert(
false &&
"Invalid vector!");
716 ocean_assert(*
this * normal >= 0);
719 const VectorT3<T> result(normal * ((normal * *
this) * 2) - *
this);
720 ocean_assert(
int(
angle(normal) * 100) ==
int(result.
angle(normal) * 100));
721 ocean_assert(result * normal >= 0);
725 return normal * ((normal * *
this) * 2) - *
this;
732 ocean_assert(*
this * normal >= 0);
733 ocean_assert(index > T(0));
735 const T dot = normal * *
this;
737 const T sqrtValue = T(1) - (index * index) * (T(1) - dot * dot);
740 if (sqrtValue < T(0))
747 const T angle0 =
angle(normal);
748 const T angle1 = result.
angle(-normal);
756 return normal * (index * dot -
NumericT<T>::sqrt(T(1) - (index * index) * (T(1) - dot * dot))) - *
this * index;
780 if (std::is_same<double, Scalar>::value)
785 const T dotProduct = normalizedThis * normalizedRight;
790 ocean_assert_accuracy(debugResult == (!
isNull() && !right.
isNull() && crossVector.
isNull()));
958 T factor = T(1) / value;
968 T factor = T(1) / value;
988 ocean_assert(index < 3u);
995 ocean_assert(index < 3u);
1002 ocean_assert(index < 3u);
1006template <
typename T>
1009 ocean_assert(index < 3u);
1013template <
typename T>
1019template <
typename T>
1025template <
typename T>
1028 size_t seed = std::hash<T>{}(vector.
x());
1029 seed ^= std::hash<T>{}(vector.
y()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1030 seed ^= std::hash<T>{}(vector.
z()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1035template <
typename T>
1041template <
typename T>
1051 return std::move(vectors);
1058 return std::move(vectors);
1061template <
typename T>
1062template <
typename U>
1065 std::vector<VectorT3<T>> result;
1066 result.reserve(vectors.size());
1068 for (
typename std::vector<
VectorT3<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
1070 result.emplace_back(*i);
1090template <
typename T>
1091template <
typename U>
1094 std::vector<VectorT3<T>> result;
1095 result.reserve(vectors.size());
1097 for (
typename std::vector<
VectorT3<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
1099 result.emplace_back(*i);
1105template <
typename T>
1106template <
typename U>
1109 std::vector< VectorT3<T>> result;
1110 result.reserve(size);
1112 for (
size_t n = 0; n < size; ++n)
1114 result.emplace_back(vectors[n]);
1120template <
typename T>
1123 stream <<
"[" << vector.
x() <<
", " << vector.
y() <<
", " << vector.
z() <<
"]";
1128template <
bool tActive,
typename T>
1129MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const VectorT3<T>& vector)
1131 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
"]";
1134template <
bool tActive,
typename T>
1135MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const VectorT3<T>& vector)
1137 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
"]";
This class provides basic numeric functionalities.
Definition Numeric.h:57
static T sin(const T value)
Returns the sine of a given value.
Definition Numeric.h:1572
static T sqrt(const T value)
Returns the square root of a given value.
Definition Numeric.h:1537
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2395
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1499
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2096
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2916
static bool isNotEqual(const T first, const T second)
Returns whether two values are not equal up to a small epsilon.
Definition Numeric.h:2622
This class implements a vector with two elements.
Definition Vector2.h:96
bool isUnit(const T eps=NumericT< T >::eps()) const
Returns whether this vector is a unit vector (whether the vector has the length 1).
Definition Vector3.h:865
VectorT3< T > normalizedOrValue(const VectorT3< T > &value) const
Returns the normalized vector.
Definition Vector3.h:637
const T * operator()() const noexcept
Access operator.
Definition Vector3.h:1014
VectorT3< T > perpendicular() const
Returns a vector that is perpendicular to this vector.
Definition Vector3.h:760
bool operator!=(const VectorT3< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector3.h:887
VectorT3< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector3.h:945
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:816
VectorT3< T > & operator-=(const VectorT3< T > &vector)
Subtracts and assigns two vectors.
Definition Vector3.h:917
bool normalize()
Normalizes this vector.
Definition Vector3.h:651
T operator*(const VectorT3< T > &vector) const
Returns the dot product of two vectors.
Definition Vector3.h:933
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition Vector3.h:601
bool isOrthogonal(const VectorT3< T > &right) const
Returns whether two vectors are orthogonal.
Definition Vector3.h:798
const T & operator[](const unsigned int index) const noexcept
Element access operator.
Definition Vector3.h:986
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:804
VectorT2< T > xy() const noexcept
Returns the x and y component of the vector as new 2D vector.
Definition Vector3.h:840
VectorT3< T > normalizedOrZero() const
Returns the normalized vector.
Definition Vector3.h:623
VectorT3< T > refract(const VectorT3< T > &normal, const T index) const
Returns the refracted vector of this vector corresponding to a given normal vector.
Definition Vector3.h:729
VectorT3< T > normalized() const
Returns the normalized vector.
Definition Vector3.h:609
static VectorT3< T > minValue()
Returns a 3D vector with all elements set to NumericT::minValue().
Definition Vector3.h:1036
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
VectorT3() noexcept
Creates a new 3D vector with undefined elements.
Definition Vector3.h:546
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector3.h:858
bool isEqual(const VectorT3< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector3.h:871
T values_[3]
The three values of the vector, with element order x, y, z.
Definition Vector3.h:542
T Type
Definition of the used data type.
Definition Vector3.h:103
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector3.h:846
VectorT3< T > & operator/=(const T &value)
Divides and assigns this vector by a scalar.
Definition Vector3.h:964
T distance(const VectorT3< T > &right) const
Returns the distance between this 3D position and a second 3D position.
Definition Vector3.h:680
T sqrDistance(const VectorT3< T > &right) const
Returns the square distance between this 3D position and a second 3D position.
Definition Vector3.h:686
VectorT3< T > operator/(const T &value) const
Divides this vector by a scalar.
Definition Vector3.h:955
static VectorT3< T > maxValue()
Returns a 3D vector with all elements set to NumericT::maxValue().
Definition Vector3.h:1042
VectorT3< T > operator-() const
Returns the negated vector.
Definition Vector3.h:927
T length() const
Returns the length of the vector.
Definition Vector3.h:668
bool isParallel(const VectorT3< T > &right) const
Returns whether two vectors are parallel.
Definition Vector3.h:777
VectorT3< T > operator+(const VectorT3< T > &vector) const
Adds two vectors.
Definition Vector3.h:895
VectorT3< T > reflect(const VectorT3< T > &normal) const
Returns the reflected vector of this vector corresponding to a given normal vector.
Definition Vector3.h:713
VectorT3< T > & operator+=(const VectorT3< T > &vector)
Adds and assigns two vectors.
Definition Vector3.h:901
bool operator==(const VectorT3< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector3.h:879
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:674
T angle(const VectorT3< T > &right) const
Returns the angle between this vector and a second vectors.
Definition Vector3.h:692
static std::vector< VectorT3< T > > vectors2vectors(std::vector< VectorT3< U > > &&vectors)
Converts vectors with specific data type to vectors with different data type.
Definition Vector3.h:1063
bool operator<(const VectorT3< T > &vector) const
Compares two vector objects and returns whether the left vector represents a smaller value than the r...
Definition Vector3.h:978
std::vector< VectorD3 > VectorsD3
Definition of a vector holding VectorD3 objects.
Definition Vector3.h:72
std::vector< VectorI3 > VectorsI3
Definition of a vector holding VectorI3 objects.
Definition Vector3.h:86
std::vector< VectorF3 > VectorsF3
Definition of a vector holding VectorF3 objects.
Definition Vector3.h:79
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
std::vector< VectorT3< T > > VectorsT3
Definition of a typename alias for vectors with VectorT3 objects.
Definition Vector3.h:58
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963