geomc 1.0
A c++ linear algebra template library
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
Vec< T, 3 > Class Template Reference

3D specialization of vector class. More...

#include <geomc/linalg/vecdetail/Vec3.h>

Inheritance diagram for Vec< T, 3 >:
VecCommon< T, 3, Vec< T, 3 > > VecBase< T, N >

Public Types

typedef Vec< T, 3 > 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 ()
 Construct vector with all elements set to 0.
 
template<typename U >
constexpr Vec (Vec< U, 2 > xy, T z)
 Construct a vector with (x, y) taken from the 2D vector xy, and z as the final element.
 
constexpr Vec (T a)
 Construct a vector with all elements set to a.
 
constexpr Vec (const T v[3])
 Construct a vector with elements copied from the 3-element array v.
 
constexpr Vec (T x, T y, T z)
 Construct a vector with elements (x, y, z).
 
Vec< T, 3 > operator^ (Vec< T, 3 > v) const
 Vector cross product.
 
Vec< T, 3 > add (T dx, T dy, T dz) const
 
Vec< T, 3 > sub (T dx, T dy, T dz) const
 
Vec< T, 3 > scale (T a, T b, T c) const
 
dot (T xx, T yy, T zz) const
 
Vec< T, 3 > reflected_x () const
 
Vec< T, 3 > reflected_y () const
 
Vec< T, 3 > reflected_z () const
 
Vec< T, 3 > cross (Vec< T, 3 > v) const
 
Vec< T, 3 > to_spherical () const
 
Vec< T, 3 > from_spherical () const
 
Vec< T, 3 > rotate (Vec< T, 3 > axis, T radians) const
 
Vec< T, 3 > rotate (T u, T v, T w, T radians) const
 
Vec< T, 3 > rotate (Vec< T, 3 > axis, Vec< T, 3 > center, T radians)
 
Vec< T, 3 > rotate (T u, T v, T w, T a, T b, T c, T radians)
 
Vec< T, 3 > align (const Vec< T, 3 > &from, const Vec< T, 3 > &to)
 
bool is_finite_real () const
 
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_toperator+= (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_toperator-= (const self_t &vv)
 Subtraction and assignment.
 
self_toperator*= (T s)
 Scalar multiplication and assignment.
 
self_toperator*= (const self_t &vv)
 Element-wise multiplication and assignment.
 
self_toperator/= (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...
 
dot (const self_t &v) const
 Dot product. More...
 
mag () const
 Euclidean norm (magnitude). More...
 
mag2 () const
 Squared magnitude. More...
 
dist (const self_t &pt) const
 Distance between points. More...
 
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...
 
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...
 
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 Vecs. More...
 
min () const
 Minimum element. More...
 
self_t max (const self_t &v) const
 Element-wise maximum of two Vecs. More...
 
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 const Vec< T, 3 > X_AXIS = Vec<T,3>(1,0,0)
 (1, 0, 0) constant
 
static const Vec< T, 3 > Y_AXIS = Vec<T,3>(0,1,0)
 (0, 1, 0) constant
 
static const Vec< T, 3 > Z_AXIS = Vec<T,3>(0,0,1)
 (0, 0, 1) constant
 
static constexpr index_t DIM
 Vector dimension.
 
static const self_t ones
 
static const self_t zeros
 

Protected Attributes

v [N]
 

Detailed Description

template<typename T>
class geom::Vec< T, 3 >

3D specialization of vector class.

Vec<T,3>'s elements may be accessed under these equivalent naming schemes:

v.{x,y,z} // conventional Euclidean coordinate names
v.{s,t,u} // conventional parameterization coordinate names
v.{r,g,b} // conventional color tuple coordinate names

x, s, and r all refer to the same element.

Member Function Documentation

◆ abs()

self_t abs ( ) const
inlineinherited

Element-wise absolute value.

Returns
A new vector x such that x[i] = abs(this[i]).

◆ add() [1/2]

self_t add ( const self_t v) const
inlineinherited

Vector addition.

Parameters
vAnother vector.
Returns
A new vector x such that x[i] = this[i] + v[i].

◆ add() [2/2]

Vec< T, 3 > add ( dx,
dy,
dz 
) const
inline
Returns
(dx, dy, dz) added with this

◆ align()

Vec< T, 3 > align ( const Vec< T, 3 > &  from,
const Vec< T, 3 > &  to 
)
inline

Compute a transform aligning from with to and apply it to this.

◆ angle_to()

T angle_to ( const self_t v) const
inlineinherited

Angle between vectors.

Parameters
vAnother vector.
Returns
Angle in radians between this and v, between 0 and pi.

◆ begin() [1/2]

T * begin ( )
inlineinherited
Returns
A writeable iterator pointing at the first element.

◆ begin() [2/2]

const T * begin ( ) const
inlineinherited
Returns
A read-only iterator pointing at the first element.

◆ bounce_on()

self_t bounce_on ( const self_t normal) const
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).

Parameters
normalNormal of surface to "bounce" on.
Returns
The "bounced" direction vector.

◆ ceil()

self_t ceil ( ) const
inlineinherited

Element-wise ceiling function.

Returns
A new vector x such that x[i] = ceil(this[i]).

◆ clamp()

self_t clamp ( const self_t lo,
const self_t hi 
) const
inlineinherited

Element-wise clamp.

Parameters
loElement-wise lower extremes.
hiElement-wise upper extremes.
Returns
A new vector such that each element x[i] is clamped between lo[i] and hi[i].

◆ cross()

Vec< T, 3 > cross ( Vec< T, 3 >  v) const
inline
Returns
Cross product of this by v, in the order shown.

◆ dist()

T dist ( const self_t pt) const
inlineinherited

Distance between points.

Parameters
ptAnother point.
Returns
The distance between this and pt.

◆ dist2()

T dist2 ( const self_t pt) const
inlineinherited

Distance squared to a point.

Parameters
ptAnother point.
Returns
The square of the distance between this and pt.

◆ dot() [1/2]

T dot ( const self_t v) const
inlineinherited

Dot product.

Parameters
vAnother vector.
Returns
The dot product of this with v.

◆ dot() [2/2]

T dot ( xx,
yy,
zz 
) const
inline
Returns
Dot product of this with the vector (xx, yy, zz)

◆ end() [1/2]

T * end ( )
inlineinherited
Returns
A writeable iterator pointing just beyond the last element.

◆ end() [2/2]

const T * end ( ) const
inlineinherited
Returns
A read-only iterator pointing just beyond the last element.

◆ floor()

self_t floor ( ) const
inlineinherited

Element-wise floor function.

Returns
A new vector x such that x[i] = floor(this[i]).

◆ fraction_on()

T fraction_on ( const self_t axis) const
inlineinherited

Return the component of this that projects to axis, as a fraction of axis's length.

Parameters
axisAn arbitrary basis vector.

◆ from_spherical()

Vec< T, 3 > from_spherical ( ) const
inline

Convert this point, interpreted as spherical coordinates (r, elevation, azimuth), to euclidean coordinates, where r (this[0]) is the radius, eleveation (this[1]) is the angle from the +z axis, and azimuth (this[2]) is the angle about z+ from the x+ axis.

Returns
This point described by this vector interpreted as spherical coordinates as (x, y, z) euclidean coordinates.

◆ get() [1/2]

T & get ( index_t  idx)
inlineinherited

Get the element at index idx.

Parameters
idxIndex of element.
Returns
A reference to the element at idx.

◆ get() [2/2]

const T & get ( index_t  idx) const
inlineinherited

Get the element at index idx.

Parameters
idxIndex of element.
Returns
A const reference to the element at idx.

◆ is_finite_real()

bool is_finite_real ( ) const
inline
Returns
true if no elements are an infinity or NaN.

◆ mag()

T mag ( ) const
inlineinherited

Euclidean norm (magnitude).

Returns
The Euclidean magnitude (geometric length) of this vector.

◆ mag2()

T mag2 ( ) const
inlineinherited

Squared magnitude.

Returns
The square of the magnitude of this vector.

◆ max() [1/2]

T max ( ) const
inlineinherited

Maximum element.

Returns
The value of the component with the highest value.

◆ max() [2/2]

self_t max ( const self_t v) const
inlineinherited

Element-wise maximum of two Vecs.

Parameters
vAnother vector.
Returns
A new vector x such that x[i] = max(this[i], v[i]).

◆ min() [1/2]

T min ( ) const
inlineinherited

Minimum element.

Returns
The value of the component with the lowest value.

◆ min() [2/2]

self_t min ( const self_t v) const
inlineinherited

Element-wise minimum of two Vecs.

Parameters
vAnother vector.
Returns
A new vector x such that x[i] = min(this[i], v[i]).

◆ mix()

self_t mix ( const self_t v,
mix 
) const
inlineinherited

Linear interpolation.

A mix parameter of 0 evaluates to this, while 1 is v.

Parameters
vAnother vector.
mixA mixing factor between 0 and 1.
Returns
A linear mixing of this with v.

◆ operator Vec< U, N >()

operator Vec< U, N > ( ) const
inlineexplicitinherited

Element typecast.

Returns
A new vector with all elements cast to type U.

◆ operator!=()

bool operator!= ( const self_t vv) const
inlineinherited

Inequality test.

Returns
true if any corresponding elements of this and vv are unequal, false otherwise.

◆ operator-()

self_t operator- ( ) const
inlineinherited

Negation.

Returns
A copy of this vector with all elements negated (i.e. a vector pointing in the opposite direction).

◆ operator==()

bool operator== ( const self_t vv) const
inlineinherited

Equality test.

Returns
true if all corresponding elements of this and vv are equal, false otherwise.

◆ operator[]() [1/2]

T & operator[] ( index_t  idx)
inlineinherited

Vector element access.

Parameters
idxIndex of element to retrieve.
Returns
A reference to the element at index idx.

◆ operator[]() [2/2]

const T & operator[] ( index_t  idx) const
inlineinherited

Vector element access.

Parameters
idxIndex of element to retrieve.
Returns
A read-only reference to the element at index idx.

◆ project_on()

self_t project_on ( const self_t axis) const
inlineinherited

Orthogonal projection to an axis.

Parameters
axisA direction vector.
Returns
A vector in direction axis with magnitude equal to the component of this aligned with axis.

◆ reflect_about()

self_t reflect_about ( self_t  normal) const
inlineinherited

Reflection about a normal.

Parameters
normalAxis of reflection.
Returns
A copy of this vector reflected across the given axis.

◆ reflected_x()

Vec< T, 3 > reflected_x ( ) const
inline
Returns
A copy with the X component negated

◆ reflected_y()

Vec< T, 3 > reflected_y ( ) const
inline
Returns
A copy with the Y component negated

◆ reflected_z()

Vec< T, 3 > reflected_z ( ) const
inline
Returns
A copy with the Z component negated

◆ resized()

PointType< T, M >::point_t resized ( ) const
inlineinherited

Resized copy of a vector.

Template Parameters
MDimension of new vector.
Returns
A new vector with size 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.

◆ rotate() [1/4]

Vec< T, 3 > rotate ( u,
v,
w,
a,
b,
c,
radians 
)
inline
Returns
A copy of this vector rotated by angle radians about the axis (u, v, w), and centerpoint (a, b, c).

◆ rotate() [2/4]

Vec< T, 3 > rotate ( u,
v,
w,
radians 
) const
inline
Returns
A copy of this vector rotated by angle radians about the axis (u, v, w).

◆ rotate() [3/4]

Vec< T, 3 > rotate ( Vec< T, 3 >  axis,
radians 
) const
inline
Returns
A copy of this vector rotated by angle radians about axis.

◆ rotate() [4/4]

Vec< T, 3 > rotate ( Vec< T, 3 >  axis,
Vec< T, 3 >  center,
radians 
)
inline
Returns
A copy of this vector rotated by angle radians about rotation axis axis and centerpoint center.

◆ scale() [1/3]

self_t scale ( const self_t v) const
inlineinherited

Element-wise multiplication.

Parameters
vAnother vector.
Returns
A new vector x such that x[i] = this[i] * v[i].

◆ scale() [2/3]

self_t scale ( a) const
inlineinherited

Scalar multiple.

Parameters
aA constant scale factor.
Returns
A new vector x such that x[i] = this[i] * a.

◆ scale() [3/3]

Vec< T, 3 > scale ( a,
b,
c 
) const
inline
Returns
Element-wise scaled copy

◆ sub() [1/2]

self_t sub ( const self_t v) const
inlineinherited

Vector subtraction.

Parameters
vAnother vector.
Returns
A new vector x such that x[i] = this[i] - v[i].

◆ sub() [2/2]

Vec< T, 3 > sub ( dx,
dy,
dz 
) const
inline
Returns
(dx, dy, dz) subtracted from this

◆ to_spherical()

Vec< T, 3 > to_spherical ( ) const
inline

Convert this euclidean point to spherical coordinates (r, elevation, azimuth), with both angles in radians. Elevation is the angle from the +z axis in the range (0, pi), and azimuth is the angle about +z from the +x axis in the range (-pi, pi).

Returns
This euclidean point converted to spherical coordinates.

◆ unit()

self_t unit ( ) const
inlineinherited

Vector normalization.

Returns
A copy of this vector with unit length.

◆ with_length()

self_t with_length ( mag) const
inlineinherited

Compute a vector with the direction of this and a new magnitude mag.

If this is the zero vector, it will remain unchanged.


The documentation for this class was generated from the following file: