11#ifndef PXR_BASE_GF_VEC3H_H
12#define PXR_BASE_GF_VEC3H_H
19#include "pxr/base/gf/api.h"
21#include "pxr/base/gf/traits.h"
31PXR_NAMESPACE_OPEN_SCOPE
51 static const size_t dimension = 3;
58 : _data{ value, value, value }
71 : _data{ p[0], p[1], p[2] }
122 return Set(a[0], a[1], a[2]);
128 GfHalf const *GetArray()
const {
return data(); }
141 return _data[0] == other[0] &&
142 _data[1] == other[1] &&
143 _data[2] == other[2];
145 bool operator!=(
GfVec3h const &other)
const {
146 return !(*
this == other);
162 return GfVec3h(-_data[0], -_data[1], -_data[2]);
167 _data[0] += other[0];
168 _data[1] += other[1];
169 _data[2] += other[2];
178 _data[0] -= other[0];
179 _data[1] -= other[1];
180 _data[2] -= other[2];
194 GfVec3h operator*(
double s)
const {
207 return *
this *= (1.0 / s);
209 GfVec3h operator/(
double s)
const {
210 return *
this * (1.0 / s);
215 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
223 return v * (*
this * v);
237 return *
this * *
this;
257 *
this /= (length > eps) ? length : eps;
263 normalized.Normalize(eps);
279 const bool normalize,
288 GfHalf eps = 0.001)
const;
300PXR_NAMESPACE_CLOSE_SCOPE
306PXR_NAMESPACE_OPEN_SCOPE
379 return v.GetNormalized(eps);
408 return delta.
GetLengthSq() <= tolerance * tolerance;
417GfBuildOrthonormalFrame(
GfVec3h const &v0,
427 v1[1] * v2[2] - v1[2] * v2[1],
428 v1[2] * v2[0] - v1[0] * v2[2],
429 v1[0] * v2[1] - v1[1] * v2[0]);
446PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 3 double components.
Basic type for a vector of 3 float components.
Basic type for a vector of 3 GfHalf components.
GfVec3h & operator/=(double s)
Division by scalar.
GfHalf operator*(GfVec3h const &v) const
See GfDot().
GfVec3h & operator-=(GfVec3h const &other)
Subtraction.
GfVec3h operator-() const
Create a vec with negated elements.
GfVec3h & operator*=(double s)
Multiplication by scalar.
GF_API bool operator==(class GfVec3d const &other) const
Equality comparison.
GfVec3h & operator+=(GfVec3h const &other)
Addition.
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 GetLength() const
Length.
GF_API bool operator==(class GfVec3f const &other) const
Equality comparison.
GfHalf ScalarType
Scalar element type and dimension.
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.
GfVec3h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GfVec3h GetComplement(GfVec3h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
constexpr GfVec3h(GfHalf value)
Initialize all elements to a single value.
friend size_t hash_value(GfVec3h const &vec)
Hash.
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.
bool operator==(GfVec3h const &other) const
Equality comparison.
GfHalf GetLengthSq() const
Squared length.
static GfVec3h XAxis()
Create a unit vector along the X-axis.
GfVec3h()=default
Default constructor does no initialization.
static GfVec3h ZAxis()
Create a unit vector along the Z-axis.
GfVec3h & Set(GfHalf s0, GfHalf s1, GfHalf s2)
Set all elements with passed arguments.
GfHalf const & operator[](size_t i) const
Indexing.
GfHalf const * data() const
Direct data access.
static GfVec3h YAxis()
Create a unit vector along the Y-axis.
GF_API bool operator==(class GfVec3i const &other) const
Equality comparison.
constexpr GfVec3h(GfHalf s0, GfHalf s1, GfHalf s2)
Initialize all elements with explicit arguments.
static GfVec3h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec3h GetProjection(GfVec3h const &v) const
Returns the projection of this onto v.
Basic type for a vector of 3 int components.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Assorted mathematical utility functions.
double GfSqrt(double f)
Return sqrt(f).
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
This header serves to simply bring in the half float datatype and provide a hash_value function.
pxr_half::half GfHalf
A 16-bit floating point data type.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
GF_API GfVec3h GfSlerp(double alpha, GfVec3h const &v0, GfVec3h const &v1)
Spherical linear interpolation in three dimensions.
GfVec3h GfCompDiv(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfHalf GfGetLength(GfVec3h const &v)
Returns the geometric length of v.
GfVec3h GfGetProjection(GfVec3h const &a, GfVec3h const &b)
Returns the projection of a onto b.
GfVec3h GfGetNormalized(GfVec3h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfHalf GfDot(GfVec3h const &v1, GfVec3h const &v2)
Returns the dot (inner) product of two vectors.
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 GfGetComplement(GfVec3h const &a, GfVec3h const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec3h operator^(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfVec3h GfCompMult(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec3h GfCross(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfHalf GfNormalize(GfVec3h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.