Gazebo Math

API Reference

8.0.0~pre1
Matrix3< T > Class Template Reference

A 3x3 matrix class. More...

#include <gz/math/Matrix3.hh>

Public Member Functions

 Matrix3 ()
 Default constructor that initializes the matrix3 to zero.
 
 Matrix3 (const Quaternion< T > &_q)
 Construct 3x3 rotation Matrix from a quaternion.
 
constexpr Matrix3 (T _v00, T _v01, T _v02, T _v10, T _v11, T _v12, T _v20, T _v21, T _v22)
 Construct a matrix3 using nine values.
 
Determinant () const
 Return the determinant of the matrix.
 
bool Equal (const Matrix3 &_m, const T &_tol) const
 Equality test with tolerance.
 
Matrix3< T > Inverse () const
 Return the inverse matrix.
 
bool operator!= (const Matrix3< T > &_m) const
 Inequality test operator.
 
T & operator() (size_t _row, size_t _col)
 Array subscript operator.
 
operator() (size_t _row, size_t _col) const
 Array subscript operator.
 
Matrix3< T > operator* (const Matrix3< T > &_m) const
 Matrix multiplication operator.
 
Matrix3< T > operator* (const T &_s) const
 Scalar multiplication operator.
 
Vector3< T > operator* (const Vector3< T > &_vec) const
 Multiplication operator with Vector3 on the right treated like a column vector.
 
Matrix3< T > operator+ (const Matrix3< T > &_m) const
 Addition operation.
 
Matrix3< T > operator- (const Matrix3< T > &_m) const
 Subtraction operator.
 
Matrix3< T > & operator= (const Quaternion< T > &_q)
 Set as a 3x3 rotation matrix from a quaternion.
 
bool operator== (const Matrix3< T > &_m) const
 Equality test operator.
 
void Set (size_t _row, size_t _col, T _v)
 Set a single value.
 
void Set (T _v00, T _v01, T _v02, T _v10, T _v11, T _v12, T _v20, T _v21, T _v22)
 Set values.
 
void SetAxes (const Vector3< T > &_xAxis, const Vector3< T > &_yAxis, const Vector3< T > &_zAxis)
 Set the matrix from three axis (1 per column).
 
void SetCol (unsigned int _c, const Vector3< T > &_v)
 Set a column.
 
void SetFrom2Axes (const Vector3< T > &_v1, const Vector3< T > &_v2)
 Set as a rotation matrix to represent rotation from vector _v1 to vector _v2, so that _v2.Normalize() == this * _v1.Normalize() holds.
 
void SetFromAxisAngle (const Vector3< T > &_axis, T _angle)
 Set as a rotation matrix from an axis and angle.
 
void Transpose ()
 Transpose this matrix.
 
Matrix3< T > Transposed () const
 Return the transpose of this matrix.
 

Static Public Attributes

static const Matrix3< T > & Identity = detail::gMatrix3Identity<T>
 A Matrix3 initialized to identity. This is equivalent to math::Matrix3<T>(1, 0, 0, 0, 1, 0, 0, 0, 1).
 
static const Matrix3< T > & Zero = detail::gMatrix3Zero<T>
 A Matrix3 initialized to zero. This is equivalent to math::Matrix3<T>(0, 0, 0, 0, 0, 0, 0, 0, 0).
 

Detailed Description

template<typename T>
class gz::math::Matrix3< T >

A 3x3 matrix class.

The following two type definitions are provided:

  • Matrix3i : Equivalent to Matrix3<int>
  • Matrix3f : Equivalent to Matrix3<float>
  • Matrix3d : Equivalent to Matrix3<double>

Examples

  • C++
#include <iostream>
int main(int argc, char **argv)
{
// Construct a default matrix3.
std::cout << "The default constructed matrix m has the following values.\n\t"
<< m << std::endl;
// Set the first column of the matrix.
m.SetCol(0, gz::math::Vector3d(3, 4, 5));
std::cout << "Setting the first column of the matrix m to 3, 4, 5.\n\t"
<< m << std::endl;
// Transpose the matrix.
std::cout << "The transposed matrix t has the values.\n\t"
<< t << std::endl;
// Multiply the two matrices.
std::cout << "m * t = " << m * t << std::endl;
}
  • Ruby
    # Modify the RUBYLIB environment variable to include the Gazebo Math
    # library install path. For example, if you install to /user:
    #
    # $ export RUBYLIB=/usr/lib/ruby:$RUBYLIB
    #
    require 'gz/math'
    # Construct a default matrix3.
    m = Gz::Math::Matrix3d.new
    printf("The default constructed matrix m has the following "+
    "values.\n\t" +
    "%2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f\n",
    m.(0, 0), m.(0, 1), m.(0, 2),
    m.(1, 0), m.(1, 1), m.(1, 2),
    m.(2, 0), m.(2, 1), m.(2, 2))
    # Set the first column of the matrix.
    m.SetCol(0, Gz::Math::Vector3d.new(3, 4, 5))
    printf("Setting the first column of the matrix m to 3, 4, 5.\n\t" +
    "%2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f\n",
    m.(0, 0), m.(0, 1), m.(0, 2),
    m.(1, 0), m.(1, 1), m.(1, 2),
    m.(2, 0), m.(2, 1), m.(2, 2))
    # Transpose the matrix.
    t = m.Transposed()
    printf("The transposed matrix t has the values.\n\t"+
    "%2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f\n",
    t.(0, 0), t.(0, 1), t.(0, 2),
    t.(1, 0), t.(1, 1), t.(1, 2),
    t.(2, 0), t.(2, 1), t.(2, 2))
    # Multiply the two matrices.
    m = m * t
    printf("m * t = " +
    "%2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f %2.1f\n",
    m.(0, 0), m.(0, 1), m.(0, 2),
    m.(1, 0), m.(1, 1), m.(1, 2),
    m.(2, 0), m.(2, 1), m.(2, 2))

Constructor & Destructor Documentation

◆ Matrix3() [1/3]

template<typename T >
Matrix3 ( )
inline

Default constructor that initializes the matrix3 to zero.

References std::memset().

◆ Matrix3() [2/3]

template<typename T >
constexpr Matrix3 ( _v00,
_v01,
_v02,
_v10,
_v11,
_v12,
_v20,
_v21,
_v22 
)
inlineconstexpr

Construct a matrix3 using nine values.

Parameters
[in]_v00Row 0, Col 0 value
[in]_v01Row 0, Col 1 value
[in]_v02Row 0, Col 2 value
[in]_v10Row 1, Col 0 value
[in]_v11Row 1, Col 1 value
[in]_v12Row 1, Col 2 value
[in]_v20Row 2, Col 0 value
[in]_v21Row 2, Col 1 value
[in]_v22Row 2, Col 2 value

◆ Matrix3() [3/3]

template<typename T >
Matrix3 ( const Quaternion< T > &  _q)
inlineexplicit

Construct 3x3 rotation Matrix from a quaternion.

Parameters
[in]_qQuaternion to set the Matrix3 from.

Member Function Documentation

◆ Determinant()

template<typename T >
T Determinant ( ) const
inline

Return the determinant of the matrix.

Returns
Determinant of this matrix.

◆ Equal()

template<typename T >
bool Equal ( const Matrix3< T > &  _m,
const T &  _tol 
) const
inline

Equality test with tolerance.

Parameters
[in]_mthe matrix to compare to
[in]_tolequality tolerance.
Returns
true if the elements of the matrices are equal within the tolerence specified by _tol.

◆ Inverse()

template<typename T >
Matrix3< T > Inverse ( ) const
inline

Return the inverse matrix.

Returns
Inverse of this matrix.

◆ operator!=()

template<typename T >
bool operator!= ( const Matrix3< T > &  _m) const
inline

Inequality test operator.

Parameters
[in]_mMatrix3<T> to test.
Returns
True if not equal (using the default tolerance of 1e-6).

◆ operator()() [1/2]

template<typename T >
T & operator() ( size_t  _row,
size_t  _col 
)
inline

Array subscript operator.

Parameters
[in]_rowrow index. _row is clamped to the range [0,2]
[in]_colcolumn index. _col is clamped to the range [0,2]
Returns
a pointer to the row

References gz::math::clamp(), gz::math::GZ_TWO_SIZE_T, and gz::math::GZ_ZERO_SIZE_T.

◆ operator()() [2/2]

template<typename T >
T operator() ( size_t  _row,
size_t  _col 
) const
inline

Array subscript operator.

Parameters
[in]_rowrow index. _row is clamped to the range [0,2]
[in]_colcolumn index. _col is clamped to the range [0,2]
Returns
a pointer to the row

References gz::math::clamp(), gz::math::GZ_TWO_SIZE_T, and gz::math::GZ_ZERO_SIZE_T.

◆ operator*() [1/3]

template<typename T >
Matrix3< T > operator* ( const Matrix3< T > &  _m) const
inline

Matrix multiplication operator.

Parameters
[in]_mMatrix3<T> to multiply
Returns
Product of this * _m

◆ operator*() [2/3]

template<typename T >
Matrix3< T > operator* ( const T &  _s) const
inline

Scalar multiplication operator.

Parameters
[in]_sValue to multiply.
Returns
The element wise scalar multiplication.

◆ operator*() [3/3]

template<typename T >
Vector3< T > operator* ( const Vector3< T > &  _vec) const
inline

Multiplication operator with Vector3 on the right treated like a column vector.

Parameters
_vecVector3
Returns
Resulting vector from multiplication

◆ operator+()

template<typename T >
Matrix3< T > operator+ ( const Matrix3< T > &  _m) const
inline

Addition operation.

Parameters
[in]_mMatrix to add.
Returns
The element wise sum of two matrices

◆ operator-()

template<typename T >
Matrix3< T > operator- ( const Matrix3< T > &  _m) const
inline

Subtraction operator.

Parameters
[in]_mMatrix to subtract.
Returns
The element wise difference of two matrices.

◆ operator=()

template<typename T >
Matrix3< T > & operator= ( const Quaternion< T > &  _q)
inline

Set as a 3x3 rotation matrix from a quaternion.

Parameters
[in]_qQuaternion to set the matrix3 from.
Returns
Reference to the new matrix3 object.

◆ operator==()

template<typename T >
bool operator== ( const Matrix3< T > &  _m) const
inline

Equality test operator.

Parameters
[in]_mMatrix3<T> to test.
Returns
True if equal (using the default tolerance of 1e-6).

◆ Set() [1/2]

template<typename T >
void Set ( size_t  _row,
size_t  _col,
_v 
)
inline

Set a single value.

Parameters
[in]_rowrow index. _row is clamped to the range [0,2]
[in]_colcolumn index. _col is clamped to the range [0,2]
[in]_vNew value.

References gz::math::clamp(), gz::math::GZ_TWO_SIZE_T, and gz::math::GZ_ZERO_SIZE_T.

◆ Set() [2/2]

template<typename T >
void Set ( _v00,
_v01,
_v02,
_v10,
_v11,
_v12,
_v20,
_v21,
_v22 
)
inline

Set values.

Parameters
[in]_v00Row 0, Col 0 value
[in]_v01Row 0, Col 1 value
[in]_v02Row 0, Col 2 value
[in]_v10Row 1, Col 0 value
[in]_v11Row 1, Col 1 value
[in]_v12Row 1, Col 2 value
[in]_v20Row 2, Col 0 value
[in]_v21Row 2, Col 1 value
[in]_v22Row 2, Col 2 value

◆ SetAxes()

template<typename T >
void SetAxes ( const Vector3< T > &  _xAxis,
const Vector3< T > &  _yAxis,
const Vector3< T > &  _zAxis 
)
inline

Set the matrix from three axis (1 per column).

Parameters
[in]_xAxisThe x axis, the first column of the matrix.
[in]_yAxisThe y axis, the second column of the matrix.
[in]_zAxisThe z axis, the third column of the matrix.

◆ SetCol()

template<typename T >
void SetCol ( unsigned int  _c,
const Vector3< T > &  _v 
)
inline

Set a column.

Parameters
[in]_cThe colum index [0, 1, 2]. _col is clamped to the range [0, 2].
[in]_vThe value to set in each row of the column.

References gz::math::clamp().

◆ SetFrom2Axes()

template<typename T >
void SetFrom2Axes ( const Vector3< T > &  _v1,
const Vector3< T > &  _v2 
)
inline

Set as a rotation matrix to represent rotation from vector _v1 to vector _v2, so that _v2.Normalize() == this * _v1.Normalize() holds.

Parameters
[in]_v1The first vector
[in]_v2The second vector

◆ SetFromAxisAngle()

template<typename T >
void SetFromAxisAngle ( const Vector3< T > &  _axis,
_angle 
)
inline

Set as a rotation matrix from an axis and angle.

Parameters
[in]_axisthe axis
[in]_angleccw rotation around the axis in radians

◆ Transpose()

template<typename T >
void Transpose ( )
inline

Transpose this matrix.

References std::swap().

◆ Transposed()

template<typename T >
Matrix3< T > Transposed ( ) const
inline

Return the transpose of this matrix.

Returns
Transpose of this matrix.

Member Data Documentation

◆ Identity

template<typename T >
const Matrix3< T > & Identity = detail::gMatrix3Identity<T>
static

A Matrix3 initialized to identity. This is equivalent to math::Matrix3<T>(1, 0, 0, 0, 1, 0, 0, 0, 1).

◆ Zero

template<typename T >
const Matrix3< T > & Zero = detail::gMatrix3Zero<T>
static

A Matrix3 initialized to zero. This is equivalent to math::Matrix3<T>(0, 0, 0, 0, 0, 0, 0, 0, 0).


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