28 #ifndef PXR_BASE_GF_VEC3H_H 29 #define PXR_BASE_GF_VEC3H_H 36 #include "pxr/base/gf/api.h" 38 #include "pxr/base/gf/traits.h" 48 PXR_NAMESPACE_OPEN_SCOPE
68 static const size_t dimension = 3;
75 : _data{ value, value, value }
88 : _data{ p[0], p[1], p[2] }
139 return Set(a[0], a[1], a[2]);
145 GfHalf const *GetArray()
const {
return data(); }
158 return _data[0] == other[0] &&
159 _data[1] == other[1] &&
160 _data[2] == other[2];
162 bool operator!=(
GfVec3h const &other)
const {
163 return !(*
this == other);
179 return GfVec3h(-_data[0], -_data[1], -_data[2]);
184 _data[0] += other[0];
185 _data[1] += other[1];
186 _data[2] += other[2];
195 _data[0] -= other[0];
196 _data[1] -= other[1];
197 _data[2] -= other[2];
211 GfVec3h operator*(
double s)
const {
224 return *
this *= (1.0 / s);
226 GfVec3h operator/(
double s)
const {
227 return *
this * (1.0 / s);
232 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
240 return v * (*
this * v);
254 return *
this * *
this;
274 *
this /= (length > eps) ? length : eps;
280 normalized.Normalize(eps);
296 const bool normalize,
305 GfHalf eps = 0.001)
const;
317 PXR_NAMESPACE_CLOSE_SCOPE
323 PXR_NAMESPACE_OPEN_SCOPE
396 return v.GetNormalized(eps);
425 return delta.
GetLengthSq() <= tolerance * tolerance;
434 GfBuildOrthonormalFrame(
GfVec3h const &v0,
444 v1[1] * v2[2] - v1[2] * v2[1],
445 v1[2] * v2[0] - v1[0] * v2[2],
446 v1[0] * v2[1] - v1[1] * v2[0]);
463 PXR_NAMESPACE_CLOSE_SCOPE
465 #endif // PXR_BASE_GF_VEC3H_H GfVec3h GetComplement(GfVec3h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec3h GfCross(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfHalf GfGetLength(GfVec3h const &v)
Returns the geometric length of v.
constexpr GfVec3h(GfHalf value)
Initialize all elements to a single value.
GfHalf const & operator[](size_t i) const
Indexing.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
constexpr GfVec3h(Scl const *p)
Construct with pointer to values.
GfVec3h & operator+=(GfVec3h const &other)
Addition.
pxr_half::half GfHalf
A 16-bit floating point data type.
Assorted mathematical utility functions.
This header serves to simply bring in the half float datatype and provide a hash_value function.
Basic type for a vector of 3 float components.
static GfVec3h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfHalf GfDot(GfVec3h const &v1, GfVec3h const &v2)
Returns the dot (inner) product of two vectors.
GfVec3h & operator-=(GfVec3h const &other)
Subtraction.
Low-level utilities for informing users of various internal and external diagnostic conditions.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
static GfVec3h XAxis()
Create a unit vector along the X-axis.
static GfVec3h ZAxis()
Create a unit vector along the Z-axis.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
GfVec3h & operator *=(double s)
Multiplication by scalar.
GfVec3h & operator/=(double s)
Division by scalar.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
static GfVec3h YAxis()
Create a unit vector along the Y-axis.
GfVec3h operator-() const
Create a vec with negated elements.
GfHalf GetLengthSq() const
Squared length.
GfVec3h GfCompDiv(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec3h GfGetComplement(GfVec3h const &a, GfVec3h const &b)
Returns the orthogonal complement of a.GetProjection(b).
Basic type for a vector of 3 int components.
static GF_API bool OrthogonalizeBasis(GfVec3h *tx, GfVec3h *ty, GfVec3h *tz, const bool normalize, double eps=GF_MIN_ORTHO_TOLERANCE)
Orthogonalize and optionally normalize a set of basis vectors.
GF_API void BuildOrthonormalFrame(GfVec3h *v1, GfVec3h *v2, GfHalf eps=0.001) const
Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.
GfHalf ScalarType
Scalar element type and dimension.
GF_API std::ostream & operator<<(std::ostream &, GfVec3h const &)
Output a GfVec3h.
double GfSqrt(double f)
Return sqrt(f).
GfVec3h & Set(GfHalf s0, GfHalf s1, GfHalf s2)
Set all elements with passed arguments.
GfVec3h GetProjection(GfVec3h const &v) const
Returns the projection of this onto v.
GF_API GfVec3h GfSlerp(double alpha, GfVec3h const &v0, GfVec3h const &v1)
Spherical linear interpolation in three dimensions.
friend size_t hash_value(GfVec3h const &vec)
Hash.
bool GfIsClose(GfVec3h const &v1, GfVec3h const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfVec3h operator^(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfVec3h & Set(GfHalf const *a)
Set all elements with a pointer to data.
Basic type for a vector of 3 double components.
Defines useful mathematical limits.
GfVec3h GfGetProjection(GfVec3h const &a, GfVec3h const &b)
Returns the projection of a onto b.
GfHalf GfNormalize(GfVec3h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec3h GfGetNormalized(GfVec3h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfHalf GetLength() const
Length.
Basic type for a vector of 3 GfHalf components.
GfVec3h()=default
Default constructor does no initialization.
constexpr GfVec3h(GfHalf s0, GfHalf s1, GfHalf s2)
Initialize all elements with explicit arguments.
GfVec3h GfCompMult(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfHalf const * data() const
Direct data access.
bool operator==(GfVec3h const &other) const
Equality comparison.