28 #ifndef PXR_BASE_GF_VEC3F_H 29 #define PXR_BASE_GF_VEC3F_H 36 #include "pxr/base/gf/api.h" 38 #include "pxr/base/gf/traits.h" 47 PXR_NAMESPACE_OPEN_SCOPE
67 static const size_t dimension = 3;
74 : _data{ value, value, value }
79 constexpr
GfVec3f(
float s0,
float s1,
float s2)
87 : _data{ p[0], p[1], p[2] }
138 return Set(a[0], a[1], a[2]);
142 float const *
data()
const {
return _data; }
143 float *
data() {
return _data; }
144 float const *GetArray()
const {
return data(); }
148 float &
operator[](
size_t i) {
return _data[i]; }
157 return _data[0] == other[0] &&
158 _data[1] == other[1] &&
159 _data[2] == other[2];
161 bool operator!=(
GfVec3f const &other)
const {
162 return !(*
this == other);
178 return GfVec3f(-_data[0], -_data[1], -_data[2]);
183 _data[0] += other[0];
184 _data[1] += other[1];
185 _data[2] += other[2];
194 _data[0] -= other[0];
195 _data[1] -= other[1];
196 _data[2] -= other[2];
210 GfVec3f operator*(
double s)
const {
223 return *
this *= (1.0 / s);
225 GfVec3f operator/(
double s)
const {
226 return *
this * (1.0 / s);
231 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
239 return v * (*
this * v);
253 return *
this * *
this;
273 *
this /= (length > eps) ? length : eps;
279 normalized.Normalize(eps);
295 const bool normalize,
316 PXR_NAMESPACE_CLOSE_SCOPE
322 PXR_NAMESPACE_OPEN_SCOPE
395 return v.GetNormalized(eps);
424 return delta.
GetLengthSq() <= tolerance * tolerance;
433 GfBuildOrthonormalFrame(
GfVec3f const &v0,
443 v1[1] * v2[2] - v1[2] * v2[1],
444 v1[2] * v2[0] - v1[0] * v2[2],
445 v1[0] * v2[1] - v1[1] * v2[0]);
462 PXR_NAMESPACE_CLOSE_SCOPE
464 #endif // PXR_BASE_GF_VEC3F_H static GfVec3f ZAxis()
Create a unit vector along the Z-axis.
GfVec3f & operator-=(GfVec3f const &other)
Subtraction.
GfVec3f operator-() const
Create a vec with negated elements.
static GF_API bool OrthogonalizeBasis(GfVec3f *tx, GfVec3f *ty, GfVec3f *tz, const bool normalize, double eps=GF_MIN_ORTHO_TOLERANCE)
Orthogonalize and optionally normalize a set of basis vectors.
Assorted mathematical utility functions.
GfVec3f GfGetNormalized(GfVec3f const &v, float eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
friend size_t hash_value(GfVec3f const &vec)
Hash.
GfVec3f GfGetComplement(GfVec3f const &a, GfVec3f const &b)
Returns the orthogonal complement of a.GetProjection(b).
Basic type for a vector of 3 float components.
GfVec3f operator^(GfVec3f const &v1, GfVec3f const &v2)
Returns the cross product of v1 and v2.
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,...
GfVec3f()=default
Default constructor does no initialization.
GF_API std::ostream & operator<<(std::ostream &, GfVec3f const &)
Output a GfVec3f.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
GfVec3f & operator+=(GfVec3f const &other)
Addition.
GfVec3f & Set(float const *a)
Set all elements with a pointer to data.
bool GfIsClose(GfVec3f const &v1, GfVec3f const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
GfVec3f GfGetProjection(GfVec3f const &a, GfVec3f const &b)
Returns the projection of a onto b.
static GfVec3f Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
float const & operator[](size_t i) const
Indexing.
GfVec3f & Set(float s0, float s1, float s2)
Set all elements with passed arguments.
Basic type for a vector of 3 int components.
GF_API GfVec3f GfSlerp(double alpha, GfVec3f const &v0, GfVec3f const &v1)
Spherical linear interpolation in three dimensions.
static GfVec3f YAxis()
Create a unit vector along the Y-axis.
double GfSqrt(double f)
Return sqrt(f).
constexpr GfVec3f(float s0, float s1, float s2)
Initialize all elements with explicit arguments.
static GfVec3f XAxis()
Create a unit vector along the X-axis.
constexpr GfVec3f(float value)
Initialize all elements to a single value.
float GetLengthSq() const
Squared length.
float GfGetLength(GfVec3f const &v)
Returns the geometric length of v.
constexpr GfVec3f(Scl const *p)
Construct with pointer to values.
GfVec3f GfCompMult(GfVec3f const &v1, GfVec3f const &v2)
Returns component-wise multiplication of vectors v1 and v2.
float GetLength() const
Length.
float GfDot(GfVec3f const &v1, GfVec3f const &v2)
Returns the dot (inner) product of two vectors.
float GfNormalize(GfVec3f *v, float eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
Basic type for a vector of 3 double components.
Defines useful mathematical limits.
GfVec3f GfCompDiv(GfVec3f const &v1, GfVec3f const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec3f & operator *=(double s)
Multiplication by scalar.
GfVec3f & operator/=(double s)
Division by scalar.
GfVec3f GfCross(GfVec3f const &v1, GfVec3f const &v2)
Returns the cross product of v1 and v2.
GfVec3f GetProjection(GfVec3f const &v) const
Returns the projection of this onto v.
bool operator==(GfVec3f const &other) const
Equality comparison.
float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
float ScalarType
Scalar element type and dimension.
float const * data() const
Direct data access.
Basic type for a vector of 3 GfHalf components.
GfVec3f GetComplement(GfVec3f const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GF_API void BuildOrthonormalFrame(GfVec3f *v1, GfVec3f *v2, float eps=GF_MIN_VECTOR_LENGTH) const
Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.