completed code

Dependencies:   mbed

Committer:
evenbrownie
Date:
Thu Nov 22 22:40:15 2018 +0000
Revision:
5:4af75af374cc
Parent:
0:f43994f44684
blah

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evenbrownie 0:f43994f44684 1 /*
evenbrownie 0:f43994f44684 2 * @author: Thomas Garcia, 2017
evenbrownie 0:f43994f44684 3 */
evenbrownie 0:f43994f44684 4
evenbrownie 0:f43994f44684 5 #ifndef __QUATERNION_H
evenbrownie 0:f43994f44684 6 #define __QUATERNION_H
evenbrownie 0:f43994f44684 7
evenbrownie 0:f43994f44684 8 struct vector {
evenbrownie 0:f43994f44684 9 float x;
evenbrownie 0:f43994f44684 10 float y;
evenbrownie 0:f43994f44684 11 float z;
evenbrownie 0:f43994f44684 12 };
evenbrownie 0:f43994f44684 13
evenbrownie 0:f43994f44684 14 struct quaternion {
evenbrownie 0:f43994f44684 15 float r;
evenbrownie 0:f43994f44684 16 float i;
evenbrownie 0:f43994f44684 17 float j;
evenbrownie 0:f43994f44684 18 float k;
evenbrownie 0:f43994f44684 19 };
evenbrownie 0:f43994f44684 20
evenbrownie 0:f43994f44684 21 /**
evenbrownie 0:f43994f44684 22 * Normalizes a vector.
evenbrownie 0:f43994f44684 23 *
evenbrownie 0:f43994f44684 24 * raw: pointer to the vector to be normalized.
evenbrownie 0:f43994f44684 25 * unit: pointer to where unit vector dimensions should be stored.
evenbrownie 0:f43994f44684 26 *
evenbrownie 0:f43994f44684 27 * returns: length of original vector
evenbrownie 0:f43994f44684 28 */
evenbrownie 0:f43994f44684 29 float vector_normalize(struct vector *raw, struct vector *unit);
evenbrownie 0:f43994f44684 30
evenbrownie 0:f43994f44684 31 /**
evenbrownie 0:f43994f44684 32 * Adds two vectors together.
evenbrownie 0:f43994f44684 33 *
evenbrownie 0:f43994f44684 34 * v1: pointer to the first vector to be added.
evenbrownie 0:f43994f44684 35 * v2: pointer to the second vector to be added.
evenbrownie 0:f43994f44684 36 * result: pointer where the sum of v1 and v2 should be stored.
evenbrownie 0:f43994f44684 37 */
evenbrownie 0:f43994f44684 38 void vector_add(struct vector *v1, struct vector *v2, struct vector *result);
evenbrownie 0:f43994f44684 39
evenbrownie 0:f43994f44684 40 /**
evenbrownie 0:f43994f44684 41 * Multiples a vector by a constant.
evenbrownie 0:f43994f44684 42 *
evenbrownie 0:f43994f44684 43 * v: pointer to the vector to be multiplied.
evenbrownie 0:f43994f44684 44 * c: scalar constant to multiply vector by.
evenbrownie 0:f43994f44684 45 * result: pointer where the c * v should be stored.
evenbrownie 0:f43994f44684 46 */
evenbrownie 0:f43994f44684 47 void vector_multiply(struct vector *v, float c, struct vector *result);
evenbrownie 0:f43994f44684 48
evenbrownie 0:f43994f44684 49 /**
evenbrownie 0:f43994f44684 50 * Creates a quaternion representing a rotation.
evenbrownie 0:f43994f44684 51 *
evenbrownie 0:f43994f44684 52 * v: unit vector representing the axis of rotation.
evenbrownie 0:f43994f44684 53 * angle: angle of rotation.
evenbrownie 0:f43994f44684 54 * result: quaternion representing a rotation of degree angle around the unit vector of v.
evenbrownie 0:f43994f44684 55 */
evenbrownie 0:f43994f44684 56 void quaternion_create(struct vector *v, float angle, struct quaternion *result);
evenbrownie 0:f43994f44684 57
evenbrownie 0:f43994f44684 58 /**
evenbrownie 0:f43994f44684 59 * Rotates a vector based on a quaternion.
evenbrownie 0:f43994f44684 60 *
evenbrownie 0:f43994f44684 61 * v: vector to be rotated.
evenbrownie 0:f43994f44684 62 * q: quaternion representing the rotation to be performed.
evenbrownie 0:f43994f44684 63 * result: The rotated vector.
evenbrownie 0:f43994f44684 64 */
evenbrownie 0:f43994f44684 65 void quaternion_rotate(struct vector *v, struct quaternion *q, struct vector *result);
evenbrownie 0:f43994f44684 66
evenbrownie 0:f43994f44684 67 /**
evenbrownie 0:f43994f44684 68 * Multiplies two quaternions together.
evenbrownie 0:f43994f44684 69 *
evenbrownie 0:f43994f44684 70 * q1: The first quaternion to be multiplied.
evenbrownie 0:f43994f44684 71 * q2: The second quaternion to be multiplied.
evenbrownie 0:f43994f44684 72 * result: q1 * q2.
evenbrownie 0:f43994f44684 73 */
evenbrownie 0:f43994f44684 74 void quaternion_multiply(struct quaternion *q1, struct quaternion *q2, struct quaternion *result);
evenbrownie 0:f43994f44684 75
evenbrownie 0:f43994f44684 76 /**
evenbrownie 0:f43994f44684 77 * Returns the roll, given a vector.
evenbrownie 0:f43994f44684 78 *
evenbrownie 0:f43994f44684 79 * v: The vector.
evenbrownie 0:f43994f44684 80 */
evenbrownie 0:f43994f44684 81 float vector_roll(struct vector *v);
evenbrownie 0:f43994f44684 82
evenbrownie 0:f43994f44684 83 /**
evenbrownie 0:f43994f44684 84 * Returns the pitch, given a vector.
evenbrownie 0:f43994f44684 85 *
evenbrownie 0:f43994f44684 86 * v: The vector.
evenbrownie 0:f43994f44684 87 */
evenbrownie 0:f43994f44684 88 float vector_pitch(struct vector *v);
evenbrownie 0:f43994f44684 89
evenbrownie 0:f43994f44684 90 #endif
evenbrownie 0:f43994f44684 91