OpenVDB  2.3.0
Vec3.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
33 
34 #include <cmath>
35 #include <openvdb/Exceptions.h>
36 #include "Math.h"
37 #include "Tuple.h"
38 
39 namespace openvdb {
41 namespace OPENVDB_VERSION_NAME {
42 namespace math {
43 
44 template<typename T> class Mat3;
45 
46 template<typename T>
47 class Vec3: public Tuple<3, T>
48 {
49 public:
50  typedef T value_type;
51  typedef T ValueType;
52 
54  Vec3() {}
55 
57  explicit Vec3(T val) { this->mm[0] = this->mm[1] = this->mm[2] = val; }
58 
60  Vec3(T x, T y, T z)
61  {
62  this->mm[0] = x;
63  this->mm[1] = y;
64  this->mm[2] = z;
65  }
66 
68  template <typename Source>
69  Vec3(Source *a)
70  {
71  this->mm[0] = a[0];
72  this->mm[1] = a[1];
73  this->mm[2] = a[2];
74  }
75 
77  template<typename Source>
78  explicit Vec3(const Tuple<3, Source> &v)
79  {
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]);
83  }
84 
85  template<typename Other>
86  Vec3(const Vec3<Other>& v)
87  {
88  this->mm[0] = static_cast<T>(v[0]);
89  this->mm[1] = static_cast<T>(v[1]);
90  this->mm[2] = static_cast<T>(v[2]);
91  }
92 
94  T& x() { return this->mm[0]; }
95  T& y() { return this->mm[1]; }
96  T& z() { return this->mm[2]; }
97 
99  T x() const { return this->mm[0]; }
100  T y() const { return this->mm[1]; }
101  T z() const { return this->mm[2]; }
102 
103  T* asPointer() { return this->mm; }
104  const T* asPointer() const { return this->mm; }
105 
107  T& operator()(int i) { return this->mm[i]; }
108 
110  T operator()(int i) const { return this->mm[i]; }
111 
114  const Vec3<T>& init(T x=0, T y=0, T z=0)
115  {
116  this->mm[0] = x; this->mm[1] = y; this->mm[2] = z;
117  return *this;
118  }
119 
120 
122  const Vec3<T>& setZero()
123  {
124  this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0;
125  return *this;
126  }
127 
129  template<typename Source>
130  const Vec3<T>& operator=(const Vec3<Source> &v)
131  {
132  // note: don't static_cast because that suppresses warnings
133  this->mm[0] = ValueType(v[0]);
134  this->mm[1] = ValueType(v[1]);
135  this->mm[2] = ValueType(v[2]);
136 
137  return *this;
138  }
139 
141  bool eq(const Vec3<T> &v, T eps = static_cast<T>(1.0e-7)) const
142  {
143  return isRelOrApproxEqual(this->mm[0], v.mm[0], eps, eps) &&
144  isRelOrApproxEqual(this->mm[1], v.mm[1], eps, eps) &&
145  isRelOrApproxEqual(this->mm[2], v.mm[2], eps, eps);
146  }
147 
148 
150  Vec3<T> operator-() const { return Vec3<T>(-this->mm[0], -this->mm[1], -this->mm[2]); }
151 
154  template <typename T0, typename T1>
155  const Vec3<T>& add(const Vec3<T0> &v1, const Vec3<T1> &v2)
156  {
157  this->mm[0] = v1[0] + v2[0];
158  this->mm[1] = v1[1] + v2[1];
159  this->mm[2] = v1[2] + v2[2];
160 
161  return *this;
162  }
163 
166  template <typename T0, typename T1>
167  const Vec3<T>& sub(const Vec3<T0> &v1, const Vec3<T1> &v2)
168  {
169  this->mm[0] = v1[0] - v2[0];
170  this->mm[1] = v1[1] - v2[1];
171  this->mm[2] = v1[2] - v2[2];
172 
173  return *this;
174  }
175 
178  template <typename T0, typename T1>
179  const Vec3<T>& scale(T0 scale, const Vec3<T1> &v)
180  {
181  this->mm[0] = scale * v[0];
182  this->mm[1] = scale * v[1];
183  this->mm[2] = scale * v[2];
184 
185  return *this;
186  }
187 
188  template <typename T0, typename T1>
189  const Vec3<T> &div(T0 scale, const Vec3<T1> &v)
190  {
191  this->mm[0] = v[0] / scale;
192  this->mm[1] = v[1] / scale;
193  this->mm[2] = v[2] / scale;
194 
195  return *this;
196  }
197 
199  T dot(const Vec3<T> &v) const
200  {
201  return
202  this->mm[0]*v.mm[0] +
203  this->mm[1]*v.mm[1] +
204  this->mm[2]*v.mm[2];
205  }
206 
208  T length() const
209  {
210  return static_cast<T>(sqrt(double(
211  this->mm[0]*this->mm[0] +
212  this->mm[1]*this->mm[1] +
213  this->mm[2]*this->mm[2])));
214  }
215 
216 
219  T lengthSqr() const
220  {
221  return
222  this->mm[0]*this->mm[0] +
223  this->mm[1]*this->mm[1] +
224  this->mm[2]*this->mm[2];
225  }
226 
228  Vec3<T> cross(const Vec3<T> &v) const
229  {
230  return Vec3<T>(this->mm[1]*v.mm[2] - this->mm[2]*v.mm[1],
231  this->mm[2]*v.mm[0] - this->mm[0]*v.mm[2],
232  this->mm[0]*v.mm[1] - this->mm[1]*v.mm[0]);
233  }
234 
235 
237  const Vec3<T>& cross(const Vec3<T> &v1, const Vec3<T> &v2)
238  {
239  // assert(this!=&v1);
240  // assert(this!=&v2);
241  this->mm[0] = v1.mm[1]*v2.mm[2] - v1.mm[2]*v2.mm[1];
242  this->mm[1] = v1.mm[2]*v2.mm[0] - v1.mm[0]*v2.mm[2];
243  this->mm[2] = v1.mm[0]*v2.mm[1] - v1.mm[1]*v2.mm[0];
244  return *this;
245  }
246 
248  template <typename S>
249  const Vec3<T> &operator*=(S scalar)
250  {
251  this->mm[0] *= scalar;
252  this->mm[1] *= scalar;
253  this->mm[2] *= scalar;
254  return *this;
255  }
256 
258  template <typename S>
259  const Vec3<T> &operator*=(const Vec3<S> &v1)
260  {
261  this->mm[0] *= v1[0];
262  this->mm[1] *= v1[1];
263  this->mm[2] *= v1[2];
264  return *this;
265  }
266 
268  template <typename S>
269  const Vec3<T> &operator/=(S scalar)
270  {
271  this->mm[0] /= scalar;
272  this->mm[1] /= scalar;
273  this->mm[2] /= scalar;
274  return *this;
275  }
276 
278  template <typename S>
279  const Vec3<T> &operator/=(const Vec3<S> &v1)
280  {
281  this->mm[0] /= v1[0];
282  this->mm[1] /= v1[1];
283  this->mm[2] /= v1[2];
284  return *this;
285  }
286 
288  template <typename S>
289  const Vec3<T> &operator+=(S scalar)
290  {
291  this->mm[0] += scalar;
292  this->mm[1] += scalar;
293  this->mm[2] += scalar;
294  return *this;
295  }
296 
298  template <typename S>
299  const Vec3<T> &operator+=(const Vec3<S> &v1)
300  {
301  this->mm[0] += v1[0];
302  this->mm[1] += v1[1];
303  this->mm[2] += v1[2];
304  return *this;
305  }
306 
308  template <typename S>
309  const Vec3<T> &operator-=(S scalar)
310  {
311  this->mm[0] -= scalar;
312  this->mm[1] -= scalar;
313  this->mm[2] -= scalar;
314  return *this;
315  }
316 
318  template <typename S>
319  const Vec3<T> &operator-=(const Vec3<S> &v1)
320  {
321  this->mm[0] -= v1[0];
322  this->mm[1] -= v1[1];
323  this->mm[2] -= v1[2];
324  return *this;
325  }
326 
329  inline const Vec3<T>& exp()
330  {
331  this->mm[0] = std::exp(this->mm[0]);
332  this->mm[1] = std::exp(this->mm[1]);
333  this->mm[2] = std::exp(this->mm[2]);
334  return *this;
335  }
336 
338  inline T sum() const
339  {
340  return this->mm[0] + this->mm[1] + this->mm[2];
341  }
342 
344  bool normalize(T eps = T(1.0e-7))
345  {
346  T d = length();
347  if (isApproxEqual(d, T(0), eps)) {
348  return false;
349  }
350  *this *= (T(1) / d);
351  return true;
352  }
353 
354 
356  Vec3<T> unit(T eps=0) const
357  {
358  T d;
359  return unit(eps, d);
360  }
361 
363  Vec3<T> unit(T eps, T& len) const
364  {
365  len = length();
366  if (isApproxEqual(len, T(0), eps)) {
367  OPENVDB_THROW(ArithmeticError, "Normalizing null 3-vector");
368  }
369  return *this / len;
370  }
371 
372  // Number of cols, rows, elements
373  static unsigned numRows() { return 1; }
374  static unsigned numColumns() { return 3; }
375  static unsigned numElements() { return 3; }
376 
379  T component(const Vec3<T> &onto, T eps=1.0e-7) const
380  {
381  T l = onto.length();
382  if (isApproxEqual(l, T(0), eps)) return 0;
383 
384  return dot(onto)*(T(1)/l);
385  }
386 
389  Vec3<T> projection(const Vec3<T> &onto, T eps=1.0e-7) const
390  {
391  T l = onto.lengthSqr();
392  if (isApproxEqual(l, T(0), eps)) return Vec3::zero();
393 
394  return onto*(dot(onto)*(T(1)/l));
395  }
396 
401  {
402  Vec3<T> u;
403  T l;
404 
405  if ( fabs(this->mm[0]) >= fabs(this->mm[1]) ) {
406  // v.x or v.z is the largest magnitude component, swap them
407  l = this->mm[0]*this->mm[0] + this->mm[2]*this->mm[2];
408  l = static_cast<T>(T(1)/sqrt(double(l)));
409  u.mm[0] = -this->mm[2]*l;
410  u.mm[1] = (T)0.0;
411  u.mm[2] = +this->mm[0]*l;
412  } else {
413  // W.y or W.z is the largest magnitude component, swap them
414  l = this->mm[1]*this->mm[1] + this->mm[2]*this->mm[2];
415  l = static_cast<T>(T(1)/sqrt(double(l)));
416  u.mm[0] = (T)0.0;
417  u.mm[1] = +this->mm[2]*l;
418  u.mm[2] = -this->mm[1]*l;
419  }
420 
421  return u;
422  }
423 
425  bool isNan() const { return isnan(this->mm[0]) || isnan(this->mm[1]) || isnan(this->mm[2]); }
426 
428  bool isInfinite() const
429  {
430  return isinf(this->mm[0]) || isinf(this->mm[1]) || isinf(this->mm[2]);
431  }
432 
434  bool isFinite() const
435  {
436  return finite(this->mm[0]) && finite(this->mm[1]) && finite(this->mm[2]);
437  }
438 
440  static Vec3<T> zero() { return Vec3<T>(0, 0, 0); }
441 };
442 
443 
445 template <typename T0, typename T1>
446 inline bool operator==(const Vec3<T0> &v0, const Vec3<T1> &v1)
447 {
448  return isExactlyEqual(v0[0], v1[0]) && isExactlyEqual(v0[1], v1[1])
449  && isExactlyEqual(v0[2], v1[2]);
450 }
451 
453 template <typename T0, typename T1>
454 inline bool operator!=(const Vec3<T0> &v0, const Vec3<T1> &v1) { return !(v0==v1); }
455 
457 template <typename S, typename T>
458 inline Vec3<typename promote<S, T>::type> operator*(S scalar, const Vec3<T> &v) { return v*scalar; }
459 
461 template <typename S, typename T>
463 {
465  result *= scalar;
466  return result;
467 }
468 
470 template <typename T0, typename T1>
472 {
473  Vec3<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1], v0[2] * v1[2]);
474  return result;
475 }
476 
477 
479 template <typename S, typename T>
481 {
482  return Vec3<typename promote<S, T>::type>(scalar/v[0], scalar/v[1], scalar/v[2]);
483 }
484 
486 template <typename S, typename T>
488 {
490  result /= scalar;
491  return result;
492 }
493 
495 template <typename T0, typename T1>
497 {
498  Vec3<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1], v0[2] / v1[2]);
499  return result;
500 }
501 
503 template <typename T0, typename T1>
505 {
507  result += v1;
508  return result;
509 }
510 
512 template <typename S, typename T>
514 {
516  result += scalar;
517  return result;
518 }
519 
521 template <typename T0, typename T1>
523 {
525  result -= v1;
526  return result;
527 }
528 
530 template <typename S, typename T>
532 {
534  result -= scalar;
535  return result;
536 }
537 
540 template <typename T>
541 inline T angle(const Vec3<T> &v1, const Vec3<T> &v2)
542 {
543  Vec3<T> c = v1.cross(v2);
544  return static_cast<T>(atan2(c.length(), v1.dot(v2)));
545 }
546 
547 template <typename T>
548 inline bool
549 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b)
550 {
551  return a.eq(b);
552 }
553 template <typename T>
554 inline bool
555 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& eps)
556 {
557  return isApproxEqual(a.x(), b.x(), eps.x()) &&
558  isApproxEqual(a.y(), b.y(), eps.y()) &&
559  isApproxEqual(a.z(), b.z(), eps.z());
560 }
561 
564 template <typename T>
565 inline void orthonormalize(Vec3<T> &v1, Vec3<T> &v2, Vec3<T> &v3)
566 {
567  // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
568  // orthonormalization produces vectors u0, u1, and u2 as follows,
569  //
570  // u0 = v0/|v0|
571  // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
572  // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1|
573  //
574  // where |A| indicates length of vector A and A*B indicates dot
575  // product of vectors A and B.
576 
577  // compute u0
578  v1.normalize();
579 
580  // compute u1
581  T d0 = v1.dot(v2);
582  v2 -= v1*d0;
583  v2.normalize();
584 
585  // compute u2
586  T d1 = v2.dot(v3);
587  d0 = v1.dot(v3);
588  v3 -= v1*d0 + v2*d1;
589  v3.normalize();
590 }
591 
596 
598 template <typename T>
599 inline Vec3<T> minComponent(const Vec3<T> &v1, const Vec3<T> &v2)
600 {
601  return Vec3<T>(
602  std::min(v1.x(), v2.x()),
603  std::min(v1.y(), v2.y()),
604  std::min(v1.z(), v2.z()));
605 }
606 
608 template <typename T>
609 inline Vec3<T> maxComponent(const Vec3<T> &v1, const Vec3<T> &v2)
610 {
611  return Vec3<T>(
612  std::max(v1.x(), v2.x()),
613  std::max(v1.y(), v2.y()),
614  std::max(v1.z(), v2.z()));
615 }
616 
619 template <typename T>
620 inline Vec3<T> Exp(Vec3<T> v) { return v.exp(); }
621 
626 
627 } // namespace math
628 } // namespace OPENVDB_VERSION_NAME
629 } // namespace openvdb
630 
631 #endif // OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
632 
633 // Copyright (c) 2012-2013 DreamWorks Animation LLC
634 // All rights reserved. This software is distributed under the
635 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:189
Vec3< T > Exp(Vec3< T > v)
Return a vector with the exponent applied to each of the components of the input vector.
Definition: Vec3.h:620
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:179
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:155
Vec3(const Tuple< 3, Source > &v)
Conversion constructor.
Definition: Vec3.h:78
Vec3< typename promote< S, T >::type > operator+(const Vec3< T > &v, S scalar)
Returns V, where for .
Definition: Vec3.h:513
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
Definition: Vec3.h:69
Vec3< T > projection(const Vec3< T > &onto, T eps=1.0e-7) const
Definition: Vec3.h:389
static unsigned numColumns()
Definition: Vec3.h:374
Vec3(T x, T y, T z)
Constructor with three arguments, e.g. Vec3d v(1,2,3);.
Definition: Vec3.h:60
const Vec3< T > & init(T x=0, T y=0, T z=0)
Definition: Vec3.h:114
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec3.h:110
T & z()
Definition: Vec3.h:96
static unsigned numElements()
Definition: Vec3.h:375
Definition: Exceptions.h:78
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:237
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:344
const Vec3< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec3.h:289
Definition: Mat.h:146
Definition: Tuple.h:50
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec3.h:428
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:446
T sum() const
Return the sum of all the vector components.
Definition: Vec3.h:338
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
Definition: Vec3.h:130
T length() const
Length of the vector.
Definition: Vec3.h:208
T lengthSqr() const
Definition: Vec3.h:219
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:361
const Vec3< T > & exp()
Definition: Vec3.h:329
T * asPointer()
Definition: Vec3.h:103
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
Definition: Vec3.h:440
T component(const Vec3< T > &onto, T eps=1.0e-7) const
Definition: Vec3.h:379
Vec3< T > maxComponent(const Vec3< T > &v1, const Vec3< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec3.h:609
const Vec3< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec3.h:249
T & y()
Definition: Vec3.h:95
Vec3< uint32_t > Vec3ui
Definition: Vec3.h:623
bool isApproxEqual(const Vec3< T > &a, const Vec3< T > &b, const Vec3< T > &eps)
Definition: Vec3.h:555
const T * asPointer() const
Definition: Vec3.h:104
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
Definition: Vec3.h:228
#define OPENVDB_VERSION_NAME
Definition: version.h:45
bool isNan() const
True if a Nan is present in vector.
Definition: Vec3.h:425
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:199
const Vec3< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec3.h:309
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:351
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec3.h:99
T y() const
Definition: Vec3.h:100
Vec3< int32_t > Vec3i
Definition: Vec3.h:622
static unsigned numRows()
Definition: Vec3.h:373
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec3.h:107
T value_type
Definition: Vec3.h:50
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:593
Vec3< typename promote< T0, T1 >::type > operator/(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Returns V, where for .
Definition: Vec3.h:496
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec3.h:363
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:141
Vec3< double > Vec3d
Definition: Vec3.h:625
const Vec3< T > & operator*=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:259
Vec3< float > Vec3s
Definition: Vec3.h:624
const Vec3< T > & setZero()
Set "this" vector to zero.
Definition: Vec3.h:122
Vec3< typename promote< T0, T1 >::type > operator*(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Returns V, where for .
Definition: Vec3.h:471
Vec3< T > minComponent(const Vec3< T > &v1, const Vec3< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec3.h:599
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec3.h:356
const Vec3< T > & operator+=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:299
void orthonormalize(Vec3< T > &v1, Vec3< T > &v2, Vec3< T > &v3)
Definition: Vec3.h:565
Vec3< T > getArbPerpendicular() const
Definition: Vec3.h:400
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:454
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:167
const Vec3< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec3.h:269
Vec3(T val)
Constructor with one argument, e.g. Vec3f v(0);.
Definition: Vec3.h:57
T angle(const Vec3< T > &v1, const Vec3< T > &v2)
Definition: Vec3.h:541
T ValueType
Definition: Vec3.h:51
Vec3< typename promote< S, T >::type > operator-(const Vec3< T > &v, S scalar)
Returns V, where for .
Definition: Vec3.h:531
MatType unit(const MatType &mat, typename MatType::value_type eps=1.0e-8)
Return a copy of the given matrix with its upper 3x3 rows normalized.
Definition: Mat.h:626
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
const Vec3< T > & operator/=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:279
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec3.h:150
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec3.h:434
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:94
T z() const
Definition: Vec3.h:101
const Vec3< T > & operator-=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:319
Vec3(const Vec3< Other > &v)
Definition: Vec3.h:86
Vec3()
Trivial constructor, the vector is NOT initialized.
Definition: Vec3.h:54