Zephyr Scientific Library (zscilib)
quaternions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 Kevin Townsend
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
66 #ifndef ZEPHYR_INCLUDE_ZSL_QUATERNIONS_H_
67 #define ZEPHYR_INCLUDE_ZSL_QUATERNIONS_H_
68 
69 #include <zsl/zsl.h>
70 #include <zsl/matrices.h>
71 #include <zsl/orientation/euler.h>
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
89 struct zsl_quat {
90  union {
91  struct {
96  };
97  struct {
102  } alias;
104  };
105 };
106 
121 };
122  /* End of QUAT_STRUCTS group */
124 
140 void zsl_quat_init(struct zsl_quat *q, enum zsl_quat_type type);
141  /* End of QUAT_INIT group */
143 
165 
189 int zsl_quat_to_unit(struct zsl_quat *q, struct zsl_quat *qn);
190 
198 int zsl_quat_to_unit_d(struct zsl_quat *q);
199 
209 bool zsl_quat_is_unit(struct zsl_quat *q);
210 
220 int zsl_quat_scale(struct zsl_quat *q, zsl_real_t s, struct zsl_quat *qs);
221 
231 int zsl_quat_scale_d(struct zsl_quat *q, zsl_real_t s);
232 
248 int zsl_quat_mult(struct zsl_quat *qa, struct zsl_quat *qb,
249  struct zsl_quat *qm);
250 
259 int zsl_quat_exp(struct zsl_quat *q, struct zsl_quat *qe);
260 
269 int zsl_quat_log(struct zsl_quat *q, struct zsl_quat *ql);
270 
281 int zsl_quat_pow(struct zsl_quat *q, zsl_real_t pow,
282  struct zsl_quat *qout);
283 
292 int zsl_quat_conj(struct zsl_quat *q, struct zsl_quat *qc);
293 
306 int zsl_quat_inv(struct zsl_quat *q, struct zsl_quat *qi);
307 
315 int zsl_quat_inv_d(struct zsl_quat *q);
316 
327 int zsl_quat_diff(struct zsl_quat *qa, struct zsl_quat *qb,
328  struct zsl_quat *qd);
329 
342 int zsl_quat_rot(struct zsl_quat *qa, struct zsl_quat *qb,
343  struct zsl_quat *qr);
344 
359 int zsl_quat_lerp(struct zsl_quat *qa, struct zsl_quat *qb,
360  zsl_real_t t, struct zsl_quat *qi);
361 
378 int zsl_quat_slerp(struct zsl_quat *qa, struct zsl_quat *qb,
379  zsl_real_t t, struct zsl_quat *qi);
380 
398 int zsl_quat_from_ang_vel(struct zsl_vec *w, struct zsl_quat *qin,
399  zsl_real_t t, struct zsl_quat *qout);
400 
423 int zsl_quat_from_ang_mom(struct zsl_vec *l, struct zsl_quat *qin,
424  zsl_real_t *i, zsl_real_t t, struct zsl_quat *qout);
425 
435 int zsl_quat_to_euler(struct zsl_quat *q, struct zsl_euler *e);
436 
446 int zsl_quat_from_euler(struct zsl_euler *e, struct zsl_quat *q);
447 
456 int zsl_quat_to_rot_mtx(struct zsl_quat *q, struct zsl_mtx *m);
457 
466 int zsl_quat_from_rot_mtx(struct zsl_mtx *m, struct zsl_quat *q);
467 
478 int zsl_quat_to_axis_angle(struct zsl_quat *q, struct zsl_vec *a,
479  zsl_real_t *b);
480 
492  struct zsl_quat *q);
493 
502 int zsl_quat_print(struct zsl_quat *q);
503  /* End of QUAT_FUNCTIONS group */
505  /* End of QUATERNIONS group */
507 
508 #ifdef __cplusplus
509 }
510 #endif
511 
512 #endif /* ZEPHYR_INCLUDE_ZSL_QUATERNIONS_H_ */
zsl_quat_to_unit_d
int zsl_quat_to_unit_d(struct zsl_quat *q)
Normalises to unit quaternion (destructive).
zsl_quat_magn
zsl_real_t zsl_quat_magn(struct zsl_quat *q)
Calculates the magnitude (or length) of the quaternion, a scalar value equal to the square root of th...
zsl_quat_scale
int zsl_quat_scale(struct zsl_quat *q, zsl_real_t s, struct zsl_quat *qs)
Multiples each element in the quaternion by a scalar value.
zsl_quat_to_axis_angle
int zsl_quat_to_axis_angle(struct zsl_quat *q, struct zsl_vec *a, zsl_real_t *b)
Converts a unit quaternion to it's axis-angle rotation equivalent.
zsl_quat::idx
zsl_real_t idx[4]
Allows access as an array.
Definition: quaternions.h:103
zsl_quat::y
zsl_real_t y
The second vector component.
Definition: quaternions.h:100
zsl_quat
Represents a quaternion, a 4D structure capable of representing 3D rigid body orientations.
Definition: quaternions.h:89
zsl_quat_inv
int zsl_quat_inv(struct zsl_quat *q, struct zsl_quat *qi)
Calculates the multiplicative inverse of unit quaternion 'q'.
zsl_quat::k
zsl_real_t k
The third imaginary component.
Definition: quaternions.h:95
zsl_quat_to_unit
int zsl_quat_to_unit(struct zsl_quat *q, struct zsl_quat *qn)
Normalises the input to be a "unit" or "rotation" quaternion, AKA a versor, such that the square root...
zsl_quat_from_ang_mom
int zsl_quat_from_ang_mom(struct zsl_vec *l, struct zsl_quat *qin, zsl_real_t *i, zsl_real_t t, struct zsl_quat *qout)
Updates an orientation quaternion with new information in form of angular momentum,...
zsl_mtx
Represents a m x n matrix, with data stored in row-major order.
Definition: matrices.h:46
zsl_quat::i
zsl_real_t i
The first imaginary component.
Definition: quaternions.h:93
zsl_quat_slerp
int zsl_quat_slerp(struct zsl_quat *qa, struct zsl_quat *qb, zsl_real_t t, struct zsl_quat *qi)
Spherical linear interpolation (SLERP).
zsl_quat_to_rot_mtx
int zsl_quat_to_rot_mtx(struct zsl_quat *q, struct zsl_mtx *m)
Converts a unit quaternion to it's equivalent rotation matrix.
zsl_quat_diff
int zsl_quat_diff(struct zsl_quat *qa, struct zsl_quat *qb, struct zsl_quat *qd)
Calculates the rotation (qd) from qa to qb using the multiplicative inverse, such that qb = qa * qd.
zsl_quat_from_rot_mtx
int zsl_quat_from_rot_mtx(struct zsl_mtx *m, struct zsl_quat *q)
Converts a rotation matrix to it's equivalent unit quaternion.
zsl_quat_to_euler
int zsl_quat_to_euler(struct zsl_quat *q, struct zsl_euler *e)
Converts a unit quaternion to it's equivalent Euler angle. Euler values expressed in radians.
zsl_quat_mult
int zsl_quat_mult(struct zsl_quat *qa, struct zsl_quat *qb, struct zsl_quat *qm)
Multiples the two supplied unit quaternions (a * b) together, and stores the results in qm.
zsl_euler
An ordered triplet of real numbers describing the orientation of a rigid body in three-dimensional (E...
Definition: euler.h:43
zsl_quat_exp
int zsl_quat_exp(struct zsl_quat *q, struct zsl_quat *qe)
Calculates the exponential of a unit quaternion.
zsl_quat_from_ang_vel
int zsl_quat_from_ang_vel(struct zsl_vec *w, struct zsl_quat *qin, zsl_real_t t, struct zsl_quat *qout)
Updates an orientation quaternion with new information in form of angular velocity and time elapsed.
zsl_quat_conj
int zsl_quat_conj(struct zsl_quat *q, struct zsl_quat *qc)
Calculates the complex conjugate of 'q'.
zsl_quat_init
void zsl_quat_init(struct zsl_quat *q, enum zsl_quat_type type)
Convenience function to set the supplied quaternion into a known state.
zsl_quat::j
zsl_real_t j
The second imaginary component.
Definition: quaternions.h:94
ZSL_QUAT_TYPE_EMPTY
@ ZSL_QUAT_TYPE_EMPTY
Definition: quaternions.h:115
zsl_quat_inv_d
int zsl_quat_inv_d(struct zsl_quat *q)
Inverts unit quaternion 'q' (destructive).
zsl_quat_from_euler
int zsl_quat_from_euler(struct zsl_euler *e, struct zsl_quat *q)
Converts a Euler angle to a unit quaternion. Euler values expressed in radians.
zsl_quat::x
zsl_real_t x
The first vector component.
Definition: quaternions.h:99
zsl_quat::r
zsl_real_t r
The real component.
Definition: quaternions.h:92
zsl_quat_rot
int zsl_quat_rot(struct zsl_quat *qa, struct zsl_quat *qb, struct zsl_quat *qr)
Rotates the pure quaternion qb using the quaternion qa.
zsl_quat::z
zsl_real_t z
The third vector component.
Definition: quaternions.h:101
matrices.h
API header file for matrices in zscilib.
zsl_quat_scale_d
int zsl_quat_scale_d(struct zsl_quat *q, zsl_real_t s)
Multiples each element in the quaternion by a scalar value (destructive).
zsl_quat_lerp
int zsl_quat_lerp(struct zsl_quat *qa, struct zsl_quat *qb, zsl_real_t t, struct zsl_quat *qi)
Linear interpolation (LERP).
zsl_quat_from_axis_angle
int zsl_quat_from_axis_angle(struct zsl_vec *a, zsl_real_t *b, struct zsl_quat *q)
Converts axis-angle rotation to its unit quaternion equivalent.
zsl.h
API header file for zscilib.
zsl_quat_print
int zsl_quat_print(struct zsl_quat *q)
Print the supplied quaternion using printf in a human-readable manner.
zsl_vec
Represents a vector.
Definition: vectors.h:40
zsl_real_t
double zsl_real_t
Definition: zsl.h:51
zsl_quat_log
int zsl_quat_log(struct zsl_quat *q, struct zsl_quat *ql)
Calculates the natural logarithm of a unit quaternion.
zsl_quat_pow
int zsl_quat_pow(struct zsl_quat *q, zsl_real_t pow, struct zsl_quat *qout)
Multiples the supplied unit quaternions to the specified exponent, and stores the results in qout (wh...
ZSL_QUAT_TYPE_IDENTITY
@ ZSL_QUAT_TYPE_IDENTITY
Indicates no rotation, with the scalar value set to 1 and imaginary values set to 0.
Definition: quaternions.h:120
zsl_quat_type
zsl_quat_type
Represents various 'types' of quaternions that can be initialised with the zsl_quat_init function.
Definition: quaternions.h:111
zsl_quat_is_unit
bool zsl_quat_is_unit(struct zsl_quat *q)
Verifies that this is a "unit" quaternion, meaning that it has a magnitude of 1, where sqrt(r^2+i^2+j...
euler.h
API header file for euler angles in zscilib.
zsl_quat::alias
struct zsl_quat::@28::@32 alias
zsl_quat::w
zsl_real_t w
The scalar component.
Definition: quaternions.h:98