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"
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
GfVec3f(
float s0,
float s1,
float s2)
88 : _data{ p[0], p[1], p[2] }
139 return Set(a[0], a[1], a[2]);
143 float const *
data()
const {
return _data; }
144 float *
data() {
return _data; }
145 float const *GetArray()
const {
return data(); }
149 float &
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!=(
GfVec3f const &other)
const {
167 return !(*
this == other);
183 return GfVec3f(-_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 GfVec3f operator*(
double s)
const {
228 return *
this *= (1.0 / s);
230 GfVec3f 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;
279 *
this /= (length > eps) ? length : eps;
285 normalized.Normalize(eps);
301 const bool normalize,
322 PXR_NAMESPACE_CLOSE_SCOPE
328 PXR_NAMESPACE_OPEN_SCOPE
401 return v.GetNormalized(eps);
430 return delta.
GetLengthSq() <= tolerance * tolerance;
439 GfBuildOrthonormalFrame(
GfVec3f const &v0,
449 v1[1] * v2[2] - v1[2] * v2[1],
450 v1[2] * v2[0] - v1[0] * v2[2],
451 v1[0] * v2[1] - v1[1] * v2[0]);
468 PXR_NAMESPACE_CLOSE_SCOPE
470 #endif // PXR_BASE_GF_VEC3F_H
float operator*(GfVec3f const &v) const
See GfDot().
static GfVec3f ZAxis()
Create a unit vector along the Z-axis.
GfVec3f & operator-=(GfVec3f const &other)
Subtraction.
float const * data() const
Direct data access.
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
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.
GfVec3d operator^(GfVec3d const &v1, GfVec3d const &v2)
Returns the cross product of v1 and v2.
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
Assorted mathematical utility functions.
friend size_t hash_value(GfVec3f const &vec)
Hash.
float GetLengthSq() const
Squared length.
Basic type for a vector of 3 float components.
bool operator==(GfVec3f const &other) const
Equality comparison.
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, like GfVec2i, GfVec4d, etc and false for all other types.
GfVec3f()=default
Default constructor does no initialization.
GfVec3d GfCross(GfVec3d const &v1, GfVec3d const &v2)
Returns the cross product of v1 and v2.
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
Spherically linearly interpolate between q0 and q1.
#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.
GfVec3f GetProjection(GfVec3f const &v) const
Returns the projection of this onto v.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
float const & operator[](size_t i) const
Indexing.
static GfVec3f Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
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.
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
GfVec3f & Set(float s0, float s1, float s2)
Set all elements with passed arguments.
Basic type for a vector of 3 int components.
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization. ...
static GfVec3f YAxis()
Create a unit vector along the Y-axis.
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.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
constexpr GfVec3f(Scl const *p)
Construct with pointer to values.
GfVec3f operator-() const
Create a vec with negated elements.
Basic type for a vector of 3 double components.
Defines useful mathematical limits.
GfVec3f & operator/=(double s)
Division by scalar.
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
float GetLength() const
Length.
GfVec3f & operator*=(double s)
Multiplication by scalar.
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.
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
Basic type for a vector of 3 GfHalf components.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately...
GfVec3f GetComplement(GfVec3f const &b) const
Returns the orthogonal complement of this->GetProjection(b).