Template Struct BaseVector

Inheritance Relationships

Derived Types

Struct Documentation

template<typename CoordT>
struct BaseVector

A generic, weakly-typed vector.

This vector is weakly-typed as it allows all common operations that can be executed numerically. Instead of this, BaseVector implementations from other libraries could be used. However, they have to provide all the methods and fields that BaseVector defines.

Subclassed by lvr2::Normal< float >, lvr2::Normal< typename BaseVecT::CoordType >, lvr2::Normal< typename Vec::CoordType >

Public Types

using CoordType = CoordT

Public Functions

inline BaseVector()

Default constructs a null-vector.

inline BaseVector(const CoordT &x, const CoordT &y, const CoordT &z)

Builds a BaseVector with the given coordinates.

inline BaseVector(const BaseVector &o)
CoordT length() const

Returns the length of this vector.

CoordT length2() const

Returns the squared length of this vector.

The squared length is easier to calculate and sufficient for certain uses cases. This method only exists for performance reasons.

CoordT distance(const BaseVector &other) const

Calculates the distance to another vector.

CoordT distance2(const BaseVector &other) const

Calculates the squared distance to another vector.

The squared distance is easier to calculate and sufficient for certain uses cases. This method only exists for performance reasons.

BaseVector<CoordT> cross(const BaseVector &other) const

Calculates the cross product between this and the given vector. Returns a new BaseVector instance.

BaseVector<CoordT> rotated(const BaseVector &n, const double &alpha) const

Calculates the rotated vector around an normal vector n with the rotation angle alpha.

CoordT dot(const BaseVector &other) const

Calculates the dot product between this and the given vector.

inline void normalize()
BaseVector<CoordT> &operator=(const BaseVector<CoordT> &other) = default

Copy assignment.

BaseVector<CoordT> operator*(const CoordT &scale) const

Scalar multiplication.

BaseVector<CoordT> operator/(const CoordT &scale) const

Scalar division.

BaseVector<CoordT> &operator*=(const CoordT &scale)

Scalar multiplication.

BaseVector<CoordT> &operator/=(const CoordT &scale)

Scalar division.

BaseVector<CoordT> operator+(const BaseVector &other) const

Element-wise addition.

BaseVector<CoordT> operator-(const BaseVector &other) const

Element-wise subtraction.

BaseVector<CoordT> &operator+=(const BaseVector<CoordT> &other)

Element-wise addition.

BaseVector<CoordT> &operator-=(const BaseVector<CoordT> &other)

Element-wise subtraction.

CoordType distanceFrom(const BaseVector<CoordT> &other) const
CoordType squaredDistanceFrom(const BaseVector<CoordType> &other) const
Normal<CoordT> normalized() const

Returns a normalized version of this vector.

Note that this must not be the null vector, or else the behavior is undefined.

bool operator==(const BaseVector &other) const
bool operator!=(const BaseVector &other) const
CoordT operator*(const BaseVector<CoordType> &other) const
CoordT operator[](const unsigned &index) const

Indexed coordinate access (reading)

CoordT &operator[](const unsigned &index)

Indexed coordinate access (writing)

Public Members

CoordT x
CoordT y
CoordT z

Public Static Functions

template<typename CollectionT>
static BaseVector<CoordT> centroid(const CollectionT &points)

Returns the centroid of all points in the given collection.

The collection need to work with a range-based for-loop and its elements need to be Point<BaseVecT>. It has to contain at least one element.

template<typename CollectionT>
static BaseVector<CoordT> average(const CollectionT &vecs)

Returns the average of all vectors in the given collection.

The collection need to work with a range-based for-loop and its elements need to be Vector<BaseVecT>. It has to contain at least one element.

Friends

template<typename T, typename S>
friend BaseVector<T> operator*(const Eigen::Matrix<S, 4, 4> &mat, const BaseVector<T> &normal)