4#ifndef OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
5#define OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
21template<
typename T>
class Mat3;
36 explicit Vec3(T val) { this->
mm[0] = this->
mm[1] = this->
mm[2] = val; }
47 template <
typename Source>
50 this->
mm[0] =
static_cast<T
>(a[0]);
51 this->
mm[1] =
static_cast<T
>(a[1]);
52 this->
mm[2] =
static_cast<T
>(a[2]);
57 template<
typename Source>
60 this->
mm[0] =
static_cast<T
>(v[0]);
61 this->
mm[1] =
static_cast<T
>(v[1]);
62 this->
mm[2] =
static_cast<T
>(v[2]);
68 template<
typename Other>
72 this->mm[0] = this->mm[1] = this->mm[2] =
static_cast<T
>(val);
77 template<
typename Other>
80 this->
mm[0] =
static_cast<T
>(v[0]);
81 this->
mm[1] =
static_cast<T
>(v[1]);
82 this->
mm[2] =
static_cast<T
>(v[2]);
86 T&
x() {
return this->
mm[0]; }
87 T&
y() {
return this->
mm[1]; }
88 T&
z() {
return this->
mm[2]; }
91 T
x()
const {
return this->
mm[0]; }
92 T
y()
const {
return this->
mm[1]; }
93 T
z()
const {
return this->
mm[2]; }
108 this->
mm[0] =
x; this->
mm[1] =
y; this->
mm[2] =
z;
116 this->
mm[0] = 0; this->
mm[1] = 0; this->
mm[2] = 0;
122 template<
typename Source>
134 bool eq(
const Vec3<T> &v, T eps =
static_cast<T
>(1.0e-7))
const
147 template <
typename T0,
typename T1>
150 this->
mm[0] = v1[0] + v2[0];
151 this->
mm[1] = v1[1] + v2[1];
152 this->
mm[2] = v1[2] + v2[2];
159 template <
typename T0,
typename T1>
162 this->
mm[0] = v1[0] - v2[0];
163 this->
mm[1] = v1[1] - v2[1];
164 this->
mm[2] = v1[2] - v2[2];
171 template <
typename T0,
typename T1>
181 template <
typename T0,
typename T1>
195 this->
mm[0]*v.
mm[0] +
196 this->
mm[1]*v.
mm[1] +
203 return static_cast<T
>(sqrt(
double(
204 this->
mm[0]*this->
mm[0] +
205 this->
mm[1]*this->
mm[1] +
206 this->
mm[2]*this->
mm[2])));
215 this->
mm[0]*this->
mm[0] +
216 this->
mm[1]*this->
mm[1] +
217 this->
mm[2]*this->
mm[2];
224 this->mm[2]*v.
mm[0] - this->mm[0]*v.
mm[2],
225 this->mm[0]*v.
mm[1] - this->mm[1]*v.
mm[0]);
234 this->
mm[0] = v1.
mm[1]*v2.
mm[2] - v1.
mm[2]*v2.
mm[1];
235 this->
mm[1] = v1.
mm[2]*v2.
mm[0] - v1.
mm[0]*v2.
mm[2];
236 this->
mm[2] = v1.
mm[0]*v2.
mm[1] - v1.
mm[1]*v2.
mm[0];
241 template <
typename S>
245 const auto value0 = this->
mm[0] * scalar;
246 const auto value1 = this->
mm[1] * scalar;
247 const auto value2 = this->
mm[2] * scalar;
249 this->
mm[0] =
static_cast<T
>(value0);
250 this->mm[1] =
static_cast<T
>(value1);
251 this->mm[2] =
static_cast<T
>(value2);
256 template <
typename S>
259 this->
mm[0] *= v1[0];
260 this->
mm[1] *= v1[1];
261 this->
mm[2] *= v1[2];
266 template <
typename S>
269 this->
mm[0] /= scalar;
270 this->
mm[1] /= scalar;
271 this->
mm[2] /= scalar;
276 template <
typename S>
279 this->
mm[0] /= v1[0];
280 this->
mm[1] /= v1[1];
281 this->
mm[2] /= v1[2];
286 template <
typename S>
290 const auto value0 = this->
mm[0] + scalar;
291 const auto value1 = this->
mm[1] + scalar;
292 const auto value2 = this->
mm[2] + scalar;
294 this->
mm[0] =
static_cast<T
>(value0);
295 this->mm[1] =
static_cast<T
>(value1);
296 this->mm[2] =
static_cast<T
>(value2);
301 template <
typename S>
304 this->
mm[0] += v1[0];
305 this->
mm[1] += v1[1];
306 this->
mm[2] += v1[2];
311 template <
typename S>
314 this->
mm[0] -= scalar;
315 this->
mm[1] -= scalar;
316 this->
mm[2] -= scalar;
321 template <
typename S>
324 this->
mm[0] -= v1[0];
325 this->
mm[1] -= v1[1];
326 this->
mm[2] -= v1[2];
334 this->
mm[0] = std::exp(this->
mm[0]);
335 this->
mm[1] = std::exp(this->
mm[1]);
336 this->
mm[2] = std::exp(this->
mm[2]);
344 this->
mm[0] = std::log(this->
mm[0]);
345 this->
mm[1] = std::log(this->
mm[1]);
346 this->
mm[2] = std::log(this->
mm[2]);
353 return this->
mm[0] + this->
mm[1] + this->
mm[2];
359 return this->
mm[0] * this->
mm[1] * this->
mm[2];
395 return l2 ? *
this /
static_cast<T
>(sqrt(l2)) :
Vec3<T>(1, 0 ,0);
410 return dot(onto)*(T(1)/l);
420 return onto*(
dot(onto)*(T(1)/l));
431 if ( fabs(this->
mm[0]) >= fabs(this->
mm[1]) ) {
433 l = this->
mm[0]*this->
mm[0] + this->
mm[2]*this->
mm[2];
434 l =
static_cast<T
>(T(1)/sqrt(
double(l)));
435 u.
mm[0] = -this->mm[2]*l;
437 u.
mm[2] = +this->mm[0]*l;
440 l = this->
mm[1]*this->
mm[1] + this->
mm[2]*this->
mm[2];
441 l =
static_cast<T
>(T(1)/sqrt(
double(l)));
443 u.
mm[1] = +this->mm[2]*l;
444 u.
mm[2] = -this->mm[1]*l;
454 if( r.
mm[0] > r.
mm[1] ) std::swap(r.
mm[0], r.
mm[1]);
455 if( r.
mm[1] > r.
mm[2] ) std::swap(r.
mm[1], r.
mm[2]);
456 if( r.
mm[0] > r.
mm[1] ) std::swap(r.
mm[0], r.
mm[1]);
473template <
typename T0,
typename T1>
481template <
typename T0,
typename T1>
485template <
typename S,
typename T>
489template <
typename S,
typename T>
498template <
typename T0,
typename T1>
507template <
typename S,
typename T>
514template <
typename S,
typename T>
523template <
typename T0,
typename T1>
531template <
typename T0,
typename T1>
540template <
typename S,
typename T>
549template <
typename T0,
typename T1>
558template <
typename S,
typename T>
572 return static_cast<T
>(atan2(c.
length(), v1.
dot(v2)));
637 std::min(v1.
x(), v2.
x()),
638 std::min(v1.
y(), v2.
y()),
639 std::min(v1.
z(), v2.
z()));
647 std::max(v1.
x(), v2.
x()),
648 std::max(v1.
y(), v2.
y()),
649 std::max(v1.
z(), v2.
z()));
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
#define OPENVDB_IS_POD(Type)
Definition Math.h:56
Definition Exceptions.h:56
Real mm[SIZE]
Definition Tuple.h:165
Vec3< T > sorted() const
Return a vector with the components of this in ascending order.
Definition Vec3.h:451
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Definition Vec3.h:182
Real & x()
Definition Vec3.h:86
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition Vec3.h:160
const Vec3< T > & setZero()
Set "this" vector to zero.
Definition Vec3.h:114
const Vec3< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition Vec3.h:267
Vec3< T > reversed() const
Return the vector (z, y, x)
Definition Vec3.h:461
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition Vec3.h:148
T length() const
Length of the vector.
Definition Vec3.h:201
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
Definition Vec3.h:48
T dot(const Vec3< T > &v) const
Dot product.
Definition Vec3.h:192
const Vec3< T > & operator*=(const Vec3< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
Definition Vec3.h:257
const Vec3< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition Vec3.h:242
T sum() const
Return the sum of all the vector components.
Definition Vec3.h:351
static unsigned numColumns()
Definition Vec3.h:400
const Vec3< T > & operator/=(const Vec3< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
Definition Vec3.h:277
const Vec3< T > & init(T x=0, T y=0, T z=0)
Definition Vec3.h:106
Vec3(T x, T y, T z)
Constructor with three arguments, e.g. Vec3d v(1,2,3);.
Definition Vec3.h:39
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition Vec3.h:382
T * asPointer()
Definition Vec3.h:95
bool eq(const Vec3< T > &v, T eps=static_cast< T >(1.0e-7)) const
Test if "this" vector is equivalent to vector v with tolerance of eps.
Definition Vec3.h:134
static unsigned numRows()
Definition Vec3.h:399
Vec3< T > getArbPerpendicular() const
Definition Vec3.h:426
const Vec3< T > & log()
Definition Vec3.h:342
T & operator()(int i)
Alternative indexed reference to the elements.
Definition Vec3.h:99
Real & y()
Definition Vec3.h:87
T component(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition Vec3.h:405
Vec3(T val)
Construct a vector all of whose components have the given value.
Definition Vec3.h:36
Real & z()
Definition Vec3.h:88
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition Vec3.h:102
T product() const
Return the product of all the vector components.
Definition Vec3.h:357
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
Definition Vec3.h:221
const T * asPointer() const
Definition Vec3.h:96
T lengthSqr() const
Definition Vec3.h:212
Vec3(const Vec3< Other > &v)
Construct a Vec3 from another Vec3 with a possibly different value type.
Definition Vec3.h:78
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
Definition Vec3.h:467
const Vec3< T > & cross(const Vec3< T > &v1, const Vec3< T > &v2)
this = v1 cross v2, v1 and v2 must be distinct objects than "this"
Definition Vec3.h:230
Vec3(Other val, typename std::enable_if< std::is_arithmetic< Other >::value, Conversion >::type=Conversion{})
Construct a vector all of whose components have the given value, which may be of an arithmetic type d...
Definition Vec3.h:69
T x() const
Get the component, e.g. float f = v.y();.
Definition Vec3.h:91
Vec3(const Tuple< 3, Source > &v)
Construct a Vec3 from a 3-Tuple with a possibly different value type.
Definition Vec3.h:58
const Vec3< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition Vec3.h:287
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
Definition Vec3.h:123
T z() const
Definition Vec3.h:93
static Vec3< T > ones()
Definition Vec3.h:468
Vec3< T > unitSafe() const
return normalized this, or (1, 0, 0) if this is null vector
Definition Vec3.h:392
T y() const
Definition Vec3.h:92
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition Vec3.h:143
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
Definition Vec3.h:172
Vec3< T > projection(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition Vec3.h:415
static unsigned numElements()
Definition Vec3.h:401
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition Vec3.h:375
const Vec3< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition Vec3.h:312
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition Vec3.h:363
Real ValueType
Definition Vec3.h:28
const Vec3< T > & operator-=(const Vec3< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
Definition Vec3.h:322
const Vec3< T > & exp()
Definition Vec3.h:332
const Vec3< T > & operator+=(const Vec3< S > &v1)
Add each element of the given vector to the corresponding element of this vector.
Definition Vec3.h:302
Real value_type
Definition Vec3.h:27
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition Vec2.h:528
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition Vec3.h:474
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Definition Vec2.h:476
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition Mat3.h:597
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition Math.h:453
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition Coord.h:554
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition Coord.h:528
Vec3< uint32_t > Vec3ui
Definition Vec3.h:663
Type Exp(const Type &x)
Return ex.
Definition Math.h:710
Vec3< double > Vec3d
Definition Vec3.h:665
Coord Abs(const Coord &xyz)
Definition Coord.h:518
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition Vec2.h:446
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Divide scalar by each element of the given vector and return the result.
Definition Vec2.h:385
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition Vec2.h:504
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition Vec3.h:482
Vec3< int32_t > Vec3i
Definition Vec3.h:662
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition Vec2.h:513
Vec3< float > Vec3s
Definition Vec3.h:664
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
Dummy class for tag dispatch of conversion constructors.
Definition Tuple.h:24
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218