4 #ifndef OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
12 #include <type_traits>
20 template<
typename T>
class Mat3;
23 class Vec3:
public Tuple<3, T>
46 template <
typename Source>
49 this->
mm[0] =
static_cast<T>(a[0]);
50 this->
mm[1] =
static_cast<T>(a[1]);
51 this->
mm[2] =
static_cast<T>(a[2]);
56 template<
typename Source>
59 this->
mm[0] =
static_cast<T>(v[0]);
60 this->
mm[1] =
static_cast<T>(v[1]);
61 this->
mm[2] =
static_cast<T>(v[2]);
67 template<
typename Other>
71 this->
mm[0] = this->
mm[1] = this->
mm[2] =
static_cast<T>(
val);
76 template<
typename Other>
79 this->
mm[0] =
static_cast<T>(v[0]);
80 this->
mm[1] =
static_cast<T>(v[1]);
81 this->
mm[2] =
static_cast<T>(v[2]);
85 T&
x() {
return this->
mm[0]; }
86 T&
y() {
return this->
mm[1]; }
87 T&
z() {
return this->
mm[2]; }
90 T x()
const {
return this->
mm[0]; }
91 T y()
const {
return this->
mm[1]; }
92 T z()
const {
return this->
mm[2]; }
107 this->
mm[0] =
x; this->
mm[1] =
y; this->
mm[2] =
z;
115 this->
mm[0] = 0; this->
mm[1] = 0; this->
mm[2] = 0;
121 template<
typename Source>
133 bool eq(
const Vec3<T> &
v, T eps = static_cast<T>(1.0e-7))
const
146 template <
typename T0,
typename T1>
149 this->
mm[0] = v1[0] + v2[0];
150 this->
mm[1] = v1[1] + v2[1];
151 this->
mm[2] = v1[2] + v2[2];
158 template <
typename T0,
typename T1>
161 this->
mm[0] = v1[0] - v2[0];
162 this->
mm[1] = v1[1] - v2[1];
163 this->
mm[2] = v1[2] - v2[2];
170 template <
typename T0,
typename T1>
173 this->
mm[0] = scale * v[0];
174 this->
mm[1] = scale * v[1];
175 this->
mm[2] = scale * v[2];
180 template <
typename T0,
typename T1>
194 this->
mm[0]*v.
mm[0] +
195 this->
mm[1]*v.
mm[1] +
202 return static_cast<T>(
sqrt(
double(
203 this->
mm[0]*this->
mm[0] +
204 this->
mm[1]*this->
mm[1] +
205 this->
mm[2]*this->
mm[2])));
214 this->
mm[0]*this->
mm[0] +
215 this->
mm[1]*this->
mm[1] +
216 this->
mm[2]*this->
mm[2];
223 this->
mm[2]*v.
mm[0] - this->
mm[0]*v.
mm[2],
224 this->
mm[0]*v.
mm[1] - this->
mm[1]*v.
mm[0]);
233 this->
mm[0] = v1.
mm[1]*v2.
mm[2] - v1.
mm[2]*v2.
mm[1];
234 this->
mm[1] = v1.
mm[2]*v2.
mm[0] - v1.
mm[0]*v2.
mm[2];
235 this->
mm[2] = v1.
mm[0]*v2.
mm[1] - v1.
mm[1]*v2.
mm[0];
240 template <
typename S>
244 const auto value0 = this->
mm[0] * scalar;
245 const auto value1 = this->
mm[1] * scalar;
246 const auto value2 = this->
mm[2] * scalar;
248 this->
mm[0] =
static_cast<T>(value0);
249 this->mm[1] =
static_cast<T>(value1);
250 this->mm[2] =
static_cast<T>(value2);
255 template <
typename S>
258 this->
mm[0] *= v1[0];
259 this->
mm[1] *= v1[1];
260 this->
mm[2] *= v1[2];
265 template <
typename S>
268 this->
mm[0] /= scalar;
269 this->
mm[1] /= scalar;
270 this->
mm[2] /= scalar;
275 template <
typename S>
278 this->
mm[0] /= v1[0];
279 this->
mm[1] /= v1[1];
280 this->
mm[2] /= v1[2];
285 template <
typename S>
289 const auto value0 = this->
mm[0] + scalar;
290 const auto value1 = this->
mm[1] + scalar;
291 const auto value2 = this->
mm[2] + scalar;
293 this->
mm[0] =
static_cast<T>(value0);
294 this->mm[1] =
static_cast<T>(value1);
295 this->mm[2] =
static_cast<T>(value2);
300 template <
typename S>
303 this->
mm[0] += v1[0];
304 this->
mm[1] += v1[1];
305 this->
mm[2] += v1[2];
310 template <
typename S>
313 this->
mm[0] -= scalar;
314 this->
mm[1] -= scalar;
315 this->
mm[2] -= scalar;
320 template <
typename S>
323 this->
mm[0] -= v1[0];
324 this->
mm[1] -= v1[1];
325 this->
mm[2] -= v1[2];
333 this->
mm[0] = std::exp(this->
mm[0]);
334 this->
mm[1] = std::exp(this->
mm[1]);
335 this->
mm[2] = std::exp(this->
mm[2]);
352 return this->
mm[0] + this->
mm[1] + this->
mm[2];
358 return this->
mm[0] * this->
mm[1] * this->
mm[2];
394 return l2 ? *
this /
static_cast<T>(
sqrt(l2)) :
Vec3<T>(1, 0 ,0);
409 return dot(onto)*(
T(1)/l);
419 return onto*(
dot(onto)*(
T(1)/l));
430 if ( fabs(this->
mm[0]) >= fabs(this->
mm[1]) ) {
432 l = this->
mm[0]*this->
mm[0] + this->
mm[2]*this->
mm[2];
433 l =
static_cast<T>(
T(1)/
sqrt(
double(l)));
434 u.
mm[0] = -this->mm[2]*l;
436 u.
mm[2] = +this->mm[0]*l;
439 l = this->
mm[1]*this->
mm[1] + this->
mm[2]*this->
mm[2];
440 l =
static_cast<T>(
T(1)/
sqrt(
double(l)));
442 u.
mm[1] = +this->mm[2]*l;
443 u.
mm[2] = -this->mm[1]*l;
462 return Vec3<T>(this->
mm[2], this->mm[1], this->mm[0]);
472 template <
typename T0,
typename T1>
480 template <
typename T0,
typename T1>
484 template <
typename S,
typename T>
488 template <
typename S,
typename T>
497 template <
typename T0,
typename T1>
506 template <
typename S,
typename T>
513 template <
typename S,
typename T>
522 template <
typename T0,
typename T1>
530 template <
typename T0,
typename T1>
539 template <
typename S,
typename T>
548 template <
typename T0,
typename T1>
557 template <
typename S,
typename T>
567 template <
typename T>
574 template <
typename T>
580 template <
typename T>
598 template <
typename T>
632 template <
typename T>
642 template <
typename T>
653 template <
typename T>
658 template <
typename T>
675 #endif // OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
SYS_API double atan2(double y, double x)
static unsigned numRows()
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
bool normalize(T eps=T(1.0e-7))
this = normalized this
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
GLsizei const GLfloat * value
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Vec3(const Vec3< Other > &v)
Construct a Vec3 from another Vec3 with a possibly different value type.
vfloat4 sqrt(const vfloat4 &a)
GLdouble GLdouble GLdouble z
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
T sum() const
Return the sum of all the vector components.
GLboolean GLboolean GLboolean GLboolean a
Vec3< T > projection(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
#define OPENVDB_USE_VERSION_NAMESPACE
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Dummy class for tag dispatch of conversion constructors.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec3< T > unitSafe() const
return normalized this, or (1, 0, 0) if this is null vector
**But if you need a result
GLfloat GLfloat GLfloat v2
GLfloat GLfloat GLfloat GLfloat v3
const Vec3< T > & operator+=(S scalar)
Add scalar to each element of this vector.
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
T dot(const Vec3< T > &v) const
Dot product.
T product() const
Return the product of all the vector components.
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.
T x() const
Get the component, e.g. float f = v.y();.
T operator()(int i) const
Alternative indexed constant reference to the elements,.
const Vec3< T > & setZero()
Set "this" vector to zero.
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
#define OPENVDB_IS_POD(Type)
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Vec3< T > reversed() const
Return the vector (z, y, x)
T component(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Coord Abs(const Coord &xyz)
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"
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
const Vec3< T > & operator+=(const Vec3< S > &v1)
Add each element of the given vector to the corresponding element of this vector. ...
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Vec3< T > sorted() const
Return a vector with the components of this in ascending order.
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
GLboolean GLboolean GLboolean b
static unsigned numElements()
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Vec3< T > getArbPerpendicular() const
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
static unsigned numColumns()
const Vec3< T > & operator/=(const Vec3< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
const Vec3< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
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.
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Vec3(T x, T y, T z)
Constructor with three arguments, e.g. Vec3d v(1,2,3);.
Vec3(const Tuple< 3, Source > &v)
Construct a Vec3 from a 3-Tuple with a possibly different value type.
const Vec3< T > & init(T x=0, T y=0, T z=0)
Vec3(T val)
Construct a vector all of whose components have the given value.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
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.
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...
const Vec3< T > & operator-=(const Vec3< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
const Vec3< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
OIIO_FORCEINLINE T log(const T &v)
const Vec3< T > & operator*=(const Vec3< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
const T * asPointer() const
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
const Vec3< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
T length() const
Length of the vector.
#define OPENVDB_THROW(exception, message)
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Type Exp(const Type &x)
Return ex.
T & operator()(int i)
Alternative indexed reference to the elements.