|
liba 0.1.15
An algorithm library based on C/C++
|
Data Structures | |
| struct | a_vector2 |
| instance structure for two-dimensional vector More... | |
Macros | |
| #define | A_VECTOR2_C(x, y) |
| #define | a_vector2_c(x) |
| #define | a_vector2_(_, x) |
Typedefs | |
| typedef struct a_vector2 | a_vector2 |
Functions | |
| a_real | a_vector2_set_dir (a_vector2 *ctx, a_real x, a_real y) |
| set the components of a 2D vector and normalize it in place. | |
| void | a_vector2_val (a_vector2 const *ctx, a_real *x, a_real *y) |
| get the cartesian coordinates of a 2D vector. | |
| void | a_vector2_set_val (a_vector2 *ctx, a_real x, a_real y) |
| set the cartesian coordinates of a 2D vector. | |
| void | a_vector2_pol (a_vector2 const *ctx, a_real *rho, a_real *theta) |
| get the polar coordinates of a 2D vector. | |
| void | a_vector2_set_pol (a_vector2 *ctx, a_real rho, a_real theta) |
| set the polar coordinates of a 2D vector. | |
| void | a_vector2_add (a_vector2 const *lhs, a_vector2 const *rhs, a_vector2 *res) |
| add a 2D vector to a 2D vector. | |
| void | a_vector2_sub (a_vector2 const *lhs, a_vector2 const *rhs, a_vector2 *res) |
| subtract a 2D vector from a 2D vector. | |
| void | a_vector2_mul (a_vector2 const *lhs, a_real rhs, a_vector2 *res) |
| multiplie a 2D vector by a scalar. | |
| void | a_vector2_div (a_vector2 const *lhs, a_real rhs, a_vector2 *res) |
| divide a 2D vector by a scalar. | |
| void | a_vector2_neg (a_vector2 const *ctx, a_vector2 *res) |
| negate a 2D vector. | |
| a_real | a_vector2_unit (a_vector2 *ctx) |
| normalize a 2D vector in-place to unit length. | |
| a_real | a_vector2_norm (a_vector2 const *ctx) |
| compute the magnitude of a 2D vector. | |
| a_real | a_vector2_norm2 (a_vector2 const *ctx) |
| compute the squared magnitude of a 2D vector. | |
| a_real | a_vector2_dot (a_vector2 const *lhs, a_vector2 const *rhs) |
| compute the dot product (scalar product) of two 2D vectors. | |
| a_real | a_vector2_dist (a_vector2 const *lhs, a_vector2 const *rhs) |
| compute the distance between two 2D vectors. | |
| a_real | a_vector2_dist2 (a_vector2 const *lhs, a_vector2 const *rhs) |
| compute the squared distance between two 2D vectors. | |
| a_real | a_vector2_angle (a_vector2 const *lhs, a_vector2 const *rhs) |
| compute the angle between two 2D vectors in radians. | |
| a_bool | a_vector2_isver (a_vector2 const *lhs, a_vector2 const *rhs) |
| check if two 2D vectors are orthogonal. | |
| a_bool | a_vector2_ispar (a_vector2 const *lhs, a_vector2 const *rhs) |
| check if two 2D vectors are parallel or anti-parallel. | |
| a_real | a_vector2_cross (a_vector2 const *lhs, a_vector2 const *rhs) |
| compute the cross product (vector product) of two 2D vectors | |
| void | a_vector2_outer (a_vector2 const *lhs, a_vector2 const *rhs, a_real res[4]) |
| compute the outer product (tensor product) of two 2D vectors. | |
| int | a_vector2_proj (a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *res) |
| project vector onto the direction of vector. | |
| int | a_vector2_perp (a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *res) |
| project vector onto the line perpendicular to vector. | |
| int | a_vector2_refl (a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *res) |
| reflect vector across the line with direction vector. | |
| void | a_vector2_rot_ (a_vector2 const *ctx, a_real sin, a_real cos, a_vector2 *res) |
| rotate a 2D vector by a specified angle (in radians). | |
| void | a_vector2_rot (a_vector2 const *ctx, a_real angle, a_vector2 *res) |
| rotate a 2D vector by a specified angle (in radians). | |
| #define a_vector2_ | ( | _, | |
| x ) |
| #define A_VECTOR2_C | ( | x, | |
| y ) |
| #define a_vector2_c | ( | x | ) |
static cast to two-dimensional vector
compute the angle between two 2D vectors in radians.
In two-dimensional space, let vector \(\vec{a}\) have coordinates \((a_x,a_y)\) and let vector \(\vec{b}\) have coordinates \((b_x,b_y)\). Then the angle between \(\vec{a}\) and \(\vec{b}\) is given by:
\[ \theta=\arccos\left(\frac{\vec{a}\cdot\vec{b}}{\|\vec{a}\|\|\vec{b}\|}\right) =\arccos\left(\frac{\vec{a}\cdot\vec{b}}{\sqrt{\|\vec{a}\|^2\|\vec{b}\|^2}}\right) \]
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
| 0 | if the vector is null |
compute the cross product (vector product) of two 2D vectors
In two-dimensional space, let vector \(\vec{a}\) have coordinates \((a_x,a_y)\) and let vector \(\vec{b}\) have coordinates \((b_x,b_y)\). Then the cross product of vectors \(\vec{a}\) and \(\vec{b}\) is defined as:
\[ \vec{a} \times \vec{b} = a_x b_y - a_y b_x \]
https://en.wikipedia.org/wiki/Cross_product
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
compute the distance between two 2D vectors.
In two-dimensional space, let vector \(\vec{a}\) have coordinates \((a_x,a_y)\) and let vector \(\vec{b}\) have coordinates \((b_x,b_y)\). Then the distance between \(\vec{a}\) and \(\vec{b}\) is given by:
\[ d(\vec{a},\vec{b})=\sqrt{(a_x-b_x)^2+(a_y-b_y)^2} \]
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
compute the squared distance between two 2D vectors.
In two-dimensional space, let vector \(\vec{a}\) have coordinates \((a_x,a_y)\) and let vector \(\vec{b}\) have coordinates \((b_x,b_y)\). Then the squared distance between \(\vec{a}\) and \(\vec{b}\) is given by:
\[ d(\vec{a},\vec{b})^2=(a_x-b_x)^2+(a_y-b_y)^2 \]
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
compute the dot product (scalar product) of two 2D vectors.
In two-dimensional space, let vector \(\vec{a}\) have coordinates \((a_x,a_y)\) and let vector \(\vec{b}\) have coordinates \((b_x,b_y)\). Then the dot product of vectors \(\vec{a}\) and \(\vec{b}\) is defined as:
\[ \vec{a} \cdot \vec{b} = a_x b_x + a_y b_y \]
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
check if two 2D vectors are parallel or anti-parallel.
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
| true | if the vector is null |
check if two 2D vectors are orthogonal.
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
| true | if the vector is null |
compute the magnitude of a 2D vector.
In two-dimensional space, a vector \(\vec{v}\) with coordinates \((x,y)\) has a magnitude defined as:
\[ \|\vec{v}\|=\sqrt{x^2+y^2} \]
| [in] | ctx | points to the input vector |
compute the squared magnitude of a 2D vector.
In two-dimensional space, a vector \(\vec{v}\) with coordinates \((x,y)\) has a squared magnitude defined as:
\[ \|\vec{v}\|^2=x^2+y^2 \]
| [in] | ctx | points to the input vector |
compute the outer product (tensor product) of two 2D vectors.
In two-dimensional space, let vector \(\vec{a}\) have coordinates \((a_x,a_y)\) and let vector \(\vec{b}\) have coordinates \((b_x,b_y)\). Then the outer product of vectors \(\vec{a}\) and \(\vec{b}\) is defined as:
\[ \vec{a} \otimes \vec{b} = \begin{bmatrix} a_x b_x & a_x b_y \\ a_y b_x & a_y b_y \end{bmatrix} \]
https://en.wikipedia.org/wiki/Outer_product
| [in] | lhs | is left-hand side 2D vector |
| [in] | rhs | is right-hand side 2D vector |
| [out] | res | stores the 2×2 matrix in row-major order |
project vector onto the line perpendicular to vector.
In two-dimensional space, let \(\vec{v}\) be the vector to be projected, and let \(\vec{d}\) be the reference direction vector. Then the perpendicular projection of \(\vec{v}\) about the direction \(\vec{d}\) is defined as:
\[ \vec{v}' = \vec{v}-\frac{\vec{d}\cdot\vec{v}}{\|\vec{d}\|^2}\vec{d} \]
| [in] | ctx | points to the vector to be projected |
| [in] | dir | points to the reference direction vector |
| [out] | res | stores the perpendicular projection vector about the direction |
| <0 | failure |
| 0 | success |
project vector onto the direction of vector.
In two-dimensional space, let \(\vec{v}\) be the vector to be projected, and let \(\vec{d}\) be the direction vector for projection. Then the projection of \(\vec{v}\) onto the direction of \(\vec{d}\) is defined as:
\[ \vec{v}' = \frac{\vec{d}\cdot\vec{v}}{\|\vec{d}\|^2}\vec{d} \]
| [in] | ctx | points to the vector to be projected |
| [in] | dir | points to the direction vector for projection |
| [out] | res | stores the projection vector onto the direction of vector |
| <0 | failure |
| 0 | success |
reflect vector across the line with direction vector.
In two-dimensional space, let \(\vec{v}\) be the vector to be reflected, and let \(\vec{d}\) be the direction vector defining the reflection line. Then the reflection of \(\vec{v}\) about the line with direction \(\vec{d}\) is defined as:
\[ \vec{v}' = 2\frac{\vec{d}\cdot\vec{v}}{\|\vec{d}\|^2}\vec{d}-\vec{v} \]
| [in] | ctx | points to the vector to be reflected |
| [in] | dir | points to the direction vector defining the reflection line |
| [out] | res | stores the reflection vector about the line with direction |
| <0 | failure |
| 0 | success |
rotate a 2D vector by a specified angle (in radians).
In two-dimensional space, let \(v\) be any vector to rotate by angle \(\theta\) (right hand rule, anticlockwise). Then the rotated vector \(\vec{v}'\) is given by:
\[ \vec{v}' = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \vec{v} \]
https://en.wikipedia.org/wiki/Rotation_matrix
| [in] | ctx | points to the input vector to rotate |
| [in] | angle | is rotation angle in radians |
| [out] | res | stores the result vector |
rotate a 2D vector by a specified angle (in radians).
In two-dimensional space, let \(v\) be any vector to rotate by angle \(\theta\) (right hand rule, anticlockwise). Then the rotated vector \(\vec{v}'\) is given by:
\[ \vec{v}' = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \vec{v} \]
https://en.wikipedia.org/wiki/Rotation_matrix
| [in] | ctx | points to the input vector to rotate |
| [in] | sin | is precomputed \(\sin(\theta)\) |
| [in] | cos | is precomputed \(\cos(\theta)\) |
| [out] | res | stores the result vector |
set the components of a 2D vector and normalize it in place.