Drake
Drake C++ Documentation
SpatialVector< SV, T > Class Template Reference

Detailed Description

template<template< typename > class SV, typename T>
class drake::multibody::SpatialVector< SV, T >

This class represents a spatial vector and has 6 elements, with a 3-element rotational vector on top of a 3-element translational vector.

Important subclasses of SpatialVector include SpatialVelocity, SpatialAcceleration, SpatialForce, and SpatialMomentum. Each of the 3-element vectors is assumed to be expressed in the same expressed-in frame E. This class only stores 6 elements and does not store the underlying expressed-in frame E or other information. The user is responsible for explicitly tracking the underlying frames with monogram notation. For example, Foo_E denotes an arbitrary spatial vector Foo expressed in a frame E. Details on spatial vectors and monogram notation are in sections Spatial Vectors and monogram notation.

Template Parameters
SVThe type of the more specialized spatial vector class. It must be a template on the scalar type T.
TThe scalar type, which must be one of the default scalars.

#include <drake/multibody/math/spatial_vector.h>

Public Types

enum  { kSpatialVectorSize = 6, kRotationSize = 3, kTranslationSize = 3 }
 Sizes for spatial quantities and its components in 3D (three dimensions). More...
 
using SpatialQuantity = SV< T >
 The more specialized spatial vector class templated on the scalar type T. More...
 
using CoeffsEigenType = Vector6< T >
 The type of the underlying in-memory representation using an Eigen vector. More...
 

Public Member Functions

 SpatialVector ()
 Default constructor. More...
 
 SpatialVector (const Eigen::Ref< const Vector3< T >> &w, const Eigen::Ref< const Vector3< T >> &v)
 Constructs a spatial vector from a rotational component w and a translational component v. More...
 
template<typename OtherDerived >
 SpatialVector (const Eigen::MatrixBase< OtherDerived > &V)
 Constructs a spatial vector V from an Eigen expression that represents a 6-element vector (3-element rotational vector on top of a 3-element translational vector). More...
 
int size () const
 For 3D (three-dimensional) analysis, the total size of the concatenated rotational vector (3 elements) and translational vector (3 elements) is six (6), which is known at compile time. More...
 
const T & operator[] (int i) const
 Const access to the i-th element of this spatial vector. More...
 
T & operator[] (int i)
 Mutable access to the i-th element of this spatial vector. More...
 
const Vector3< T > & rotational () const
 Const access to the rotational component of this spatial vector. More...
 
Vector3< T > & rotational ()
 Mutable access to the rotational component of this spatial vector. More...
 
const Vector3< T > & translational () const
 Const access to the translational component of this spatial vector. More...
 
Vector3< T > & translational ()
 Mutable access to the translational component of this spatial vector. More...
 
const T * data () const
 Returns a (const) bare pointer to the underlying data. More...
 
T * mutable_data ()
 Returns a (mutable) bare pointer to the underlying data. More...
 
std::tuple< const T, const T > GetMaximumAbsoluteDifferences (const SpatialQuantity &other) const
 Returns the maximum absolute values of the differences in the rotational and translational components of this and other (i.e., the infinity norms of the difference in rotational and translational components). More...
 
decltype(T()< T()) IsNearlyEqualWithinAbsoluteTolerance (const SpatialQuantity &other, double rotational_tolerance, double translational_tolerance) const
 Compares the rotational and translational parts of this and other to check if they are the same to within specified absolute differences. More...
 
decltype(T()< T()) IsApprox (const SpatialQuantity &other, double tolerance=std::numeric_limits< double >::epsilon()) const
 Determines whether all six corresponding elements of two spatial vectors are equal to each other to within a specified tolerance epsilon. More...
 
void SetNaN ()
 Sets all the elements in this SpatialVector to NaN. More...
 
SpatialQuantitySetZero ()
 Sets both the rotational and translational components of this SpatialVector to zero. More...
 
CoeffsEigenTypeget_coeffs ()
 Returns a mutable reference to the underlying storage. More...
 
const CoeffsEigenTypeget_coeffs () const
 Returns a constant reference to the underlying storage. More...
 
SpatialQuantity operator- () const
 Unary minus operator. More...
 
SpatialQuantityoperator+= (const SpatialQuantity &V)
 Addition assignment operator. More...
 
SpatialQuantityoperator-= (const SpatialQuantity &V)
 Subtraction assignment operator. More...
 
SpatialQuantityoperator *= (const T &s)
 Multiplication assignment operator. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 SpatialVector (const SpatialVector &)=default
 
SpatialVectoroperator= (const SpatialVector &)=default
 
 SpatialVector (SpatialVector &&)=default
 
SpatialVectoroperator= (SpatialVector &&)=default
 

Static Public Member Functions

static SpatialQuantity Zero ()
 Factory to create a zero spatial vector, i.e., a SpatialVector whose rotational and translational components are both zero. More...
 

Friends

SpatialQuantity operator+ (const SpatialQuantity &V1_E, const SpatialQuantity &V2_E)
 Adds two spatial vectors by simply adding their 6 underlying elements. More...
 
SpatialQuantity operator- (const SpatialQuantity &V1, const SpatialQuantity &V2)
 Subtracts two spatial vectors by simply subtracting their 6 underlying elements. More...
 
SpatialQuantity operator * (const math::RotationMatrix< T > &R_FE, const SpatialQuantity &V_E)
 Expresses a spatial vector in another frame. More...
 

Related Functions

(Note that these are not member functions.)

SpatialQuantity operator * (const T &s, const SpatialQuantity &V)
 Multiplication of a spatial vector V from the left by a scalar s. More...
 
SpatialQuantity operator * (const SpatialQuantity &V, const T &s)
 Multiplication of a spatial vector V from the right by a scalar s. More...
 
template<template< typename > class SpatialQuantity, typename T >
std::ostream & operator<< (std::ostream &o, const SpatialVector< SpatialQuantity, T > &V)
 Stream insertion operator to write SpatialVector objects into a std::ostream. More...
 

Member Typedef Documentation

◆ CoeffsEigenType

The type of the underlying in-memory representation using an Eigen vector.

◆ SpatialQuantity

using SpatialQuantity = SV<T>

The more specialized spatial vector class templated on the scalar type T.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Sizes for spatial quantities and its components in 3D (three dimensions).

Enumerator
kSpatialVectorSize 
kRotationSize 
kTranslationSize 

Constructor & Destructor Documentation

◆ SpatialVector() [1/5]

SpatialVector ( const SpatialVector< SV, T > &  )
default

◆ SpatialVector() [2/5]

SpatialVector ( SpatialVector< SV, T > &&  )
default

◆ SpatialVector() [3/5]

Default constructor.

In Release builds, all 6 elements of a newly constructed spatial vector are uninitialized (for speed). In Debug builds, the 6 elements are set to NaN so that invalid operations on an uninitialized spatial vector fail fast (fast bug detection).

◆ SpatialVector() [4/5]

SpatialVector ( const Eigen::Ref< const Vector3< T >> &  w,
const Eigen::Ref< const Vector3< T >> &  v 
)

Constructs a spatial vector from a rotational component w and a translational component v.

◆ SpatialVector() [5/5]

SpatialVector ( const Eigen::MatrixBase< OtherDerived > &  V)
explicit

Constructs a spatial vector V from an Eigen expression that represents a 6-element vector (3-element rotational vector on top of a 3-element translational vector).

This constructor asserts the size of V is six (6) either at compile-time for fixed sized Eigen expressions or at run-time for dynamic sized Eigen expressions.

Member Function Documentation

◆ data()

const T* data ( ) const

Returns a (const) bare pointer to the underlying data.

It is guaranteed that there will be six (6) T's densely packed at data[0], data[1], etc.

◆ get_coeffs() [1/2]

CoeffsEigenType& get_coeffs ( )

Returns a mutable reference to the underlying storage.

◆ get_coeffs() [2/2]

const CoeffsEigenType& get_coeffs ( ) const

Returns a constant reference to the underlying storage.

◆ GetMaximumAbsoluteDifferences()

std::tuple<const T, const T> GetMaximumAbsoluteDifferences ( const SpatialQuantity other) const

Returns the maximum absolute values of the differences in the rotational and translational components of this and other (i.e., the infinity norms of the difference in rotational and translational components).

Parameters
[in]otherspatial vector to subtract from this spatial vector.
Returns
The following quantities in a tuple, in the order below.
std::tuple Description
w_max_difference Maximum absolute difference in rotation components
v_max_difference Maximum absolute difference in translation components

◆ IsApprox()

decltype(T() < T()) IsApprox ( const SpatialQuantity other,
double  tolerance = std::numeric_limits<double>::epsilon() 
) const

Determines whether all six corresponding elements of two spatial vectors are equal to each other to within a specified tolerance epsilon.

Parameters
[in]otherspatial vector to compare to this spatial vector.
[in]epsilonspecified tolerance for this test.
Returns
true if ‖this - other‖∞ < epsilon, otherwise returns false. Note: the infinity norm ‖this - other‖∞ is simply the maximum of the six absolute values in (this - other).

◆ IsNearlyEqualWithinAbsoluteTolerance()

decltype(T() < T()) IsNearlyEqualWithinAbsoluteTolerance ( const SpatialQuantity other,
double  rotational_tolerance,
double  translational_tolerance 
) const

Compares the rotational and translational parts of this and other to check if they are the same to within specified absolute differences.

Parameters
[in]otherspatial vector to compare to this spatial vector.
[in]rotational_tolerancemaximum allowable absolute difference between the rotational parts of this and other. The units depend on the underlying class. For example, spatial velocity, acceleration, and force have units of rad/sec, rad/sec^2, and N*m, respectively.
[in]translational_tolerancemaximum allowable absolute difference between the translational parts of this and other. The units depend on the underlying class. For example, spatial velocity, acceleration, and force have units of meter/sec, meter/sec^2, and Newton, respectively.
Returns
true if all three rotational elements of this and other are equal within rotational_tolerance and all three translational elements of this and other are equal within translational_tolerance.

◆ mutable_data()

T* mutable_data ( )

Returns a (mutable) bare pointer to the underlying data.

It is guaranteed that there will be six (6) T's densely packed at data[0], data[1], etc.

◆ operator *=()

SpatialQuantity& operator *= ( const T &  s)

Multiplication assignment operator.

◆ operator+=()

SpatialQuantity& operator+= ( const SpatialQuantity V)

Addition assignment operator.

◆ operator-()

SpatialQuantity operator- ( ) const

Unary minus operator.

◆ operator-=()

SpatialQuantity& operator-= ( const SpatialQuantity V)

Subtraction assignment operator.

◆ operator=() [1/2]

SpatialVector& operator= ( SpatialVector< SV, T > &&  )
default

◆ operator=() [2/2]

SpatialVector& operator= ( const SpatialVector< SV, T > &  )
default

◆ operator[]() [1/2]

const T& operator[] ( int  i) const

Const access to the i-th element of this spatial vector.

In Debug builds, this function asserts that i is in bounds whereas for release builds, no bounds-check on i is performed (for speed).

◆ operator[]() [2/2]

T& operator[] ( int  i)

Mutable access to the i-th element of this spatial vector.

In Debug builds, this function asserts that i is in bounds whereas for release builds, no bounds-check on i is performed (for speed).

◆ rotational() [1/2]

const Vector3<T>& rotational ( ) const

Const access to the rotational component of this spatial vector.

◆ rotational() [2/2]

Vector3<T>& rotational ( )

Mutable access to the rotational component of this spatial vector.

◆ SetNaN()

void SetNaN ( )

Sets all the elements in this SpatialVector to NaN.

This is typically used to quickly detect uninitialized values since NaN will trigger a chain of invalid computations that can be tracked back to their source.

◆ SetZero()

SpatialQuantity& SetZero ( )

Sets both the rotational and translational components of this SpatialVector to zero.

◆ size()

int size ( ) const

For 3D (three-dimensional) analysis, the total size of the concatenated rotational vector (3 elements) and translational vector (3 elements) is six (6), which is known at compile time.

◆ translational() [1/2]

const Vector3<T>& translational ( ) const

Const access to the translational component of this spatial vector.

◆ translational() [2/2]

Vector3<T>& translational ( )

Mutable access to the translational component of this spatial vector.

◆ Zero()

static SpatialQuantity Zero ( )
static

Factory to create a zero spatial vector, i.e., a SpatialVector whose rotational and translational components are both zero.

Friends And Related Function Documentation

◆ operator * [1/3]

SpatialQuantity operator * ( const T &  s,
const SpatialQuantity V 
)
friend

Multiplication of a spatial vector V from the left by a scalar s.

◆ operator * [2/3]

SpatialQuantity operator * ( const SpatialQuantity V,
const T &  s 
)
friend

Multiplication of a spatial vector V from the right by a scalar s.

◆ operator * [3/3]

SpatialQuantity operator * ( const math::RotationMatrix< T > &  R_FE,
const SpatialQuantity V_E 
)
friend

Expresses a spatial vector in another frame.

Parameters
[in]R_FERotationMatrix relating a frame F to a frame E.
[in]V_Espatial vector expressed in frame E.
Returns
V_F spatial vector expressed in frame F, calculated from:
  V_F.rotational()    = R_FE * V_E.rotational(),
  V_F.translational() = R_FE * V_E.translational()

◆ operator+

SpatialQuantity operator+ ( const SpatialQuantity V1_E,
const SpatialQuantity V2_E 
)
friend

Adds two spatial vectors by simply adding their 6 underlying elements.

Parameters
[in]V1_Espatial vector expressed in the same frame E as V2_E.
[in]V2_Espatial vector expressed in the same frame E as V1_E.
Note
The general utility of this operator+() function is questionable and it should only be used if you are sure it makes sense. Please refer to documentation for the appropriate spatial quantity subclass (e.g., SpatialVelocity, SpatialAcceleration, SpatialForce, or SpatialMomentum).

◆ operator-

SpatialQuantity operator- ( const SpatialQuantity V1,
const SpatialQuantity V2 
)
friend

Subtracts two spatial vectors by simply subtracting their 6 underlying elements.

Parameters
[in]V1_Espatial vector expressed in the same frame E as V2_E.
[in]V2_Espatial vector expressed in the same frame E as V1_E.
Note
The general utility of this operator-() function is questionable and it should only be used if you are sure it makes sense. Please refer to documentation for the appropriate spatial quantity subclass (e.g., SpatialVelocity, SpatialAcceleration, SpatialForce, or SpatialMomentum).

◆ operator<<()

std::ostream & operator<< ( std::ostream &  o,
const SpatialVector< SpatialQuantity, T > &  V 
)
related

Stream insertion operator to write SpatialVector objects into a std::ostream.

Especially useful for debugging.


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