28 #ifndef PXR_BASE_GF_VEC3D_H 29 #define PXR_BASE_GF_VEC3D_H 36 #include "pxr/base/gf/api.h" 38 #include "pxr/base/gf/traits.h" 41 #include <boost/functional/hash.hpp> 48 PXR_NAMESPACE_OPEN_SCOPE
68 static const size_t dimension = 3;
75 : _data{ value, value, value }
80 constexpr
GfVec3d(
double s0,
double s1,
double s2)
88 : _data{ p[0], p[1], p[2] }
139 return Set(a[0], a[1], a[2]);
143 double const *
data()
const {
return _data; }
144 double *
data() {
return _data; }
145 double const *GetArray()
const {
return data(); }
148 double const &
operator[](
size_t i)
const {
return _data[i]; }
149 double &
operator[](
size_t i) {
return _data[i]; }
154 boost::hash_combine(h, vec[0]);
155 boost::hash_combine(h, vec[1]);
156 boost::hash_combine(h, vec[2]);
162 return _data[0] == other[0] &&
163 _data[1] == other[1] &&
164 _data[2] == other[2];
166 bool operator!=(
GfVec3d const &other)
const {
167 return !(*
this == other);
183 return GfVec3d(-_data[0], -_data[1], -_data[2]);
188 _data[0] += other[0];
189 _data[1] += other[1];
190 _data[2] += other[2];
199 _data[0] -= other[0];
200 _data[1] -= other[1];
201 _data[2] -= other[2];
215 GfVec3d operator*(
double s)
const {
228 return *
this *= (1.0 / s);
230 GfVec3d operator/(
double s)
const {
231 return *
this * (1.0 / s);
236 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
244 return v * (*
this * v);
258 return *
this * *
this;
278 *
this /= (length > eps) ? length : eps;
284 normalized.Normalize(eps);
300 const bool normalize,
321 PXR_NAMESPACE_CLOSE_SCOPE
327 PXR_NAMESPACE_OPEN_SCOPE
400 return v.GetNormalized(eps);
429 return delta.
GetLengthSq() <= tolerance * tolerance;
438 GfBuildOrthonormalFrame(
GfVec3d const &v0,
448 v1[1] * v2[2] - v1[2] * v2[1],
449 v1[2] * v2[0] - v1[0] * v2[2],
450 v1[0] * v2[1] - v1[1] * v2[0]);
467 PXR_NAMESPACE_CLOSE_SCOPE
469 #endif // PXR_BASE_GF_VEC3D_H constexpr GfVec3d(Scl const *p)
Construct with pointer to values.
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
static GfVec3d YAxis()
Create a unit vector along the Y-axis.
GfVec3d operator^(GfVec3d const &v1, GfVec3d const &v2)
Returns the cross product of v1 and v2.
GfVec3d & operator-=(GfVec3d const &other)
Subtraction.
Assorted mathematical utility functions.
double ScalarType
Scalar element type and dimension.
double GetLengthSq() const
Squared length.
GfVec3d GetProjection(GfVec3d const &v) const
Returns the projection of this onto v.
Basic type for a vector of 3 float components.
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...
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,...
GF_API GfVec3d GfSlerp(double alpha, GfVec3d const &v0, GfVec3d const &v1)
Spherical linear interpolation in three dimensions.
GfVec3d GfCross(GfVec3d const &v1, GfVec3d const &v2)
Returns the cross product of v1 and v2.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
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.
GfVec3d & Set(double s0, double s1, double s2)
Set all elements with passed arguments.
double GfDot(GfVec3d const &v1, GfVec3d const &v2)
Returns the dot (inner) product of two vectors.
static GfVec3d ZAxis()
Create a unit vector along the Z-axis.
constexpr GfVec3d(double s0, double s1, double s2)
Initialize all elements with explicit arguments.
GfVec3d GfCompDiv(GfVec3d const &v1, GfVec3d const &v2)
Returns component-wise quotient of vectors v1 and v2.
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.
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.
Basic type for a vector of 3 int components.
double GfSqrt(double f)
Return sqrt(f).
GfVec3d & Set(double const *a)
Set all elements with a pointer to data.
double const * data() const
Direct data access.
GfVec3d & operator/=(double s)
Division by scalar.
double GfNormalize(GfVec3d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec3d & operator+=(GfVec3d const &other)
Addition.
GfVec3d & operator *=(double s)
Multiplication by scalar.
Basic type for a vector of 3 double components.
Defines useful mathematical limits.
GfVec3d()=default
Default constructor does no initialization.
friend size_t hash_value(GfVec3d const &vec)
Hash.
GfVec3d GfGetComplement(GfVec3d const &a, GfVec3d const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec3d GfGetProjection(GfVec3d const &a, GfVec3d const &b)
Returns the projection of a onto b.
GfVec3d GfGetNormalized(GfVec3d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
bool operator==(GfVec3d const &other) const
Equality comparison.
Basic type for a vector of 3 GfHalf components.
constexpr GfVec3d(double value)
Initialize all elements to a single value.
static GfVec3d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
double GetLength() const
Length.
GF_API std::ostream & operator<<(std::ostream &, GfVec3d const &)
Output a GfVec3d.
double const & operator[](size_t i) const
Indexing.
static GfVec3d XAxis()
Create a unit vector along the X-axis.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
GfVec3d GetComplement(GfVec3d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec3d operator-() const
Create a vec with negated elements.