Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
No Matches
quaternions.c File Reference

Functions related to 3D quaternions and Euler angles. More...

#include <stdio.h>
#include <math.h>
#include <assert.h>
#include "geometry_datatypes.h"
Include dependency graph for quaternions.c:


quaternion quat_from_euler (const euler *in_euler)
 Function to convert given Euler angles to a quaternion.
euler euler_from_quat (const quaternion *in_quat)
 Function to convert given quaternion to Euler angles.
quaternion quaternion_multiply (const quaternion *in_quat1, const quaternion *in_quat2)
 Function to multiply two quaternions.
static void test ()
int main ()

Detailed Description

Functions related to 3D quaternions and Euler angles.

Krishna Vedala

Function Documentation

◆ main()

int main ( void  )
171 test();
172 return 0;
void test()
Test function.
Definition decimal_to_binary_recursion.c:20

◆ test()

static void test ( void  )
155 quaternion quat = {0.7071f, 0.7071f, 0.f, 0.f};
156 euler eul = euler_from_quat(&quat);
157 printf("Euler: %.4g, %.4g, %.4g\n", eul.pitch, eul.roll, eul.yaw);
159 quaternion test_quat = quat_from_euler(&eul);
160 printf("Quaternion: %.4g %+.4g %+.4g %+.4g\n", test_quat.w,
161 test_quat.dual.x, test_quat.dual.y, test_quat.dual.z);
163 assert(fabsf(test_quat.w - quat.w) < .01);
164 assert(fabsf(test_quat.q1 - quat.q1) < .01);
165 assert(fabsf(test_quat.q2 - quat.q2) < .01);
166 assert(fabsf(test_quat.q3 - quat.q3) < .01);
euler euler_from_quat(const quaternion *in_quat)
Function to convert given quaternion to Euler angles.
Definition quaternions.c:88
quaternion quat_from_euler(const euler *in_euler)
Function to convert given Euler angles to a quaternion.
Definition quaternions.c:47
3D Euler or Tait-Bryan angles (in radian)
Definition geometry_datatypes.h:81
float roll
or bank = rotation about X axis
Definition geometry_datatypes.h:84
float pitch
or elevation = rotation about Y axis
Definition geometry_datatypes.h:89
float yaw
or heading = rotation about Z axis
Definition geometry_datatypes.h:94
a Quaternion type represented using a scalar or and a 3D vector
Definition geometry_datatypes.h:61
vec_3d dual
can be a 3D vector
Definition geometry_datatypes.h:70
float w
real part of quaternion
Definition geometry_datatypes.h:64
float z
Z co-ordinate.
Definition geometry_datatypes.h:25
float x
X co-ordinate.
Definition geometry_datatypes.h:23
float y
Y co-ordinate.
Definition geometry_datatypes.h:24