11#ifndef PXR_BASE_GF_VEC3D_H
12#define PXR_BASE_GF_VEC3D_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
31PXR_NAMESPACE_OPEN_SCOPE
51 static const size_t dimension = 3;
73 : x(value), y(value), z(value)
78 constexpr GfVec3d(
double s0,
double s1,
double s2)
86 : x(p[0]), y(p[1]), z(p[2])
138 return Set(a[0], a[1], a[2]);
146 double const *
data()
const {
return &x; }
147 double *
data() {
return &x; }
148 double const *GetArray()
const {
return data(); }
161 return x == other.x &&
165 bool operator!=(
GfVec3d const &other)
const {
166 return !(*
this == other);
214 GfVec3d operator*(
double s)
const {
227 return *
this *= (1.0 / s);
229 GfVec3d operator/(
double s)
const {
230 return *
this * (1.0 / s);
235 return x * v.x + y * v.y + z * v.z;
243 return v * (*
this * v);
257 return *
this * *
this;
277 *
this /= (length > eps) ? length : eps;
283 normalized.Normalize(eps);
299 const bool normalize,
345 template <
class Vec = GfVec2d>
constexpr Vec xy()
const;
346 template <
class Vec = GfVec2d>
constexpr Vec xz()
const;
347 template <
class Vec = GfVec2d>
constexpr Vec yx()
const;
348 template <
class Vec = GfVec2d>
constexpr Vec yz()
const;
349 template <
class Vec = GfVec2d>
constexpr Vec zx()
const;
350 template <
class Vec = GfVec2d>
constexpr Vec zy()
const;
351 template <
class Vec = GfVec3d>
constexpr Vec xyz()
const;
352 template <
class Vec = GfVec3d>
constexpr Vec xzy()
const;
353 template <
class Vec = GfVec3d>
constexpr Vec yxz()
const;
354 template <
class Vec = GfVec3d>
constexpr Vec yzx()
const;
355 template <
class Vec = GfVec3d>
constexpr Vec zxy()
const;
356 template <
class Vec = GfVec3d>
constexpr Vec zyx()
const;
364PXR_NAMESPACE_CLOSE_SCOPE
374PXR_NAMESPACE_OPEN_SCOPE
402 static_assert(std::is_same<Vec, GfVec2d>::value);
410 static_assert(std::is_same<Vec, GfVec2d>::value);
418 static_assert(std::is_same<Vec, GfVec2d>::value);
426 static_assert(std::is_same<Vec, GfVec2d>::value);
434 static_assert(std::is_same<Vec, GfVec2d>::value);
442 static_assert(std::is_same<Vec, GfVec2d>::value);
450 static_assert(std::is_same<Vec, GfVec3d>::value);
458 static_assert(std::is_same<Vec, GfVec3d>::value);
466 static_assert(std::is_same<Vec, GfVec3d>::value);
474 static_assert(std::is_same<Vec, GfVec3d>::value);
482 static_assert(std::is_same<Vec, GfVec3d>::value);
490 static_assert(std::is_same<Vec, GfVec3d>::value);
544 return v.GetNormalized(eps);
573 return delta.
GetLengthSq() <= tolerance * tolerance;
582GfBuildOrthonormalFrame(
GfVec3d const &v0,
592 v1.y * v2.z - v1.z * v2.y,
593 v1.z * v2.x - v1.x * v2.z,
594 v1.x * v2.y - v1.y * v2.x);
611PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 double components.
Basic type for a vector of 3 double components.
GfVec3d operator-() const
Create a vec with negated elements.
GfVec3d & Set(double const *a)
Set all elements with a pointer to data.
GF_API bool operator==(class GfVec3h const &other) const
Equality comparison.
constexpr GfVec3d(double value)
Initialize all elements to a single value.
static GfVec3d ZAxis()
Create a unit vector along the Z-axis.
double GetLengthSq() const
Squared length.
GfVec3d & operator+=(GfVec3d const &other)
Addition.
GF_API void BuildOrthonormalFrame(GfVec3d *v1, GfVec3d *v2, double eps=GF_MIN_VECTOR_LENGTH) const
Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.
constexpr GfVec3d(Scl const *p)
Construct with pointer to values.
GfVec3d & operator*=(double s)
Multiplication by scalar.
GF_API bool operator==(class GfVec3f const &other) const
Equality comparison.
GfVec3d GetProjection(GfVec3d const &v) const
Returns the projection of this onto v.
double const * data() const
Direct data access.
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
double ScalarType
Scalar element type and dimension.
static GfVec3d XAxis()
Create a unit vector along the X-axis.
GfVec3d & operator-=(GfVec3d const &other)
Subtraction.
static GfVec3d YAxis()
Create a unit vector along the Y-axis.
static GfVec3d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec3d & Set(double s0, double s1, double s2)
Set all elements with passed arguments.
bool operator==(GfVec3d const &other) const
Equality comparison.
friend size_t hash_value(GfVec3d const &vec)
Hash.
GfVec3d()=default
GfVec3d value-initializes to zero and performs no default initialization, like float or double.
double const & operator[](size_t i) const
Indexing.
GF_API bool operator==(class GfVec3i const &other) const
Equality comparison.
static GF_API bool OrthogonalizeBasis(GfVec3d *tx, GfVec3d *ty, GfVec3d *tz, const bool normalize, double eps=GF_MIN_ORTHO_TOLERANCE)
Orthogonalize and optionally normalize a set of basis vectors.
GfVec3d GetComplement(GfVec3d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
double GetLength() const
Length.
double operator*(GfVec3d const &v) const
See GfDot().
GfVec3d & operator/=(double s)
Division by scalar.
constexpr GfVec3d(double s0, double s1, double s2)
Initialize all elements with explicit arguments.
Basic type for a vector of 3 float components.
Basic type for a vector of 3 GfHalf components.
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).
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
GF_API std::ostream & operator<<(std::ostream &, GfVec3d const &)
Output a GfVec3d.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
double GfDot(GfVec3d const &v1, GfVec3d const &v2)
Returns the dot (inner) product of two vectors.
GfVec3d operator^(GfVec3d const &v1, GfVec3d const &v2)
Returns the cross product of v1 and v2.
GfVec3d GfGetNormalized(GfVec3d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
double GfNormalize(GfVec3d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
GF_API GfVec3d GfSlerp(double alpha, GfVec3d const &v0, GfVec3d const &v1)
Spherical linear interpolation in three dimensions.
GfVec3d GfCompDiv(GfVec3d const &v1, GfVec3d const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec3d GfGetComplement(GfVec3d const &a, GfVec3d const &b)
Returns the orthogonal complement of a.GetProjection(b).
double GfGetLength(GfVec3d const &v)
Returns the geometric length of v.
GfVec3d GfCompMult(GfVec3d const &v1, GfVec3d const &v2)
Returns component-wise multiplication of vectors v1 and v2.
bool GfIsClose(GfVec3d const &v1, GfVec3d const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfVec3d GfGetProjection(GfVec3d const &a, GfVec3d const &b)
Returns the projection of a onto b.
GfVec3d GfCross(GfVec3d const &v1, GfVec3d const &v2)
Returns the cross product of v1 and v2.