CARLA
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
carla::geom::Quaternion Class Reference

Quaternion representing a 3D rotation, stored as (x, y, z, w). More...

#include <Quaternion.h>

Public Member Functions

Quaternion Conjugate () const
 Conjugate of this quaternion.
 
Vector3D GetForwardVector () const
 Unit vector pointing toward the local X axis of this rotation, expressed in CARLA's left-handed frame.
 
Vector3D GetRightVector () const
 Unit vector pointing toward the local Y axis of this rotation, expressed in CARLA's left-handed frame.
 
Vector3D GetUpVector () const
 Unit vector pointing toward the local Z axis of this rotation, expressed in CARLA's left-handed frame.
 
Quaternion Inverse () const
 Inverse of this quaternion (assumes non-zero norm).
 
RightHandedVector3D InverseRotatedVector (const RightHandedVector3D &in) const
 Inverse rotation of a right-handed vector.
 
float Length () const
 
 MSGPACK_DEFINE_ARRAY (x, y, z, w)
 
bool operator!= (const Quaternion &rhs) const
 
Quaternion operator* (const Quaternion &rhs) const
 Hamilton product (*this) * rhs.
 
bool operator== (const Quaternion &rhs) const
 
 Quaternion ()=default
 
 Quaternion (const RightHandedRotation &rotation)
 Quaternion of a right-handed (FLU) Euler triple, degrees, intrinsic Z-Y-X: q = qz(yaw) * qy(pitch) * qx(roll).
 
 Quaternion (const Rotation &rotation)
 Quaternion of a CARLA (left-handed) Euler rotation, degrees.
 
constexpr Quaternion (float ix, float iy, float iz, float iw)
 
RightHandedVector3D RotatedVector (const RightHandedVector3D &in) const
 Rotate a right-handed vector by this quaternion.
 
Rotation Rotator () const
 Convert this quaternion back to a CARLA (left-handed) Euler rotation.
 
RightHandedRotation ToRightHandedRotation () const
 This rotation as right-handed (FLU) Euler angles, degrees, intrinsic Z-Y-X.
 
Quaternion UnitQuaternion () const
 

Public Attributes

float w = 1.0f
 
float x = 0.0f
 
float y = 0.0f
 
float z = 0.0f
 

Detailed Description

Quaternion representing a 3D rotation, stored as (x, y, z, w).

Frame: right-handed, x forward / y left / z up (ROS REP-103 "FLU"). It is the quaternion of RightHandedRotation, not of CARLA's left-handed Rotation, and it is bit-for-bit the one the ROS 2 bridge publishes (ros2::TransformFromCarlaRotation in carla/ros2/publishers/TransformQuaternion.h).

The Quaternion(const Rotation &) constructor therefore performs a handedness change: it routes through Rotation::ToRightHanded(), which negates yaw and pitch and leaves roll alone. (The #9751 commit message says "yaw and roll"; that is wrong – see Docs/coordinate_conventions.md.) With those signs the basis vectors of Quaternion(r) – which convert back to CARLA's frame on the way out – reproduce, column for column, the matrix of Rotation::RotateVector and Transform::GetMatrix.

Definition at line 37 of file geom/Quaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

carla::geom::Quaternion::Quaternion ( )
default

◆ Quaternion() [2/4]

constexpr carla::geom::Quaternion::Quaternion ( float  ix,
float  iy,
float  iz,
float  iw 
)
inlineconstexpr

Definition at line 57 of file geom/Quaternion.h.

◆ Quaternion() [3/4]

carla::geom::Quaternion::Quaternion ( const RightHandedRotation &  rotation)
inlineexplicit

Quaternion of a right-handed (FLU) Euler triple, degrees, intrinsic Z-Y-X: q = qz(yaw) * qy(pitch) * qx(roll).

This is the textbook right-handed roll-pitch-yaw formula – no sign tricks live here.

Definition at line 67 of file geom/Quaternion.h.

References carla::geom::RightHandedRotation::pitch, carla::geom::RightHandedRotation::roll, w, x, y, carla::geom::RightHandedRotation::yaw, and z.

◆ Quaternion() [4/4]

carla::geom::Quaternion::Quaternion ( const Rotation &  rotation)
inlineexplicit

Quaternion of a CARLA (left-handed) Euler rotation, degrees.

The handedness change happens exactly once, in Rotation::ToRightHanded(): yaw and pitch are negated, roll is not. The resulting (x, y, z, w) is in the right-handed FLU frame and is the value the ROS 2 bridge publishes.

Definition at line 94 of file geom/Quaternion.h.

Member Function Documentation

◆ Conjugate()

Quaternion carla::geom::Quaternion::Conjugate ( ) const
inline

Conjugate of this quaternion.

For a unit quaternion the conjugate is also its inverse.

Definition at line 191 of file geom/Quaternion.h.

References Quaternion(), w, x, y, and z.

Referenced by TEST().

◆ GetForwardVector()

Vector3D carla::geom::Quaternion::GetForwardVector ( ) const
inline

Unit vector pointing toward the local X axis of this rotation, expressed in CARLA's left-handed frame.

The canonical axes are passed through the Vector3D -> RightHandedVector3D boundary conversion so the Y-sign flip happens on both ends of the rotation.

Definition at line 173 of file geom/Quaternion.h.

References RotatedVector().

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ GetRightVector()

Vector3D carla::geom::Quaternion::GetRightVector ( ) const
inline

Unit vector pointing toward the local Y axis of this rotation, expressed in CARLA's left-handed frame.

Definition at line 179 of file geom/Quaternion.h.

References RotatedVector().

Referenced by TEST(), and TEST().

◆ GetUpVector()

Vector3D carla::geom::Quaternion::GetUpVector ( ) const
inline

Unit vector pointing toward the local Z axis of this rotation, expressed in CARLA's left-handed frame.

Definition at line 185 of file geom/Quaternion.h.

References RotatedVector().

Referenced by TEST(), and TEST().

◆ Inverse()

Quaternion carla::geom::Quaternion::Inverse ( ) const
inline

Inverse of this quaternion (assumes non-zero norm).

Definition at line 196 of file geom/Quaternion.h.

References Quaternion(), w, x, y, and z.

Referenced by InverseRotatedVector(), TEST(), and TEST().

◆ InverseRotatedVector()

RightHandedVector3D carla::geom::Quaternion::InverseRotatedVector ( const RightHandedVector3D &  in) const
inline

Inverse rotation of a right-handed vector.

For a unit quaternion this is equivalent to rotating by the conjugate.

Definition at line 165 of file geom/Quaternion.h.

References Inverse(), and RotatedVector().

◆ Length()

float carla::geom::Quaternion::Length ( ) const
inline

Definition at line 205 of file geom/Quaternion.h.

References w, x, y, and z.

Referenced by UnitQuaternion().

◆ MSGPACK_DEFINE_ARRAY()

carla::geom::Quaternion::MSGPACK_DEFINE_ARRAY ( x  ,
y  ,
z  ,
w   
)

◆ operator!=()

bool carla::geom::Quaternion::operator!= ( const Quaternion &  rhs) const
inline

Definition at line 235 of file geom/Quaternion.h.

◆ operator*()

Quaternion carla::geom::Quaternion::operator* ( const Quaternion &  rhs) const
inline

Hamilton product (*this) * rhs.

Definition at line 219 of file geom/Quaternion.h.

References Quaternion(), w, x, y, and z.

◆ operator==()

bool carla::geom::Quaternion::operator== ( const Quaternion &  rhs) const
inline

Definition at line 231 of file geom/Quaternion.h.

References w, x, y, and z.

◆ RotatedVector()

RightHandedVector3D carla::geom::Quaternion::RotatedVector ( const RightHandedVector3D &  in) const
inline

Rotate a right-handed vector by this quaternion.

Computes q * v_pure * q_conjugate via the Rodrigues form v + 2w*(q.xyz x v) + 2*(q.xyz x (q.xyz x v)).

Definition at line 148 of file geom/Quaternion.h.

References w, x, carla::geom::RightHandedVector3D::x, y, carla::geom::RightHandedVector3D::y, z, and carla::geom::RightHandedVector3D::z.

Referenced by GetForwardVector(), GetRightVector(), GetUpVector(), InverseRotatedVector(), TEST(), and TEST().

◆ Rotator()

Rotation carla::geom::Quaternion::Rotator ( ) const
inline

Convert this quaternion back to a CARLA (left-handed) Euler rotation.

Inverse of the Quaternion(Rotation) constructor; the handedness change is undone once, by Rotation::FromRightHanded().

Definition at line 126 of file geom/Quaternion.h.

References carla::geom::Rotation::FromRightHanded(), w, x, y, and z.

◆ ToRightHandedRotation()

RightHandedRotation carla::geom::Quaternion::ToRightHandedRotation ( ) const
inline

This rotation as right-handed (FLU) Euler angles, degrees, intrinsic Z-Y-X.

Inverse of Quaternion(const RightHandedRotation &).

Definition at line 104 of file geom/Quaternion.h.

References w, x, y, and z.

Referenced by TEST().

◆ UnitQuaternion()

Quaternion carla::geom::Quaternion::UnitQuaternion ( ) const
inline

Definition at line 209 of file geom/Quaternion.h.

References Length(), Quaternion(), w, x, y, and z.

Member Data Documentation

◆ w

float carla::geom::Quaternion::w = 1.0f

◆ x

float carla::geom::Quaternion::x = 0.0f

◆ y

float carla::geom::Quaternion::y = 0.0f

◆ z

float carla::geom::Quaternion::z = 0.0f

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