C Attitude Math Library
Quaternion, Euler, and DCM math utilities for attitude control.
Loading...
Searching...
No Matches
euler.h File Reference

Go to the source code of this file.

Data Structures

struct  EulerAngles
 Storage for Euler angles with an associated rotation order. More...
 

Enumerations

enum  EulerOrder { EULER_ZYX , EULER_ZYZ , EULER_XYZ }
 Enumeration of supported Euler rotation orders. More...
 

Functions

void euler_to_dcm (const EulerAngles *e, double dcm[3][3])
 Convert Euler angles to a direction cosine matrix.
 
int euler_to_dcm_checked (const EulerAngles *e, double dcm[3][3])
 Checked Euler-to-DCM conversion.
 
void euler_to_quaternion (const EulerAngles *e, double q[4])
 Convert Euler angles to a quaternion.
 
int euler_to_quaternion_checked (const EulerAngles *e, double q[4])
 Checked Euler-to-quaternion conversion.
 

Enumeration Type Documentation

◆ EulerOrder

enum EulerOrder

Enumeration of supported Euler rotation orders.

The library currently implements intrinsic ZYX rotations. The other values are reserved so callers can reject unsupported inputs through the checked API.

Enumerator
EULER_ZYX 

Standard aerospace yaw → pitch → roll sequence.

EULER_ZYZ 

Useful for certain satellite pointing laws and robotics arms.

EULER_XYZ 

Roll → pitch → yaw intrinsic sequence.

Definition at line 14 of file euler.h.

14 {
15 EULER_ZYX,
16 EULER_ZYZ,
17 EULER_XYZ,
18 // Extend with other orders as needed.
EulerOrder
Enumeration of supported Euler rotation orders.
Definition euler.h:14
@ EULER_ZYX
Standard aerospace yaw → pitch → roll sequence.
Definition euler.h:15
@ EULER_XYZ
Roll → pitch → yaw intrinsic sequence.
Definition euler.h:17
@ EULER_ZYZ
Useful for certain satellite pointing laws and robotics arms.
Definition euler.h:16

Function Documentation

◆ euler_to_dcm()

void euler_to_dcm ( const EulerAngles *  e,
double  dcm[3][3] 
)

Convert Euler angles to a direction cosine matrix.

Parameters
eEuler angle container in radians.
dcmOutput \(3\times3\) matrix (row-major).

Definition at line 41 of file euler.c.

41 {
42 if (!euler_to_dcm_checked(e, dcm)) {
43 set_nan_matrix(dcm);
44 }
45}
int euler_to_dcm_checked(const EulerAngles *e, double dcm[3][3])
Checked Euler-to-DCM conversion.
Definition euler.c:16

◆ euler_to_dcm_checked()

int euler_to_dcm_checked ( const EulerAngles *  e,
double  dcm[3][3] 
)

Checked Euler-to-DCM conversion.

Returns
1 on success, 0 for null pointers, non-finite angles, or an unsupported order.

Definition at line 16 of file euler.c.

16 {
17 if (e == NULL || dcm == NULL || e->order != EULER_ZYX ||
18 !isfinite(e->roll) || !isfinite(e->pitch) || !isfinite(e->yaw)) {
19 return 0;
20 }
21
22 double cr = cos(e->roll);
23 double sr = sin(e->roll);
24 double cp = cos(e->pitch);
25 double sp = sin(e->pitch);
26 double cy = cos(e->yaw);
27 double sy = sin(e->yaw);
28
29 dcm[0][0] = cy*cp;
30 dcm[0][1] = cy*sp*sr - sy*cr;
31 dcm[0][2] = cy*sp*cr + sy*sr;
32 dcm[1][0] = sy*cp;
33 dcm[1][1] = sy*sp*sr + cy*cr;
34 dcm[1][2] = sy*sp*cr - cy*sr;
35 dcm[2][0] = -sp;
36 dcm[2][1] = cp*sr;
37 dcm[2][2] = cp*cr;
38 return 1;
39}
double pitch
Rotation about y-axis.
Definition euler.h:28
double yaw
Rotation about z-axis.
Definition euler.h:29
EulerOrder order
Intrinsic rotation order.
Definition euler.h:30
double roll
Rotation about x-axis.
Definition euler.h:27

◆ euler_to_quaternion()

void euler_to_quaternion ( const EulerAngles *  e,
double  q[4] 
)

Convert Euler angles to a quaternion.

Parameters
eEuler angle container in radians.
qOutput quaternion in \([w, x, y, z]\) order.

Definition at line 67 of file euler.c.

67 {
68 if (!euler_to_quaternion_checked(e, q) && q != NULL) {
69 for (int index = 0; index < 4; ++index) {
70 q[index] = NAN;
71 }
72 }
73}
int euler_to_quaternion_checked(const EulerAngles *e, double q[4])
Checked Euler-to-quaternion conversion.
Definition euler.c:47

◆ euler_to_quaternion_checked()

int euler_to_quaternion_checked ( const EulerAngles *  e,
double  q[4] 
)

Checked Euler-to-quaternion conversion.

Returns
1 on success, 0 for null pointers, non-finite angles, or an unsupported order.

Definition at line 47 of file euler.c.

47 {
48 if (e == NULL || q == NULL || e->order != EULER_ZYX ||
49 !isfinite(e->roll) || !isfinite(e->pitch) || !isfinite(e->yaw)) {
50 return 0;
51 }
52
53 double cr = cos(e->roll/2.0);
54 double sr = sin(e->roll/2.0);
55 double cp = cos(e->pitch/2.0);
56 double sp = sin(e->pitch/2.0);
57 double cy = cos(e->yaw/2.0);
58 double sy = sin(e->yaw/2.0);
59
60 q[0] = cr*cp*cy + sr*sp*sy; // w
61 q[1] = sr*cp*cy - cr*sp*sy; // x
62 q[2] = cr*sp*cy + sr*cp*sy; // y
63 q[3] = cr*cp*sy - sr*sp*cy; // z
64 return 1;
65}