PIP 5.6.1
Platform-Independent Primitives
Public Member Functions | Static Public Member Functions | List of all members
PIMathVectorT< Size, Type > Class Template Reference

Fixed-size mathematical vector with compile-time size Provides vector operations including arithmetic, normalization, angles, cross product, and dot product. More...

#include <pimathvector.h>

Inheritance diagram for PIMathVectorT< Size, Type >:
Inheritance graph
[legend]

Public Member Functions

 PIMathVectorT (const Type &v=Type())
 Constructs a vector and fills every coordinate with v.
 
 PIMathVectorT (const PIVector< Type > &val)
 Constructs a fixed-size vector from a dynamic one of the same size.
 
 PIMathVectorT (std::initializer_list< Type > init_list)
 Constructs a vector from an initializer list with exactly Size elements.
 
constexpr uint size () const
 Returns the compile-time vector dimension.
 
_CVectorfill (const Type &v)
 Fills all coordinates with v.
 
_CVectormove (const Type &v)
 Adds v to every coordinate.
 
_CVectormove (const _CVector &v)
 Adds another vector component-wise.
 
_CVectorswapElements (uint f, uint s)
 Swaps two coordinates in place.
 
Type lengthSqr () const
 Returns the squared Euclidean length.
 
Type length () const
 Returns the Euclidean length. Available for arithmetic element types.
 
Type manhattanLength () const
 Returns the Manhattan length. Available for arithmetic element types.
 
Type angleCos (const _CVector &v) const
 Returns the cosine of the angle to v.
 
Type angleSin (const _CVector &v) const
 Returns the sine of the angle to v.
 
Type angleRad (const _CVector &v) const
 Returns the angle to v in radians.
 
Type angleDeg (const _CVector &v) const
 Returns the angle to v in degrees.
 
Type angleElevation (const _CVector &v) const
 Returns the elevation angle from this point to v in degrees.
 
_CVector projection (const _CVector &v)
 Returns the projection of this vector onto v.
 
_CVectornormalize ()
 Normalizes this vector in place.
 
_CVector normalized ()
 Returns a normalized copy of this vector.
 
bool isNull () const
 Returns true when all coordinates are zero.
 
bool isOrtho (const _CVector &v) const
 Returns true when this vector is orthogonal to v.
 
Type & operator[] (uint index)
 Returns writable access to a coordinate.
 
const Type & operator[] (uint index) const
 Returns read-only access to a coordinate.
 
Type at (uint index) const
 Returns a coordinate by value.
 
Type & element (uint index)
 Returns writable access to a coordinate.
 
const Type & element (uint index) const
 Returns read-only access to a coordinate.
 
_CVectoroperator= (const Type &v)
 Assigns the same value to all coordinates.
 
bool operator== (const _CVector &v) const
 Compares two vectors component-wise.
 
bool operator!= (const _CVector &v) const
 Returns true when vectors differ in at least one coordinate.
 
void operator+= (const _CVector &v)
 Adds v component-wise.
 
void operator-= (const _CVector &v)
 Subtracts v component-wise.
 
void operator*= (const Type &v)
 Multiplies all coordinates by v.
 
void operator/= (const Type &v)
 Divides all coordinates by v.
 
_CVector operator- () const
 Returns the vector with inverted sign.
 
_CVector operator+ (const _CVector &v) const
 Returns the component-wise sum with v.
 
_CVector operator- (const _CVector &v) const
 Returns the component-wise difference with v.
 
_CVector operator* (const Type &v) const
 Returns a copy scaled by v.
 
_CVector operator/ (const Type &v) const
 Returns a copy divided by v.
 
_CVector cross (const _CVector &v) const
 Returns the 3D cross product with v.
 
Type dot (const _CVector &v) const
 Returns the scalar product with v.
 
_CVector mul (const _CVector &v) const
 Returns the component-wise product with v.
 
_CVector mul (const Type &v) const
 Returns a copy scaled by v.
 
_CVector div (const _CVector &v) const
 Returns the component-wise division by v.
 
_CVector div (const Type &v) const
 Returns a copy divided by v.
 
PIMathMatrixT< 1, Size, Type > transposed () const
 Returns the vector as a 1 x Size matrix.
 
Type distToLine (const _CVector &lp0, const _CVector &lp1)
 Returns the distance from this 2D point to the line through lp0 and lp1.
 
template<uint Size1, typename Type1 >
PIMathVectorT< Size1, Type1 > turnTo () const
 Converts this vector to another dimension and element type.
 
template<typename T >
PIMathVectorT< Size, T > toType () const
 Returns this vector with another element type.
 
template<uint SubSize>
PIMathVectorT< SubSize, Type > subvector (int offset=0) const
 Returns a subvector starting at offset and zero-fills coordinates outside the source range.
 
template<uint SubSize>
PIMathVectorT< Size, Type > & setSubvector (int index, const PIMathVectorT< SubSize, Type > &v)
 Writes v into this vector starting at index and ignores coordinates outside the destination range.
 

Static Public Member Functions

static _CVector fromTwoPoints (const _CVector &st, const _CVector &fn)
 Builds the displacement vector from point st to point fn.
 
static _CVector cross (const _CVector &v1, const _CVector &v2)
 Returns the cross product of v1 and v2.
 
static Type dot (const _CVector &v1, const _CVector &v2)
 Returns the scalar product of v1 and v2.
 
static _CVector mul (const _CVector &v1, const _CVector &v2)
 Returns the component-wise product of v1 and v2.
 
static _CVector mul (const Type &v1, const _CVector &v2)
 Returns v2 scaled by v1.
 
static _CVector mul (const _CVector &v1, const Type &v2)
 Returns v1 scaled by v2.
 
static _CVector div (const _CVector &v1, const _CVector &v2)
 Returns the component-wise division of v1 by v2.
 
static _CVector div (const _CVector &v1, const Type &v2)
 Returns v1 divided by scalar v2.
 

Detailed Description

template<uint Size, typename Type = double>
class PIMathVectorT< Size, Type >

Fixed-size mathematical vector with compile-time size Provides vector operations including arithmetic, normalization, angles, cross product, and dot product.