19 #ifndef __UT_Vector3_h__
20 #define __UT_Vector3_h__
48 template <
typename T,
typename S>
50 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>
70 template <
typename T,
typename S>
94 template <
typename T,
typename S>
103 template <
typename T,
typename S>
107 template <
typename T>
111 template <
typename T,
typename S>
118 template <
typename T,
typename S>
121 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
125 template <
typename T>
129 template <
typename T>
133 template <
typename T>
139 template <
typename T>
142 template <
typename T>
144 template <
typename T>
150 template <
typename T>
156 template <
typename T>
168 template <
typename T>
182 template <
typename T>
190 template <
typename T>
197 template <
typename T>
204 template <
typename T>
211 template <
typename T>
217 template <
typename T>
224 template <
typename T>
229 static constexpr
int tuple_size = 3;
266 template <
typename S>
274 template <
typename S>
276 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2];
return *
this; }
363 return SYSsqrt( length2() );
438 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
439 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
440 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
487 template <
typename S>
489 template <
typename S>
492 template <
typename S>
501 template <
typename S>
503 template <
typename S>
511 template <
typename S>
514 template <
typename S>
517 template <
typename S>
520 template <
typename S>
523 template <
typename S>
558 return (
SYSabs(
z()) < ax) ? 2 : 0;
560 return (
SYSabs(
z()) < ay) ? 2 : 1;
566 return (
SYSabs(
z()) >= ax) ? 2 : 0;
568 return (
SYSabs(
z()) >= ay) ? 2 : 1;
592 template <
typename S>
645 T *
t = 0,
T tol = 1e-5)
const;
689 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
696 vec[0] = xx; vec[1] = yy; vec[2] = zz;
701 vec[0]=v[0]; vec[1]=v[1]; vec[2]=v[2];
715 T denom = 1.0f / vec[2];
746 template <
typename S>
751 void save(std::ostream &os,
bool binary =
false)
const;
828 friend std::ostream &operator<<(std::ostream &os, const UT_Vector3T<T> &
v)
840 template <
typename T>
847 template <
typename T>
855 template <
typename T>
858 for (
int i = 0; i != tuple_size; ++i )
867 template <
typename T>
874 template <
typename T>
881 template <
typename T,
typename S>
888 template <
typename T>
895 template <
typename T>
902 template <
typename T,
typename S>
909 template <
typename T,
typename S>
916 template <
typename T,
typename S>
923 template <
typename T,
typename S>
930 template <
typename T,
typename S>
937 template <
typename T,
typename S>
942 if ( SYS_IsFloatingPoint_v< T > )
946 T inv =
T(1) / scalar;
952 template <
typename T,
typename S>
959 template <
typename T>
965 template <
typename T>
970 a.vec[1]*
b.vec[2] -
a.vec[2]*
b.vec[1],
971 a.vec[2]*
b.vec[0] -
a.vec[0]*
b.vec[2],
972 a.vec[0]*
b.vec[1] -
a.vec[1]*
b.vec[0]
976 template <
typename T>
982 return SYSatan2(v1crossv2.
length(), v1dotv2);
985 template <
typename T>
992 template <
typename T>
1003 template <
typename T>
1014 template <
typename T,
typename S>
1021 template <
typename T,
typename S>
1031 template <
typename T>
1043 template <
typename T>
1055 template <
typename T>
1067 template <
typename T>
1074 template <
typename T>
1081 template <
typename T>
1088 template <
typename T>
1092 return SYShat(v.
x(), s.
x()) * SYShat(v.
y(), s.
y()) * SYShat(v.
z(), s.
z());
1095 template <
typename T>
1099 const T xhat = SYShat(v.
x(), s.
x());
1100 const T yhat = SYShat(v.
y(), s.
y());
1101 const T zhat = SYShat(v.
z(), s.
z());
1103 xhat * SYSdhat(v.
y(), s.
y()) * zhat,
1104 xhat * yhat * SYSdhat(v.
z(), s.
z()));
1107 template <
typename T>
1114 template <
typename T>
1118 return (v1 - v2).length();
1120 template <
typename T>
1124 return (v1 - v2).length2();
1128 template <
typename T>
1138 proj_t = vec.
dot( pos - pt1 );
1141 if( proj_t <= (
T)0.0 )
1146 else if( proj_t >= veclen2 )
1155 vec = (pt1 + (proj_t * vec)) - pos;
1158 return dot(vec, vec);
1161 template <
typename T>
1170 T proj = vec.
dot(dir_hat);
1174 template <
typename T>
1183 T proj = vec.
dot(dir_hat);
1189 template <
typename T>
1200 template <
typename T>
1214 template <
typename T>
1223 du.
x(), dv.
x(), dw.
x(),
1224 du.
y(), dv.
y(), dw.
y(),
1225 du.
z(), dv.
z(), dw.
z()
1228 bool failed = matrix.
solve(orig.
x(), orig.
y(), orig.
z(), output);
1230 SYSisGreaterOrEqual(output.
x(), 0) && SYSisLessOrEqual(output.
x(), 1) &&
1231 SYSisGreaterOrEqual(output.
y(), 0) && SYSisLessOrEqual(output.
y(), 1) &&
1232 SYSisGreaterOrEqual(output.
z(), 0) && SYSisLessOrEqual(output.
z(), 1);
1235 template <
typename T>
1242 template<
typename T>
1245 template<
typename T, ex
int D >
1248 template<
typename T>
1259 template<
typename T >
1262 template<
typename T >
1265 template<
typename T >
1272 template <
typename T>
1275 template<
typename TS >
1285 template <
typename V >
1289 template <
typename T>
1296 template <
typename T>
1299 template<
typename TS >
1311 template<
typename TS >
1323 template <
typename V >
1327 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)
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_FromUnbounded creates a V from an unbounded array-like type.
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)
constexpr SYS_FORCE_INLINE T & y() noexcept
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
friend constexpr auto length2(const UT_Vector3T &a) noexcept
GLdouble GLdouble GLdouble z
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.
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.
GLboolean GLboolean GLboolean GLboolean a
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)
constexpr SYS_FORCE_INLINE UT_Vector3T< T > operator()(const TS &as) const noexcept
Class which writes ASCII or binary JSON streams.
constexpr SYS_FORCE_INLINE T length() const noexcept
static const exint TupleSize
GLfloat GLfloat GLfloat v2
constexpr auto 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 > 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 & x() 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)
constexpr SYS_FORCE_INLINE T & x() noexcept
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)
constexpr SYS_FORCE_INLINE T & z() noexcept
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
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
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
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.
T rayPointDist2(const UT_Vector3T< T > &pos, const UT_Vector3T< T > &orig, const UT_Vector3T< T > &dir)
GLboolean GLboolean GLboolean 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
constexpr SYS_FORCE_INLINE bool isNan() const noexcept
int solve(T cx, T cy, T cz, UT_Vector3T< S > &result) const
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
friend constexpr auto distance2(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Compute the distance squared.
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
LeafData & operator=(const LeafData &)=delete
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
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
bool SYSisEqual(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
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
GLubyte GLubyte GLubyte GLubyte w
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
SIM_API const UT_StringHolder distance
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)
constexpr SYS_FORCE_INLINE T & y() noexcept
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.
T linePointDist2(const UT_Vector3T< T > &pos, const UT_Vector3T< T > &orig, const UT_Vector3T< T > &dir)
constexpr SYS_FORCE_INLINE T & x() noexcept