My Project
 
Loading...
Searching...
No Matches
Quaternion Class Reference

#include <Quaternion.h>

Public Member Functions

 Quaternion (float w_, float x_, float y_, float z_)
 
Quaternion operator* (Quaternion qt)
 
Quaternion operator*= (Quaternion qt)
 
Quaternion normalize ()
 
Quaternion conjugate ()
 
Vector3 rotate_vector (Vector3 vt)
 
Quaternion from_axis_angle (float theta, Vector3 vt)
 
Vector3 quaternion_to_euler ()
 
Quaternion euler_to_quaternion (Vector3 vt)
 
Quaternion update_with_rates (float dt, Vector3 rates)
 
Quaternion update_with_accel (Vector3 at, Vector3 target_vector, float gain)
 
Quaternion update_with_mag (Vector3 mt, Vector3 at, Vector3 target_vector, Quaternion declination_compensation, float gain)
 

Public Attributes

float w
 
float x
 
float y
 
float z
 

Detailed Description

Class to perform quaternion math

w - x - y - z components

Input for euler angle and other orientation math: X Roll Y Pitch Z Yaw Euler rotation order: Z - Y - X

Member Function Documentation

◆ conjugate()

Quaternion Quaternion::conjugate ( )

Calculates conjugate of quaternion (backwards rotation)

Returns
Conjugate of this quaternion

◆ euler_to_quaternion()

Quaternion Quaternion::euler_to_quaternion ( Vector3 vt)

Converts XYZ Euler angles to a quaternion representation (Z-Y-X Yaw-Pitch-Roll order)

Parameters
vtEuler angles vector (Roll - Pitch - Yaw)
Returns
This quaternion after conversion

◆ from_axis_angle()

Quaternion Quaternion::from_axis_angle ( float theta,
Vector3 vt )

Sets quaternion from axis-angle representation

Parameters
thetaAngle component
vtVector component
Returns
This quaternion after conversion

◆ normalize()

Quaternion Quaternion::normalize ( )

Returns normalized quaternion (sets length to 1) if its magnitude is not zero

Returns
Normalized quaternion

◆ operator*()

Quaternion Quaternion::operator* ( Quaternion qt)

Quaternion product operator

Parameters
qtOther quaternion to do the product with
Returns
This quaternion

◆ operator*=()

Quaternion Quaternion::operator*= ( Quaternion qt)

Quaternion product operator, updates the current quaternion

Parameters
qtOther quaternion to do the product with
Returns
This quaternion

◆ quaternion_to_euler()

Vector3 Quaternion::quaternion_to_euler ( )

Calculates euler representation of quaternion rotation (Z-Y-X Yaw-Pitch-Roll)

Returns
Euler angles vector (Roll - Pitch - Yaw)

◆ rotate_vector()

Vector3 Quaternion::rotate_vector ( Vector3 vt)

Returns Vector3 rotated by a quaternion

Parameters
vtVector3 to be rotated
Returns
vt after rotation

◆ update_with_accel()

Quaternion Quaternion::update_with_accel ( Vector3 at,
Vector3 target_vector,
float gain )

Updates quaternion from inertial-frame accelerometer readings, (x = +1g | +9.8m/s^2). Algorithm works on the idea that the x axis (upwards) should have all the acceleration while y and z should be zero

Parameters
vtDimensionless inertial accelerometer measurements
target_vectorVector to which the accelerometers should "point at"
gainHow much to rotate quaternion by (0 - 1.0f)
Returns
This quaternion after updating

◆ update_with_mag()

Quaternion Quaternion::update_with_mag ( Vector3 mt,
Vector3 at,
Vector3 target_vector,
Quaternion declination_compensation,
float gain )

Updates quaternion from body-frame magnetometer readings in the same manner the accelerometer update does

Parameters
mtDimensionless body magnetometer measurements
atDimensionless body accelerometer measurements
target_vectorVector to which EAST should "point at"
gainHow much to rotate quaternion by (0 - 1.0f)
Returns
This quaternion after updating

◆ update_with_rates()

Quaternion Quaternion::update_with_rates ( float dt,
Vector3 rates )

Updates quaternion from body-axis angular rates

Parameters
ratesRadian angular rates
dtDelta time
Returns
This quaternion after updating

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