geomc 1.0
A c++ linear algebra template library
|
A tuple of N
elements of type T
.
More...
#include <geomc/linalg/Vec.h>
Public Types | |
typedef Vec< T, N > | self_t |
Self type. I.e., Vec<T,N> if a vector, Quat<T> if a quaternion. | |
typedef T | elem_t |
Element type. | |
Public Member Functions | |
constexpr | Vec () |
constexpr | Vec (T a) |
constexpr | Vec (const T a[N]) |
template<typename U > | |
constexpr | Vec (const Vec< U, N-1 > &v, T a) |
template<typename Mx , typename Ref > | |
Vec (detail::MtxColIterator< Mx, Ref > mtx_col) | |
const T & | operator[] (index_t idx) const |
Vector element access. More... | |
T & | operator[] (index_t idx) |
Vector element access. More... | |
operator Vec< U, N > () const | |
Element typecast. More... | |
bool | operator== (const self_t &vv) const |
Equality test. More... | |
bool | operator!= (const self_t &vv) const |
Inequality test. More... | |
self_t | operator+ (const self_t &v) const |
Element-wise addition. | |
self_t & | operator+= (const self_t &vv) |
Element-wise addition and assignment. | |
self_t | operator- (const self_t &v) const |
Element-wise subtraction. | |
self_t | operator- () const |
Negation. More... | |
self_t & | operator-= (const self_t &vv) |
Subtraction and assignment. | |
self_t & | operator*= (T s) |
Scalar multiplication and assignment. | |
self_t & | operator*= (const self_t &vv) |
Element-wise multiplication and assignment. | |
self_t & | operator/= (T s) |
Scalar division and assignment. | |
self_t | add (const self_t &v) const |
Vector addition. More... | |
self_t | sub (const self_t &v) const |
Vector subtraction. More... | |
self_t | scale (const self_t &v) const |
Element-wise multiplication. More... | |
self_t | scale (T a) const |
Scalar multiple. More... | |
self_t | unit () const |
Vector normalization. More... | |
T | dot (const self_t &v) const |
Dot product. More... | |
T | mag () const |
Euclidean norm (magnitude). More... | |
T | mag2 () const |
Squared magnitude. More... | |
T | dist (const self_t &pt) const |
Distance between points. More... | |
T | dist2 (const self_t &pt) const |
Distance squared to a point. More... | |
self_t | reflect_about (self_t normal) const |
Reflection about a normal. More... | |
self_t | bounce_on (const self_t &normal) const |
Elastic collision. More... | |
self_t | project_on (const self_t &axis) const |
Orthogonal projection to an axis. More... | |
T | fraction_on (const self_t &axis) const |
Return the component of this that projects to axis , as a fraction of axis's length. More... | |
self_t | with_length (T mag) const |
Compute a vector with the direction of this and a new magnitude mag . More... | |
self_t | mix (const self_t &v, T mix) const |
Linear interpolation. More... | |
T | angle_to (const self_t &v) const |
Angle between vectors. More... | |
self_t | abs () const |
Element-wise absolute value. More... | |
self_t | floor () const |
Element-wise floor function. More... | |
self_t | ceil () const |
Element-wise ceiling function. More... | |
self_t | min (const self_t &v) const |
Element-wise minimum of two Vec s. More... | |
T | min () const |
Minimum element. More... | |
self_t | max (const self_t &v) const |
Element-wise maximum of two Vec s. More... | |
T | max () const |
Maximum element. More... | |
self_t | clamp (const self_t &lo, const self_t &hi) const |
Element-wise clamp. More... | |
self_t | round () const |
Round each element to the nearest integer. | |
index_t | argmax () const |
Return the index of the coordinate with the largest absolute value. | |
index_t | argmin () const |
Return the index of the coordinate with the smallest absolute value. | |
PointType< T, M >::point_t | resized () const |
Resized copy of a vector. More... | |
bool | is_zero () const |
Return true if all elements are zero. | |
index_t | size () const |
The number of elements in this vector. Always equal to N . | |
const T & | get (index_t idx) const |
T & | get (index_t idx) |
const T * | begin () const |
T * | begin () |
const T * | end () const |
T * | end () |
Static Public Attributes | |
static constexpr index_t | DIM |
Vector dimension. | |
static const self_t | ones |
static const self_t | zeros |
Protected Attributes | |
T | v [N] |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T , index_t N, typename U > | |
Vec< T, N > | operator* (const Vec< T, N > &v, U d) |
template<typename T , index_t N, typename U > | |
Vec< T, N > | operator* (U d, const Vec< T, N > &v) |
template<typename T , index_t N> | |
const Vec< T, N > | operator* (const Vec< T, N > &a, const Vec< T, N > &b) |
template<typename T , index_t N, typename U > | |
Vec< T, N > | operator/ (const Vec< T, N > &v, U d) |
template<typename T , index_t N, typename U > | |
Vec< T, N > | operator/ (const Vec< T, N > &v, U d) |
template<typename T , index_t N> | |
const Vec< T, N > | operator/ (const Vec< T, N > &a, const Vec< T, N > &b) |
template<typename T , index_t N> | |
geom::Vec< T, N > | max (const geom::Vec< T, N > &a, const geom::Vec< T, N > &b) |
template<typename T , index_t N> | |
geom::Vec< T, N > | min (const geom::Vec< T, N > &a, const geom::Vec< T, N > &b) |
template<typename T , index_t N> | |
geom::Vec< T, N > | abs (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | floor (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | ceil (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | sqrt (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | sin (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | cos (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | tan (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | exp (const geom::Vec< T, N > &v) |
template<typename T , index_t N> | |
geom::Vec< T, N > | log (const geom::Vec< T, N > &v) |
A tuple of N
elements of type T
.
Vectors are lightweight and generally perform as well as a bare array of their element type.
Geomc makes no type distinction between vectors, points, or normals; the distinction is to be made by the programmer based on usage.
Declaring a 3-dimensional vector of doubles:
Vec<double,3> v;
Basic arithmetic:
v3 = v1 + v2; // addition v3 = v1 - v2; // subtraction v3 = -v1; // negation v3 = 2.71 * v1; // scalar mult v3 = 1.61 / v1; // scalar div v3 = v1 / 1.41; // scalar div
Element-wise multiplication / division:
v3 = v1 * v2; v3 = v2 / v1;
Element access:
double z = v[2]; z = v.get(2);
Access to / iteration over internal array:
for (double *p = v.begin(); p != v.end(); p++) { double a = f(*p, ...); }
Cross product (3D only):
v3 = v1 ^ v2;
Compatibility with std:
// element-wise operations std::min(v1, v2); std::max(v1, v2); std::abs(v1); std::floor(v1); std::ceil(v1);
Resizing:
Vec<double,3> v3d; Vec<double,2> v2d = v3d.resized<2>(); // truncate the last coordinate Vec<double,4> v4d = v3d.resized<4>(); // last coordinate is zero
|
inlineconstexpr |
Construct a new vector with all elements set to zero.
|
inlineconstexpr |
Construct a new vector with all elements set to the value of a
.
a | Scalar value |
|
inlineconstexpr |
Construct a new vector with elements copied from a
.
a | An array of length N . |
Construct a new vector with the elements from v
, with a
as the last element.
v | A vector of dimension N - 1 |
a | The value of the last element |
|
inline |
Construct a vector from a column of a matrix.
mtx_col | A matrix column iterator (obtained via mtx.col(i) ). |
|
inlineinherited |
Element-wise absolute value.
x
such that x[i] = abs(this[i])
. Vector addition.
v | Another vector. |
x
such that x[i] = this[i] + v[i]
.
|
inlineinherited |
Angle between vectors.
v | Another vector. |
this
and v
, between 0 and pi
.
|
inlineinherited |
|
inlineinherited |
Elastic collision.
Treat this
as a velocity vector or incident ray; this function returns the velocity reflected off of a surface with normal normal
. Convenience for -reflect_about(normal)
.
normal | Normal of surface to "bounce" on. |
|
inlineinherited |
Element-wise ceiling function.
x
such that x[i] = ceil(this[i])
. Element-wise clamp.
lo | Element-wise lower extremes. |
hi | Element-wise upper extremes. |
x[i]
is clamped between lo[i]
and hi[i]
.
|
inlineinherited |
Distance between points.
pt | Another point. |
this
and pt
.
|
inlineinherited |
Distance squared to a point.
pt | Another point. |
this
and pt
.
|
inlineinherited |
Dot product.
v | Another vector. |
this
with v
.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
Element-wise floor function.
x
such that x[i] = floor(this[i])
.
|
inlineinherited |
Return the component of this
that projects to axis
, as a fraction of axis's length.
axis | An arbitrary basis vector. |
|
inlineinherited |
Get the element at index idx
.
idx | Index of element. |
idx
.
|
inlineinherited |
Get the element at index idx
.
idx | Index of element. |
idx
.
|
inlineinherited |
Euclidean norm (magnitude).
|
inlineinherited |
Squared magnitude.
|
inlineinherited |
Maximum element.
Element-wise maximum of two Vec
s.
v | Another vector. |
x
such that x[i] = max(this[i], v[i])
.
|
inlineinherited |
Minimum element.
Element-wise minimum of two Vec
s.
v | Another vector. |
x
such that x[i] = min(this[i], v[i])
. Linear interpolation.
A mix parameter of 0 evaluates to this
, while 1 is v
.
v | Another vector. |
mix | A mixing factor between 0 and 1. |
this
with v
.
|
inlineexplicitinherited |
Element typecast.
U
.
|
inlineinherited |
Inequality test.
true
if any corresponding elements of this
and vv
are unequal, false
otherwise.
|
inlineinherited |
Negation.
|
inlineinherited |
Equality test.
true
if all corresponding elements of this
and vv
are equal, false
otherwise.
|
inlineinherited |
Vector element access.
idx | Index of element to retrieve. |
idx
.
|
inlineinherited |
Vector element access.
idx | Index of element to retrieve. |
idx
. Orthogonal projection to an axis.
axis | A direction vector. |
axis
with magnitude equal to the component of this
aligned with axis
. Reflection about a normal.
normal | Axis of reflection. |
|
inlineinherited |
Resized copy of a vector.
M | Dimension of new vector. |
M
. If M
is larger than N
, the new elements will be set to zero. If M
is 1, then the return type is T
. Element-wise multiplication.
v | Another vector. |
x
such that x[i] = this[i] * v[i]
.
|
inlineinherited |
Scalar multiple.
a | A constant scale factor. |
x
such that x[i] = this[i] * a
. Vector subtraction.
v | Another vector. |
x
such that x[i] = this[i] - v[i]
.
|
inlineinherited |
Vector normalization.
|
inlineinherited |
Compute a vector with the direction of this
and a new magnitude mag
.
If this
is the zero vector, it will remain unchanged.
Element-wise maximum.
Element-wise minimum.
Element-wise vector multiplication
a | A vector |
b | A vector |
x
such that x[i] = a[i] * b[i]
Vector-scalar multiplication
v | A vector |
d | Scalar value of type satisfying std::is_scalar |
x
such that x[i] = v[i] * d
Vector-scalar multiplication
d | Scalar value of type satisfying std::is_scalar |
v | A vector |
x
such that x[i] = d * v[i]
Element-wise vector division
a | A vector |
b | A vector |
x
such that x[i] = a[i] / b[i]
Vector division by a scalar
v | A vector |
d | Scalar value |
x
such that x[i] = v[i] / d
Scalar division by a vector
d | Scalar value |
v | A vector |
x
such that x[i] = d / v[i]