Vec3¶
The Vec3
class template represents a 3D vector, with predefined
typedefs for vectors of type short
, int
, int64_t
,
float
, and double
.
Note that the integer specializations of Vec3
lack the
length()
and normalize()
methods that are present in the
float
and double
versions, because the results don’t fit into
integer quantities.
There are also various utility functions that operate on vectors
defined in ImathVecAlgo.h
and described in Vector Functions.
Example:
#include <Imath/ImathVec.h>
void
vec3_example()
{
Imath::V3f a (1.0f, 2.0f, 3.0f);
Imath::V3f b; // b is uninitialized
b.x = a[0];
b.y = a[1];
b.z = a[2];
assert (a == b);
assert (a.length() == sqrt (a ^ a));
a.normalize();
assert (Imath::equalWithAbsError (a.length(), 1.0f, 1e-6f));
}
-
template <class T>
classVec3
¶ 3-element vector
Subclassed by Imath::Color3< T >, Imath::Euler< T >
Constructors and Assignment
-
Vec3
()¶ Uninitialized by default.
-
constexpr
Vec3
(T a)¶ Initialize to a scalar
(a,a,a)
-
constexpr
Vec3
(T a, T b, T c)¶ Initialize to given elements
(a,b,c)
-
template <class S>
constexprVec3
(const Vec4<S> &v)¶ Vec4 to Vec3 conversion: divide x, y and z by w, even if w is 0.
The result depends on how the environment handles floating-point exceptions.
-
template <class S>
constexprVec3
(const Vec4<S> &v, InfException)¶ Vec4 to Vec3 conversion: divide x, y and z by w.
Throws an exception if w is zero or if division by w would overflow.
-
~Vec3
()¶ Destructor.
Compatibility with Sb
-
template <class S>
voidsetValue
(S a, S b, S c)¶ Set the value.
-
template <class S>
voidgetValue
(S &a, S &b, S &c) const¶ Return the value in
a
,b
, andc
-
T *
getValue
()¶ Return a raw pointer to the array of values.
-
const T *
getValue
() const¶ Return a raw pointer to the array of values.
Arithmetic and Comparison
-
constexpr bool
equalWithAbsError
(const Vec3<T> &v, T e) const¶ Compare two matrices and test if they are “approximately equal”:
- Return
- True if the coefficients of this and
m
are the same with an absolute error of no more than e, i.e., for all i, j:abs (this[i][j] - m[i][j]) <= e
Query and Manipulation
-
T
length
() const¶ Return the Euclidean norm.
-
constexpr T
length2
() const¶ Return the square of the Euclidean norm, i.e.
the dot product with itself.
-
const Vec3<T> &
normalizeNonNull
()¶ Normalize without any checks for length()==0.
Slightly faster than the other normalization routines, but if v.length() is 0.0, the result is undefined.
Numeric Limits
-
static constexpr T
baseTypeLowest
()¶ Largest possible negative value.
-
static constexpr T
baseTypeMax
()¶ Largest possible positive value.
-
static constexpr T
baseTypeSmallest
()¶ Smallest possible positive value.
-
static constexpr T
baseTypeEpsilon
()¶ Smallest possible e for which 1+e != 1.
Public Types
-
typedef T
BaseType
¶ The base type: In templates that accept a parameter
V
, you can refer toT
asV::BaseType
Public Functions
-
constexpr T &
operator[]
(int i)¶ Element access by index.
-
constexpr const T &
operator[]
(int i) const¶ Element access by index.
-
template <>
shortlength
() const
-
template <>
const Vec3<short> &normalize
()
-
template <>
const Vec3<short> &normalizeExc
()
-
template <>
const Vec3<short> &normalizeNonNull
()
-
template <>
Vec3<short>normalized
() const
-
template <>
Vec3<short>normalizedExc
() const
-
template <>
Vec3<short>normalizedNonNull
() const
-
template <>
intlength
() const
-
template <>
const Vec3<int> &normalize
()
-
template <>
const Vec3<int> &normalizeExc
()
-
template <>
const Vec3<int> &normalizeNonNull
()
-
template <>
Vec3<int>normalized
() const
-
template <>
Vec3<int>normalizedExc
() const
-
template <>
Vec3<int>normalizedNonNull
() const
-
template <>
int64_tlength
() const
-
template <>
const Vec3<int64_t> &normalize
()
-
template <>
const Vec3<int64_t> &normalizeExc
()
-
template <>
const Vec3<int64_t> &normalizeNonNull
()
-
template <>
Vec3<int64_t>normalized
() const
-
template <>
Vec3<int64_t>normalizedExc
() const
-
template <>
Vec3<int64_t>normalizedNonNull
() const
Public Static Functions
-
static constexpr unsigned int
dimensions
()¶ Return the number of dimensions, i.e. 3.
-
Warning
doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream& s, const Vec3<T>& v) in doxygen xml output for project “Imath” from directory: doxyxml/. Potential matches:
- std::ostream &operator<<(std::ostream&, Imath::half)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Color4<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Euler<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Interval<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Line3<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix22<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix33<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix44<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Plane3<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Quat<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Shear6<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec2<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec3<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec4<T>&)