19 #ifndef __UT_Vector3_h__
20 #define __UT_Vector3_h__
46 template <
typename T,
typename S>
48 template <
typename T,
typename S>
54 template <
typename T,
typename S>
56 template <
typename T,
typename S>
58 template <
typename T,
typename S>
60 template <
typename T,
typename S>
62 template <
typename T,
typename S>
64 template <
typename T,
typename S>
66 template <
typename T,
typename S>
68 template <
typename T,
typename S>
92 template <
typename T,
typename S>
100 template <
typename T,
typename S>
107 template <
typename T,
typename S>
110 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
114 template <
typename T>
118 template <
typename T>
122 template <
typename T>
128 template <
typename T>
131 template <
typename T>
133 template <
typename T>
145 template <
typename T>
156 template <
typename T>
164 template <
typename T>
171 template <
typename T>
178 template <
typename T>
185 template <
typename T>
191 template <
typename T>
197 template <
typename T>
206 using Base::operator=;
207 using Base::operator*=;
219 static constexpr
int tuple_size = 3;
232 Base(Base::CT::CF, vx, vy, vz)
254 template <
typename S>
260 template <
typename S,
bool S_INSTANTIATED>
268 template <
typename S>
270 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2];
return *
this; }
287 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
288 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
289 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
336 template <
typename S>
338 template <
typename S>
341 template <
typename S>
350 template <
typename S>
352 template <
typename S>
360 template <
typename S>
363 template <
typename S>
366 template <
typename S>
369 template <
typename S>
372 template <
typename S>
401 return (
SYSabs(
z()) < ax) ? 2 : 0;
403 return (
SYSabs(
z()) < ay) ? 2 : 1;
409 return (
SYSabs(
z()) >= ax) ? 2 : 0;
411 return (
SYSabs(
z()) >= ay) ? 2 : 1;
435 template <
typename S>
488 T *
t = 0,
T tol = 1e-5)
const;
532 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
539 vec[0] = xx; vec[1] = yy; vec[2] = zz;
544 vec[0]=v[0]; vec[1]=v[1]; vec[2]=v[2];
558 T denom = 1.0f / vec[2];
589 template <
typename S>
594 void save(std::ostream &os,
bool binary =
false)
const;
620 friend std::ostream &operator<<(std::ostream &os, const UT_Vector3T<T> &
v)
632 template <
typename T>
639 template <
typename T>
648 template <
typename T>
655 template <
typename T>
662 template <
typename T,
typename S>
669 template <
typename T>
676 template <
typename T>
683 template <
typename T,
typename S>
690 template <
typename T,
typename S>
697 template <
typename T,
typename S>
704 template <
typename T,
typename S>
711 template <
typename T,
typename S>
718 template <
typename T,
typename S>
723 if ( SYS_IsFloatingPoint_v< T > )
727 T inv =
T(1) / scalar;
733 template <
typename T,
typename S>
740 template <
typename T>
744 return a.vec[0]*
b.vec[0] +
a.vec[1]*
b.vec[1] +
a.vec[2]*
b.vec[2];
747 template <
typename T>
752 a.vec[1]*
b.vec[2] -
a.vec[2]*
b.vec[1],
753 a.vec[2]*
b.vec[0] -
a.vec[0]*
b.vec[2],
754 a.vec[0]*
b.vec[1] -
a.vec[1]*
b.vec[0]
758 template <
typename T>
764 return SYSatan2(v1crossv2.
length(), v1dotv2);
767 template <
typename T>
774 template <
typename T>
785 template <
typename T>
796 template <
typename T,
typename S>
806 template <
typename T>
818 template <
typename T>
830 template <
typename T>
842 template <
typename T>
849 template <
typename T>
856 template <
typename T>
863 template <
typename T>
867 return SYShat(v.
x(), s.
x()) * SYShat(v.
y(), s.
y()) * SYShat(v.
z(), s.
z());
870 template <
typename T>
874 const T xhat = SYShat(v.
x(), s.
x());
875 const T yhat = SYShat(v.
y(), s.
y());
876 const T zhat = SYShat(v.
z(), s.
z());
878 xhat * SYSdhat(v.
y(), s.
y()) * zhat,
879 xhat * yhat * SYSdhat(v.
z(), s.
z()));
882 template <
typename T>
889 template <
typename T>
893 return (v1 - v2).length();
895 template <
typename T>
899 return (v1 - v2).length2();
903 template <
typename T>
913 proj_t = vec.
dot( pos - pt1 );
916 if( proj_t <= (
T)0.0 )
921 else if( proj_t >= veclen2 )
930 vec = (pt1 + (proj_t * vec)) - pos;
933 return dot(vec, vec);
938 template <
typename T>
949 template <
typename T>
963 template <
typename T>
972 du.
x(), dv.
x(), dw.
x(),
973 du.
y(), dv.
y(), dw.
y(),
974 du.
z(), dv.
z(), dw.
z()
977 bool failed =
matrix.solve(orig.
x(), orig.
y(), orig.
z(), output);
979 SYSisGreaterOrEqual(output.
x(), 0) && SYSisLessOrEqual(output.
x(), 1) &&
980 SYSisGreaterOrEqual(output.
y(), 0) && SYSisLessOrEqual(output.
y(), 1) &&
981 SYSisGreaterOrEqual(output.
z(), 0) && SYSisLessOrEqual(output.
z(), 1);
984 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 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 UT_Vector3T(const fpreal32 v[tuple_size]) noexcept
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
UT_Vector3T< T > SYSrecip(const UT_Vector3T< T > &v)
constexpr T dot(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
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.
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
fpreal64 UTangleBetween(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
The angle between two vectors in radians.
UT_Vector3T< T > SYSmin(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise min and maximum.
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.
unsigned hash() const
Compute a hash.
JSON reader class which handles parsing of JSON or bJSON files.
SYS_FORCE_INLINE MF length() const
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Class which writes ASCII or binary JSON streams.
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 T & operator()(unsigned i) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal16 v[tuple_size]) noexcept
constexpr SYS_FORCE_INLINE void operator*=(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that) noexcept
T segmentPointDist2(const UT_Vector3T< T > &pos, const UT_Vector3T< T > &pt1, const UT_Vector3T< T > &pt2)
GLubyte GLubyte GLubyte GLubyte w
SYS_FORCE_INLINE T z() const
void getFrameOfReference(UT_Vector3T< T > &X, UT_Vector3T< T > &Y) const
constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T< T > &v) noexcept
SYS_FORCE_INLINE MF normalize()
SYS_FORCE_INLINE T y() const
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T< S > &v) noexcept
Our own type of any given value_type.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
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))
size_t hash_value(const UT_Vector3T< T > &val)
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)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
static int entries()
Returns the vector size.
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)
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)
constexpr SYS_FORCE_INLINE UT_Vector3T(T v) 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 UT_FixedVector & operator=(const UT_FixedVector &that)=default
#define UT_ASSERT_EXPR_P(ZZ)
UT_Vector3T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector3T< T > &v)
SYS_FORCE_INLINE UT_StorageNum< typename UT_StorageBetter< T, S >::Type >::MathFloat distance(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that) const
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal64 v[tuple_size]) noexcept
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_FixedVector< S, tuple_size, S_INSTANTIATED > &v) noexcept
Arbitrary UT_FixedVector of the same size.
bool SYSisFinite(const UT_Vector3T< T > &v)
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
constexpr SYS_FORCE_INLINE UT_StorageAtLeast32Bit< T, T >::Type length2() const noexcept
UT_FixedVector< T, 3, true > Base
bool SYSequalZero(const UT_Vector3T< T > &v)
SYS_FORCE_INLINE UT_StorageAtLeast32Bit< T, S >::Type dot(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that) const
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.
SYS_FORCE_INLINE T g() const
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 const T * data() const noexcept
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
UT_Vector3T< T > rowVecMult3(const UT_Vector3T< T > &v, const UT_Matrix4T< S > &m)
UT_FixedVector< T, 3 > FixedVectorType
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
UT_Vector3T< T > colVecMult(const UT_Matrix3T< S > &m, const UT_Vector3T< T > &v)
Class to store JSON objects as C++ objects.
SYS_FORCE_INLINE T b() const
SYS_FORCE_INLINE UT_Vector3T()=default
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.
SYS_FORCE_INLINE void normal(const UT_Vector3T< T > &va, const UT_Vector3T< T > &vb)
SYS_FORCE_INLINE void multiplyComponents(const UT_Vector3T< T > &v)
uint64_t multiply(uint64_t lhs, uint64_t rhs)
SYS_FORCE_INLINE T r() const
SYS_FORCE_INLINE T x() const
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.