6#include "MRPch/MRBindingMacros.h"
18#pragma warning(disable: 4804)
19#pragma warning(disable: 4146)
34 constexpr Vector3() noexcept :
x( 0 ),
y( 0 ),
z( 0 ) { }
48 constexpr explicit Vector3(
const Vector3<U> & v ) noexcept :
x( T( v.x ) ),
y( T( v.y ) ),
z( T( v.z ) ) { }
50 constexpr const T &
operator [](
int e )
const noexcept {
return *( &
x + e ); }
51 constexpr T &
operator [](
int e )
noexcept {
return *( &
x + e ); }
67 return ( 1 / len ) * (*this);
81 return xf ? ( *xf )( *this ) : *
this;
87 for (
auto i = 0; i <
elements; ++i )
88 if ( (*
this)[i] == 0.f && std::signbit( (*
this)[i] ) )
94 return std::isfinite(
x ) && std::isfinite(
y ) && std::isfinite(
z );
111 if constexpr ( std::is_integral_v<T> )
112 return { b.x / a, b.y / a, b.z / a };
114 return b * ( 1 / a );
122 if constexpr ( std::is_integral_v<T> )
123 { a.
x /= b; a.y /= b; a.z /= b;
return a; }
125 return a *= ( 1 / b );
137 return ( a - b ).lengthSq();
144 return ( a - b ).length();
152 a.
y * b.
z - a.
z * b.
y,
153 a.
z * b.
x - a.
x * b.
z,
154 a.
x * b.
y - a.
y * b.
x
162 return a.x * b.x + a.y * b.y + a.z * b.z;
176 return dot( a, cross( b, c ) );
183 return { a.
x * b.
x,a.
y * b.
y,a.
z * b.
z };
190 return { a.
x / b.
x, a.
y / b.
y, a.
z / b.
z };
199 return std::atan2( cross( a, b ).
length(), dot( a, b ) );
208 if ( abs( x ) < abs( y ) )
209 return ( abs( x ) < abs( z ) ) ?
Vector3( 1, 0, 0 ) :
Vector3( 0, 0, 1 );
211 return ( abs( y ) < abs( z ) ) ?
Vector3( 0, 1, 0 ) :
Vector3( 0, 0, 1 );
218 auto c1 = furthestBasisVector();
219 res.first = cross( *
this, c1 ).normalized();
220 res.second = cross( *
this, res.first ).normalized();
228 const auto zenithAngle = T( PI2 ) - altitude;
231 std::sin( zenithAngle ) * std::cos( azimuth ),
232 std::sin( zenithAngle ) * std::sin( azimuth ),
233 std::cos( zenithAngle )
241MR_BIND_IGNORE
inline auto begin(
const Vector3<T> & v ) {
return &v[0]; }
246MR_BIND_IGNORE
inline auto end(
const Vector3<T> & v ) {
return &v[3]; }
248MR_BIND_IGNORE
inline auto end(
Vector3<T> & v ) {
return &v[3]; }
#define MR_SAME_TYPE_TEMPLATE_PARAM(target_, name_)
Definition MRMacros.h:32
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:31
length
Definition MRObjectDimensionsEnum.h:14
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:295
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:297
MRMESH_CLASS Vector3
Definition MRMesh/MRMeshFwd.h:170
Definition MRMesh/MRAffineXf.h:14
Definition MRMesh/MRMatrix3.h:19
Definition MRMesh/MRMeshFwd.h:89
Definition MRSymMatrix3.h:15
Definition MRVector2.h:25
Definition MRMesh/MRVector3.h:26
static constexpr Vector3 plusX() noexcept
Definition MRMesh/MRVector3.h:40
auto dot(const Vector3< T > &a, const Vector3< T > &b) -> decltype(a.x *b.x)
dot product
Definition MRMesh/MRVector3.h:160
Vector3< T > unitVector3(T azimuth, T altitude)
returns a point on unit sphere given two angles
Definition MRMesh/MRVector3.h:226
T distanceSq(const Vector3< T > &a, const Vector3< T > &b)
squared distance between two points, which is faster to compute than just distance
Definition MRMesh/MRVector3.h:135
friend constexpr bool operator!=(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:98
Vector3< T > div(const Vector3< T > &a, const Vector3< T > &b)
per component division
Definition MRMesh/MRVector3.h:188
friend constexpr auto operator*(T a, const Vector3< T > &b) -> Vector3< decltype(std::declval< T >() *std::declval< T >())>
Definition MRMesh/MRVector3.h:107
friend constexpr auto operator-(const Vector3< T > &a) -> Vector3< decltype(-std::declval< T >())>
Definition MRMesh/MRVector3.h:103
T x
Definition MRMesh/MRVector3.h:32
static constexpr Vector3 minusX() noexcept
Definition MRMesh/MRVector3.h:43
static constexpr Vector3 minusY() noexcept
Definition MRMesh/MRVector3.h:44
bool isFinite() const
Definition MRMesh/MRVector3.h:92
T y
Definition MRMesh/MRVector3.h:32
static constexpr int elements
Definition MRMesh/MRVector3.h:30
friend constexpr const Vector3< T > & operator+(const Vector3< T > &a)
Definition MRMesh/MRVector3.h:102
friend constexpr Vector3< T > & operator/=(Vector3< T > &a, T b)
Definition MRMesh/MRVector3.h:120
std::pair< Vector3, Vector3 > perpendicular() const
void unsignZeroValues()
get rid of signed zero values to be sure that equal vectors have identical binary representation
Definition MRMesh/MRVector3.h:85
Vector3(NoInit) noexcept
Definition MRMesh/MRVector3.h:35
T ValueType
Definition MRMesh/MRVector3.h:27
constexpr const T & operator[](int e) const noexcept
Definition MRMesh/MRVector3.h:50
auto length() const
Definition MRMesh/MRVector3.h:54
constexpr Vector3(T x, T y, T z) noexcept
Definition MRMesh/MRVector3.h:36
friend constexpr bool operator==(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:97
friend constexpr Vector3< T > & operator*=(Vector3< T > &a, T b)
Definition MRMesh/MRVector3.h:119
T distance(const Vector3< T > &a, const Vector3< T > &b)
distance between two points, better use distanceSq for higher performance
Definition MRMesh/MRVector3.h:142
T mixed(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
mixed product
Definition MRMesh/MRVector3.h:174
static constexpr Vector3 plusZ() noexcept
Definition MRMesh/MRVector3.h:42
friend constexpr auto operator/(Vector3< T > b, T a) -> Vector3< decltype(std::declval< T >()/std::declval< T >())>
Definition MRMesh/MRVector3.h:109
T sqr(const Vector3< T > &a)
squared length
Definition MRMesh/MRVector3.h:167
Vector3 normalized() const
Definition MRMesh/MRVector3.h:62
T angle(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:197
constexpr Vector3(const Vector2< T > &v) noexcept
Definition MRMesh/MRVector3.h:37
constexpr Vector3(const Vector3< U > &v) noexcept
Definition MRMesh/MRVector3.h:48
constexpr Vector3() noexcept
Definition MRMesh/MRVector3.h:34
static constexpr Vector3 minusZ() noexcept
Definition MRMesh/MRVector3.h:45
Vector3< T > mult(const Vector3< T > &a, const Vector3< T > &b)
per component multiplication
Definition MRMesh/MRVector3.h:181
T z
Definition MRMesh/MRVector3.h:32
friend constexpr Vector3< T > & operator-=(Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:118
T lengthSq() const
Definition MRMesh/MRVector3.h:53
static constexpr Vector3 plusY() noexcept
Definition MRMesh/MRVector3.h:41
Vector3 furthestBasisVector() const
returns one of 3 basis unit vector that makes the biggest angle with the direction specified by this
Vector3 transformed(const AffineXf3< TT > *xf) const
returns this vector transformed by xf if it is
Definition MRMesh/MRVector3.h:79
static constexpr Vector3 diagonal(T a) noexcept
Definition MRMesh/MRVector3.h:39
Vector3< T > cross(const Vector3< T > &a, const Vector3< T > &b)
cross product
Definition MRMesh/MRVector3.h:149
friend constexpr Vector3< T > & operator+=(Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:117