19 #ifndef __UT_Vector3_h__
20 #define __UT_Vector3_h__
49 template <
typename T,
typename S>
51 template <
typename T,
typename S>
57 template <
typename T,
typename S>
59 template <
typename T,
typename S>
61 template <
typename T,
typename S>
63 template <
typename T,
typename S>
65 template <
typename T,
typename S>
67 template <
typename T,
typename S>
69 template <
typename T,
typename S>
71 template <
typename T,
typename S>
101 template <
typename T,
typename S>
105 template <
typename T>
109 template <
typename T,
typename S>
116 template <
typename T,
typename S>
119 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
123 template <
typename T>
127 template <
typename T>
131 template <
typename T>
137 template <
typename T>
140 template <
typename T>
142 template <
typename T>
154 template <
typename T>
168 template <
typename T>
176 template <
typename T>
183 template <
typename T>
190 template <
typename T>
197 template <
typename T>
203 template <
typename T>
210 template <
typename T>
215 static constexpr
int tuple_size = 3;
252 template <
typename S>
265 template <
typename S>
267 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2];
return *
this; }
354 return SYSsqrt( length2() );
429 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
430 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
431 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
478 template <
typename S>
480 template <
typename S>
483 template <
typename S>
492 template <
typename S>
494 template <
typename S>
502 template <
typename S>
505 template <
typename S>
508 template <
typename S>
511 template <
typename S>
514 template <
typename S>
526 operator=(::
cross(*
this,
v));
548 return (
SYSabs(
z()) < ax) ? 2 : 0;
550 return (
SYSabs(
z()) < ay) ? 2 : 1;
556 return (
SYSabs(
z()) >= ax) ? 2 : 0;
558 return (
SYSabs(
z()) >= ay) ? 2 : 1;
582 template <
typename S>
635 T *
t = 0,
T tol = 1e-5)
const;
679 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
686 vec[0] = xx; vec[1] = yy; vec[2] = zz;
691 vec[0]=v[0]; vec[1]=v[1]; vec[2]=v[2];
705 T denom = 1.0f / vec[2];
736 template <
typename S>
741 void save(std::ostream &os,
bool binary =
false)
const;
818 friend std::ostream &operator<<(std::ostream &os, const UT_Vector3T<T> &
v)
830 template <
typename T>
837 template <
typename T>
845 template <
typename T>
848 for (
int i = 0; i != tuple_size; ++i )
857 template <
typename T>
864 template <
typename T>
871 template <
typename T,
typename S>
878 template <
typename T>
885 template <
typename T>
892 template <
typename T,
typename S>
899 template <
typename T,
typename S>
906 template <
typename T,
typename S>
913 template <
typename T,
typename S>
920 template <
typename T,
typename S>
927 template <
typename T,
typename S>
932 if ( SYS_IsFloatingPoint_v< T > )
936 T inv =
T(1) / scalar;
942 template <
typename T,
typename S>
949 template <
typename T>
955 template <
typename T>
960 a.vec[1]*
b.vec[2] -
a.vec[2]*
b.vec[1],
961 a.vec[2]*
b.vec[0] -
a.vec[0]*
b.vec[2],
962 a.vec[0]*
b.vec[1] -
a.vec[1]*
b.vec[0]
966 template <
typename T>
972 return SYSatan2(v1crossv2.
length(), v1dotv2);
975 template <
typename T>
982 template <
typename T>
993 template <
typename T>
1004 template <
typename T,
typename S>
1014 template <
typename T>
1026 template <
typename T>
1038 template <
typename T>
1050 template <
typename T>
1057 template <
typename T>
1064 template <
typename T>
1071 template <
typename T>
1075 return SYShat(v.
x(), s.
x()) * SYShat(v.
y(), s.
y()) * SYShat(v.
z(), s.
z());
1078 template <
typename T>
1082 const T xhat = SYShat(v.
x(), s.
x());
1083 const T yhat = SYShat(v.
y(), s.
y());
1084 const T zhat = SYShat(v.
z(), s.
z());
1086 xhat * SYSdhat(v.
y(), s.
y()) * zhat,
1087 xhat * yhat * SYSdhat(v.
z(), s.
z()));
1090 template <
typename T>
1097 template <
typename T>
1101 return (v1 - v2).length();
1103 template <
typename T>
1107 return (v1 - v2).length2();
1111 template <
typename T>
1121 proj_t = vec.
dot( pos - pt1 );
1124 if( proj_t <= (
T)0.0 )
1129 else if( proj_t >= veclen2 )
1138 vec = (pt1 + (proj_t * vec)) - pos;
1141 return dot(vec, vec);
1146 template <
typename T>
1157 template <
typename T>
1171 template <
typename T>
1180 du.
x(), dv.
x(), dw.
x(),
1181 du.
y(), dv.
y(), dw.
y(),
1182 du.
z(), dv.
z(), dw.
z()
1185 bool failed =
matrix.solve(orig.
x(), orig.
y(), orig.
z(), output);
1187 SYSisGreaterOrEqual(output.
x(), 0) && SYSisLessOrEqual(output.
x(), 1) &&
1188 SYSisGreaterOrEqual(output.
y(), 0) && SYSisLessOrEqual(output.
y(), 1) &&
1189 SYSisGreaterOrEqual(output.
z(), 0) && SYSisLessOrEqual(output.
z(), 1);
1192 template <
typename T>
1199 template<
typename T>
1202 template<
typename T, ex
int D >
1205 template<
typename T>
1216 template<
typename T >
1219 template<
typename T >
1222 template<
typename T >
1228 template <
typename T>
1231 template<
typename TS >
1243 template<
typename TS >
1255 template <
typename V >
1259 template <
typename T>
UT_Vector3T< T > rowVecMult(const UT_Vector3T< T > &v, const UT_Matrix3T< S > &m)
UT_Vector3T< T > SYSlerp(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2, S t)
Componentwise linear interpolation.
constexpr SYS_FORCE_INLINE T length2() const noexcept
constexpr SYS_FORCE_INLINE T operator()(unsigned i) const noexcept
UT_API double intersectLines(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &p2, const UT_Vector3T< T > &v2, T &t1, T &t2)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
constexpr UT_Vector3T< T > cross(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
GLboolean GLboolean GLboolean b
constexpr SYS_FORCE_INLINE UT_Vector3T(const int32 v[tuple_size]) noexcept
constexpr SYS_FORCE_INLINE T dot(const UT_Vector3T &b) const noexcept
typename UT_StorageNum< T >::MathFloat UT_StorageMathFloat_t
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal32 v[tuple_size]) noexcept
#define SYS_STATIC_ASSERT(expr)
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
friend constexpr bool isZero(const UT_Vector3T &a) noexcept
UT_Vector3T< T > SYSrecip(const UT_Vector3T< T > &v)
constexpr SYS_FORCE_INLINE UT_Vector3T< T > operator()(const TS &as) const noexcept
UT_Vector3T< T > SYSbilerp(const UT_Vector3T< T > &u0v0, const UT_Vector3T< T > &u1v0, const UT_Vector3T< T > &u0v1, const UT_Vector3T< T > &u1v1, S u, S v)
Bilinear interpolation.
T distance2(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance squared.
T distance3d(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance between two points.
constexpr SYS_FORCE_INLINE T y() const noexcept
int UTinverseTrilerpFlat(const UT_Vector3T< T > &input, const UT_Vector3T< T > &p0, const UT_Vector3T< T > &du, const UT_Vector3T< T > &dv, const UT_Vector3T< T > &dw, UT_Vector3T< T > &output)
UT_Vector3T< T > SYSabs(const UT_Vector3T< T > &v)
constexpr SYS_FORCE_INLINE UT_Vector3T(const int64 v[tuple_size]) noexcept
void assign(const T *v)
Set the values of the vector components.
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
GLenum GLenum GLenum input
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
fpreal64 UTangleBetween(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
The angle between two vectors in radians.
friend constexpr T distance2(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Compute the distance squared.
constexpr SYS_FORCE_INLINE T & z() noexcept
UT_Vector3T< T > SYSmin(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise min and maximum.
constexpr bool SYSisNan(const F f)
T segmentDistance(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
Returns the distance between two line segments: p0-p1 and a-b.
constexpr SYS_FORCE_INLINE UT_Vector3T & operator-=(const T &a) noexcept
unsigned hash() const
Compute a hash.
constexpr SYS_FORCE_INLINE T b() const noexcept
JSON reader class which handles parsing of JSON or bJSON files.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Class which writes ASCII or binary JSON streams.
constexpr SYS_FORCE_INLINE T length() const noexcept
static const exint TupleSize
UT_Vector3T< T > SYStrihatgrad(const UT_Vector3T< T > &v, const UT_Vector3T< T > &s)
Gradient of trilinear hat function over kernel widths in s.
T SYStrihat(const UT_Vector3T< T > &v, const UT_Vector3T< T > &s)
Trilinear hat function over kernel widths in s.
constexpr SYS_FORCE_INLINE UT_Vector3T & operator*=(const T &a) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const T v) noexcept
constexpr SYS_FORCE_INLINE T & operator()(unsigned i) noexcept
constexpr SYS_FORCE_INLINE const T * data() const noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal16 v[tuple_size]) noexcept
friend constexpr bool operator>(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
T segmentPointDist2(const UT_Vector3T< T > &pos, const UT_Vector3T< T > &pt1, const UT_Vector3T< T > &pt2)
GLubyte GLubyte GLubyte GLubyte w
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_FixedVector< T, tuple_size > &v) noexcept
UT_FixedVector of the same size.
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
void getFrameOfReference(UT_Vector3T< T > &X, UT_Vector3T< T > &Y) const
constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T< T > &v) noexcept
constexpr SYS_FORCE_INLINE T & operator[](exint i) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T< S > &v) noexcept
Our own type of any given value_type.
constexpr UT_Vector3T< T > operator/(const UT_Vector3T< T > &v, S scalar) noexcept
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
UT_API UT_Vector2T< T > segmentClosest(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
GLfloat GLfloat GLfloat v2
GLsizei GLsizei GLfloat distance
void clampZero(T tol=T(0.00001f))
typename UT_StorageAtLeast32Bit< T0, T1 >::type UT_StorageAtLeast32Bit_t
constexpr SYS_FORCE_INLINE void negate() noexcept
constexpr SYS_FORCE_INLINE const T & operator[](exint i) const noexcept
friend constexpr bool operator<(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T & operator-=(const UT_Vector3T &a) noexcept
size_t hash_value(const UT_Vector3T< T > &val)
constexpr SYS_FORCE_INLINE T x() const noexcept
static const bool isVectorType
GLboolean GLboolean GLboolean GLboolean a
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
typename Dot< T, SIZE >::R DotReturn_t
static int entries()
Returns the vector size.
constexpr SYS_FORCE_INLINE UT_Vector3T & operator+=(const T &a) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const T vx, const T vy, const T vz) noexcept
GLdouble GLdouble GLdouble z
UT_Vector3T< T > SYSmax(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
constexpr SYS_FORCE_INLINE T & r() noexcept
UT_Vector3T< T > SYSbarycentric(const UT_Vector3T< T > &v0, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2, S u, S v)
Barycentric interpolation.
UT_API UT_Vector2T< T > segmentClosestParallel(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
friend constexpr bool operator==(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
T segmentDistance2(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
Returns the squared distance between two line segments: p0-p1 and a-b.
constexpr SYS_FORCE_INLINE T & g() noexcept
UT_Vector3T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector3T< T > &v)
constexpr SYS_FORCE_INLINE UT_Vector3T & operator*=(const UT_Vector3T &a) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal64 v[tuple_size]) noexcept
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
constexpr SYS_FORCE_INLINE UT_Vector3T & operator/=(const UT_Vector3T &a) noexcept
friend constexpr T length2(const UT_Vector3T &a) noexcept
constexpr UT::FA::DotReturn_t< T, 3 > dot(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
constexpr SYS_FORCE_INLINE bool isNan() const noexcept
constexpr SYS_FORCE_INLINE T g() const noexcept
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
bool SYSisFinite(const UT_Vector3T< T > &v)
bool SYSequalZero(const UT_Vector3T< T > &v)
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f)
Set the values of the vector components.
SYS_FORCE_INLINE UT_Vector3T< T > & operator=(const UT_Vector3T< S > &v)
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
UT_Vector3T< T > SYSinvlerp(const UT_Vector3T< T > &a, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise inverse linear interpolation.
constexpr SYS_FORCE_INLINE T r() const noexcept
bool SYSisInteger(const UT_Vector3T< T > &v1)
Componentwise integer test.
UT_API bool intersectSegments(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b, T &t)
constexpr SYS_FORCE_INLINE UT_Vector3T< T > operator-() const noexcept
constexpr SYS_FORCE_INLINE T distance2(const UT_Vector3T &b) const noexcept
UT_Vector3T< T > rowVecMult3(const UT_Vector3T< T > &v, const UT_Matrix4T< S > &m)
constexpr UT_Vector3T< SYS_FixedArrayElement_t< TS > > UTmakeVector3T(const TS &as) noexcept
constexpr SYS_FORCE_INLINE T & b() noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T & operator+=(const UT_Vector3T &a) noexcept
UT_FixedVector< T, 3 > FixedVectorType
constexpr SYS_FORCE_INLINE UT_Vector3T< T > & operator=(const UT_Vector3T< T > &that)=default
constexpr SYS_FORCE_INLINE bool isEqual(const UT_Vector3T &b, const T tolerance=SYS_FTOLERANCE) const noexcept
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
UT_Vector3T< T > colVecMult(const UT_Matrix3T< S > &m, const UT_Vector3T< T > &v)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Class to store JSON objects as C++ objects.
constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
constexpr SYS_FORCE_INLINE T distance(const UT_Vector3T &b) const noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T & operator/=(const T &a) noexcept
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
SYS_FORCE_INLINE UT_Vector3T()=default
friend constexpr bool operator<=(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
friend constexpr bool operator>=(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
UT_Vector3T< T > project(const UT_Vector3T< T > &u, const UT_Vector3T< T > &v)
The orthogonal projection of a vector u onto a vector v.
constexpr SYS_FORCE_INLINE T z() const noexcept
SYS_FORCE_INLINE void normal(const UT_Vector3T< T > &va, const UT_Vector3T< T > &vb)
constexpr SYS_FORCE_INLINE T * data() noexcept
constexpr SYS_FORCE_INLINE T & y() noexcept
SYS_FORCE_INLINE void multiplyComponents(const UT_Vector3T< T > &v)
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
constexpr SYS_FORCE_INLINE bool equalZero(const T tolerance=SYS_FTOLERANCE) const noexcept
friend constexpr bool operator!=(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
uint64_t multiply(uint64_t lhs, uint64_t rhs)
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector3T< T > &v)
fpreal64 angleTo(const UT_Vector3T< T > &v) const
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
constexpr SYS_FORCE_INLINE T & x() noexcept