Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Data Structures | |
struct | vec_3d_ |
3D vector type More... | |
Typedefs | |
typedef struct vec_3d_ | vec_3d |
3D vector type | |
Functions | |
vec_3d | vector_sub (const vec_3d *a, const vec_3d *b) |
Subtract one vector from another. More... | |
vec_3d | vector_add (const vec_3d *a, const vec_3d *b) |
Add one vector to another. More... | |
float | dot_prod (const vec_3d *a, const vec_3d *b) |
Obtain the dot product of two 3D vectors. More... | |
vec_3d | vector_prod (const vec_3d *a, const vec_3d *b) |
Compute the vector product of two 3d vectors. More... | |
const char * | print_vector (const vec_3d *a, const char *name) |
Print formatted vector on stdout. More... | |
float | vector_norm (const vec_3d *a) |
Compute the norm a vector. More... | |
vec_3d | unit_vec (const vec_3d *a) |
Obtain unit vector in the same direction as given vector. More... | |
mat_3x3 | get_cross_matrix (const vec_3d *a) |
The cross product of vectors can be represented as a matrix multiplication operation. More... | |
double | get_angle (const vec_3d *a, const vec_3d *b) |
Obtain the angle between two given vectors. More... | |
Obtain the dot product of two 3D vectors.
\[ \vec{a}\cdot\vec{b}=a_xb_x + a_yb_y + a_zb_z \]
[in] | a | first vector |
[in] | b | second vector |
Obtain the angle between two given vectors.
\[\alpha=acos\left(\frac{\vec{a} \cdot \vec{b}}{\lVert\vec{a}\rVert \cdot \lVert\vec{b}\rVert}\right)\]
[in] | a | first input vector |
[in] | b | second input vector |
< The norm of vector a
< The norm of vector b
detect possible division by 0 - the angle is not defined in this case
The cross product of vectors can be represented as a matrix multiplication operation.
This function obtains the 3x3
matrix of the cross-product operator from the first vector.
\[\begin{align*} \left(\vec{a}\times\right)\vec{b} &= \tilde{A}_a\vec{b}\\ \tilde{A}_a &= \begin{bmatrix}0&-a_z&a_y\\a_z&0&-a_x\\-a_y&a_x&0\end{bmatrix} \end{align*}\]
[in] | a | input vector |
3x3
matrix for the cross product operator \(\left(\vec{a}\times\right)\) const char * print_vector | ( | const vec_3d * | a, |
const char * | name | ||
) |
Print formatted vector on stdout.
[in] | a | vector to print |
[in] | name | name of the vector |
Obtain unit vector in the same direction as given vector.
\[\hat{a}=\frac{\vec{a}}{\lVert\vec{a}\rVert}\]
[in] | a | input vector |
Add one vector to another.
\[ \vec{c}=\vec{a}+\vec{b}=\left(a_x+b_x\right)\hat{i}+ \left(a_y+b_y\right)\hat{j}+\left(a_z+b_z\right)\hat{k}\]
[in] | a | vector to add to |
[in] | b | vector to add |
float vector_norm | ( | const vec_3d * | a | ) |
Compute the norm a vector.
\[\lVert\vec{a}\rVert = \sqrt{\vec{a}\cdot\vec{a}} \]
[in] | a | input vector |
Compute the vector product of two 3d vectors.
\[\begin{align*} \vec{a}\times\vec{b} &= \begin{vmatrix} \hat{i} & \hat{j} & \hat{k}\\ a_x & a_y & a_z\\ b_x & b_y & b_z \end{vmatrix}\\ &= \left(a_yb_z-b_ya_z\right)\hat{i} - \left(a_xb_z-b_xa_z\right)\hat{j} + \left(a_xb_y-b_xa_y\right)\hat{k} \end{align*} \]
[in] | a | first vector \(\vec{a}\) |
[in] | b | second vector \(\vec{b}\) |
Subtract one vector from another.
\[ \vec{c}=\vec{a}-\vec{b}=\left(a_x-b_x\right)\hat{i}+ \left(a_y-b_y\right)\hat{j}+\left(a_z-b_z\right)\hat{k}\]
[in] | a | vector to subtract from |
[in] | b | vector to subtract |