IMP Reference Guide  develop.cb469e0f11,2024/05/28 The Integrative Modeling Platform
IMP::algebra::Rotation3D Class Reference

3D rotation class. More...

#include <IMP/algebra/Rotation3D.h>

Inheritance diagram for IMP::algebra::Rotation3D:

## Detailed Description

3D rotation class.

Rotations are currently represented using quaternions and a cached copy of the rotation matrix. The quaternion allows for fast and stable composition and the cached rotation matrix means that rotations are performed quickly. See https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation for a comparison of different implementations of rotations.

Currently the rotation can be initialized from either:

• XYZ Euler angles
• Rotation Matrix
• Quaternion
• angle/axis representation

Definition at line 52 of file Rotation3D.h.

## Public Member Functions

Rotation3D (const Rotation3D &rot)
Rotation3D copy constructor. More...

Rotation3D (const VectorD< 4 > &v, bool assume_normalized=false)

Rotation3D ()
Create an invalid rotation. More...

Rotation3D (double a, double b, double c, double d)
Create a rotation from a quaternion. More...

Vector3D get_gradient_of_rotated (const Vector3D &v, unsigned int i, bool wrt_unnorm=false) const
Return the gradient of rotated vector wrt the ith quaternion element. More...

Rotation3D get_inverse () const
Return the rotation which undoes this rotation. More...

bool get_is_valid () const

Eigen::MatrixXd get_jacobian_of_rotated (const Eigen::Vector3d &v, bool wrt_unnorm=false) const
Return the Jacobian of rotated vector wrt the quaternion. More...

const Vector4Dget_quaternion () const
Return the quaternion so that it can be stored. More...

Vector3D get_rotated (const Vector3D &o) const
Rotate a vector around the origin. More...

void get_rotated_adjoint (const Vector3D &v, const Vector3D &Dw, Vector3D *Dv, Rotation3DAdjoint *Dr) const
Get adjoint of inputs to get_rotated from adjoint of output. More...

Get adjoint of inputs to get_rotated from adjoint of output. More...

double get_rotated_one_coordinate (const Vector3D &o, unsigned int coord) const
Get only the requested rotation coordinate of the vector. More...

Vector3D get_rotation_matrix_row (int i) const

Vector3D operator* (const Vector3D &v) const
Rotate a vector around the origin. More...

Rotation3D operator* (const Rotation3D &q) const
Multiply two rotations. More...

Rotation3D operator/ (const Rotation3D &r) const
Compute the rotation which when composed with r gives this. More...

const Rotation3Doperator/= (const Rotation3D &r)

Rotation3Doperator= (const Rotation3D &rot)

void show (std::ostream &out=std::cout) const

## Friends

Rotation3D compose (const Rotation3D &a, const Rotation3D &b)

## Constructor & Destructor Documentation

 IMP::algebra::Rotation3D::Rotation3D ( const Rotation3D & rot )

Rotation3D copy constructor.

Definition at line 106 of file Rotation3D.h.

 IMP::algebra::Rotation3D::Rotation3D ( const VectorD< 4 > & v, bool assume_normalized = false )
explicit

Create a rotation from a vector of 4 quaternion coefficients.

Note
: use assume_normalized with care - inputting an unnormalized vector would result in unexpected results if it is true

Definition at line 119 of file Rotation3D.h.

 IMP::algebra::Rotation3D::Rotation3D ( )

Create an invalid rotation.

Definition at line 125 of file Rotation3D.h.

 IMP::algebra::Rotation3D::Rotation3D ( double a, double b, double c, double d )

Create a rotation from a quaternion.

Exceptions
 ValueException if the rotation is not a unit vector.

Definition at line 129 of file Rotation3D.h.

## Member Function Documentation

 Vector3D IMP::algebra::Rotation3D::get_gradient_of_rotated ( const Vector3D & v, unsigned int i, bool wrt_unnorm = false ) const

Return the gradient of rotated vector wrt the ith quaternion element.

Given the rotation $$x = R(q) v$$, where $$v$$ is a vector, $$q=(q_0,q_1,q_2,q_3)$$ is the quaternion of the rotation with elements $$q_i$$, and $$R(q)$$ is the corresponding rotation matrix, the function returns the gradient $$\nabla_{q_i} x$$.

This function just returns a single column from get_jacobian(), so it is more efficient to call that function if all columns are needed.

Parameters
 [in] v vector to be rotated by rotation $$R(q)$$ [in] wrt_unnorm Gradient is computed wrt unnormalized quaternion. Rotation includes a normalization operation, and the gradient is projected to the tangent space at $$q$$.
 Rotation3D IMP::algebra::Rotation3D::get_inverse ( ) const

Return the rotation which undoes this rotation.

Definition at line 234 of file Rotation3D.h.

 bool IMP::algebra::Rotation3D::get_is_valid ( ) const

Return true is the rotation is valid, false if invalid or not initialized (e.g., only initialized by the empty constructor)

Definition at line 307 of file Rotation3D.h.

 Eigen::MatrixXd IMP::algebra::Rotation3D::get_jacobian_of_rotated ( const Eigen::Vector3d & v, bool wrt_unnorm = false ) const

Return the Jacobian of rotated vector wrt the quaternion.

Given the rotation $$x = R(q) v$$, where $$v$$ is a vector, $$q$$ is the quaternion of the rotation, and $$R(q)$$ is the corresponding rotation matrix, the function returns the 3x4 matrix $$J$$ with elements $$J_{ij}=\frac{\partial x_i}{\partial q_j}$$.

Parameters
 [in] v vector to be rotated by rotation $$R(q)$$ [in] wrt_unnorm Jacobian is computed wrt unnormalized quaternion. Rotation includes a normalization operation, and the columns are projected to the tangent space at $$q$$.
 const Vector4D& IMP::algebra::Rotation3D::get_quaternion ( ) const

Return the quaternion so that it can be stored.

Note that there is no guarantee on which of the two equivalent quaternions is returned.

Definition at line 245 of file Rotation3D.h.

 Vector3D IMP::algebra::Rotation3D::get_rotated ( const Vector3D & o ) const

Rotate a vector around the origin.

Definition at line 193 of file Rotation3D.h.

 void IMP::algebra::Rotation3D::get_rotated_adjoint ( const Vector3D & v, const Vector3D & Dw, Vector3D * Dv, Rotation3DAdjoint * Dr ) const

Get adjoint of inputs to get_rotated from adjoint of output.

Compute the adjoint (reverse-mode sensitivity) of input vector to get_rotated and this rotation from the adjoint of the output vector.

 RotatedVector3DAdjoint IMP::algebra::Rotation3D::get_rotated_adjoint ( const Vector3D & v, const Vector3D & Dw ) const

Get adjoint of inputs to get_rotated from adjoint of output.

Compute the adjoint (reverse-mode sensitivity) of input vector to get_rotated and this rotation from the adjoint of the output vector.

 double IMP::algebra::Rotation3D::get_rotated_one_coordinate ( const Vector3D & o, unsigned int coord ) const

Get only the requested rotation coordinate of the vector.

Definition at line 217 of file Rotation3D.h.

 Vector3D IMP::algebra::Rotation3D::operator* ( const Vector3D & v ) const

Rotate a vector around the origin.

Definition at line 224 of file Rotation3D.h.

 Rotation3D IMP::algebra::Rotation3D::operator* ( const Rotation3D & q ) const

Multiply two rotations.

Definition at line 252 of file Rotation3D.h.

Here is the call graph for this function:

 Rotation3D IMP::algebra::Rotation3D::operator/ ( const Rotation3D & r ) const

Compute the rotation which when composed with r gives this.

Definition at line 259 of file Rotation3D.h.

Here is the call graph for this function:

## Friends And Related Function Documentation

 Rotation3D compose ( const Rotation3D & a, const Rotation3D & b )
friend