|
liba 0.1.15
An algorithm library based on C/C++
|
Data Structures | |
| struct | a_point2 |
| instance structure for two-dimensional point More... | |
Macros | |
| #define | A_POINT2_C(x, y) |
| #define | a_point2_c(x) |
| #define | a_point2_(_, x) |
Typedefs | |
| typedef struct a_point2 | a_point2 |
Functions | |
| void | a_vector2_set (a_vector2 *ctx, a_point2 const *p, a_point2 const *q) |
| set a 2D vector as the difference from point p to point q. | |
| void | a_point2_val (a_point2 const *ctx, a_real *x, a_real *y) |
| get the cartesian coordinates of a 2D point. | |
| void | a_point2_set_val (a_point2 *ctx, a_real x, a_real y) |
| set the cartesian coordinates of a 2D point. | |
| void | a_point2_pol (a_point2 const *ctx, a_real *rho, a_real *theta) |
| get the polar coordinates of a 2D point. | |
| void | a_point2_set_pol (a_point2 *ctx, a_real rho, a_real theta) |
| set the polar coordinates of a 2D point. | |
| void | a_point2_add (a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res) |
| add a 2D vector to a 2D point. | |
| void | a_point2_sub (a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res) |
| subtract a 2D vector from a 2D point. | |
| void | a_point2_mul (a_point2 const *lhs, a_real rhs, a_point2 *res) |
| multiplie a 2D point by a scalar. | |
| void | a_point2_div (a_point2 const *lhs, a_real rhs, a_point2 *res) |
| divide a 2D point by a scalar. | |
| void | a_point2_pos (a_point2 const *ctx, a_vector2 *res) |
| convert it into a vector from the origin to the point. | |
| void | a_point2_neg (a_point2 const *ctx, a_vector2 *res) |
| convert it into a vector from the point to the origin. | |
| a_real | a_point2_norm (a_point2 const *ctx) |
| compute the magnitude of a 2D point. | |
| a_real | a_point2_norm2 (a_point2 const *ctx) |
| compute the squared magnitude of a 2D point. | |
| a_real | a_point2_dist (a_point2 const *lhs, a_point2 const *rhs) |
| compute the distance between two 2D points. | |
| a_real | a_point2_dist2 (a_point2 const *lhs, a_point2 const *rhs) |
| compute the squared distance between two 2D points. | |
| a_real | a_point2_mindist (a_point2 const *ctx, a_point2 const *i_p, a_size i_n, a_point2 *o_p, a_size *o_i) |
| compute the minimum distance from a reference point to a point set. | |
| a_real | a_point2_maxdist (a_point2 const *ctx, a_point2 const *i_p, a_size i_n, a_point2 *o_p, a_size *o_i) |
| compute the maximum distance from a reference point to a point set. | |
| void | a_point2_lerp (a_point2 const *lhs, a_point2 const *rhs, a_real val, a_point2 *res) |
| compute linear interpolation (LERP) between two 2D points. | |
| a_real | a_point2_tricir (a_point2 const *p1, a_point2 const *p2, a_point2 const *p3, a_point2 *pc) |
| compute the circumcenter and circumradius of a triangle defined by three 2D points. | |
| a_real | a_point2_tricir2 (a_point2 const *p1, a_point2 const *p2, a_point2 const *p3, a_point2 *pc) |
| compute the circumcenter and squared circumradius of a triangle defined by three 2D points. | |
| int | a_point2_cmpx (a_point2 const *lhs, a_point2 const *rhs) |
| compare two 2D points primarily by X-coordinate, then by Y-coordinate. | |
| int | a_point2_cmpy (a_point2 const *lhs, a_point2 const *rhs) |
| compare two 2D points primarily by Y-coordinate, then by X-coordinate. | |
| void | a_vector2::set (a_point2 const &p, a_point2 const &q) |
| set a 2D vector as the difference from point p to point q. | |
| #define a_point2_ | ( | _, | |
| x ) |
| #define A_POINT2_C | ( | x, | |
| y ) |
| #define a_point2_c | ( | x | ) |
static cast to two-dimensional point
compare two 2D points primarily by X-coordinate, then by Y-coordinate.
| [in] | lhs | is left-hand side 2D point |
| [in] | rhs | is right-hand side 2D point |
| >0 | if lhs is greater than rhs |
| <0 | if lhs is less than rhs |
| 0 | if lhs is equal to rhs |
compare two 2D points primarily by Y-coordinate, then by X-coordinate.
| [in] | lhs | is left-hand side 2D point |
| [in] | rhs | is right-hand side 2D point |
| >0 | if lhs is greater than rhs |
| <0 | if lhs is less than rhs |
| 0 | if lhs is equal to rhs |
compute the distance between two 2D points.
In two-dimensional space, let point \(p\) have coordinates \((p_x,p_y)\) and let point \(q\) have coordinates \((q_x,q_y)\). Then the distance between \(p\) and \(q\) is given by:
\[ d(p,q)=\sqrt{(p_x-q_x)^2+(p_y-q_y)^2} \]
| [in] | lhs | is left-hand side 2D point |
| [in] | rhs | is right-hand side 2D point |
compute the squared distance between two 2D points.
In two-dimensional space, let point \(p\) have coordinates \((p_x,p_y)\) and let point \(q\) have coordinates \((q_x,q_y)\). Then the squared distance between \(p\) and \(q\) is given by:
\[ d(p,q)^2=(p_x-q_x)^2+(p_y-q_y)^2 \]
| [in] | lhs | is left-hand side 2D point |
| [in] | rhs | is right-hand side 2D point |
compute linear interpolation (LERP) between two 2D points.
Let \(\vec{a}\) and \(\vec{b}\) be two 2D points and let \(t\) be the interpolation factor. Then the linear interpolation \(\vec{p}\) between \(\vec{a}\) and \(\vec{b}\) is given by:
\[ \vec{p} = \vec{a} + (\vec{b} - \vec{a}) * t \]
| [in] | lhs | points to the starting point |
| [in] | rhs | points to the ending point |
| [in] | val | is the interpolation factor |
| [out] | res | stores the interpolated point |
| a_real a_point2_maxdist | ( | a_point2 const * | ctx, |
| a_point2 const * | i_p, | ||
| a_size | i_n, | ||
| a_point2 * | o_p, | ||
| a_size * | o_i ) |
compute the maximum distance from a reference point to a point set.
| [in] | ctx | points to the reference point |
| [in] | i_p | points to the points in memory |
| [in] | i_n | number of the points in memory |
| [out] | o_p | stores the farthest point; may be NULL |
| [out] | o_i | stores the index of the farthest point; may be NULL |
| -inf | failure |
| a_real a_point2_mindist | ( | a_point2 const * | ctx, |
| a_point2 const * | i_p, | ||
| a_size | i_n, | ||
| a_point2 * | o_p, | ||
| a_size * | o_i ) |
compute the minimum distance from a reference point to a point set.
| [in] | ctx | points to the reference point |
| [in] | i_p | points to the points in memory |
| [in] | i_n | number of the points in memory |
| [out] | o_p | stores the nearest point; may be NULL |
| [out] | o_i | stores the index of the nearest point; may be NULL |
| +inf | failure |
compute the magnitude of a 2D point.
In two-dimensional space, a point \(\vec{p}\) with coordinates \((x,y)\) has a magnitude defined as:
\[ \|\vec{p}\|=\sqrt{x^2+y^2} \]
| [in] | ctx | points to the input point |
compute the squared magnitude of a 2D point.
In two-dimensional space, a point \(\vec{p}\) with coordinates \((x,y)\) has a squared magnitude defined as:
\[ \|\vec{p}\|^2=x^2+y^2 \]
| [in] | ctx | points to the input point |
| a_real a_point2_tricir | ( | a_point2 const * | p1, |
| a_point2 const * | p2, | ||
| a_point2 const * | p3, | ||
| a_point2 * | pc ) |
compute the circumcenter and circumradius of a triangle defined by three 2D points.
| [in] | p1 | is the first 2D point on circle |
| [in] | p2 | is the second 2D point on circle |
| [in] | p3 | is the third 2D point on circle |
| [out] | pc | stores the circumcenter |
| 0 | if points are collinear |
| a_real a_point2_tricir2 | ( | a_point2 const * | p1, |
| a_point2 const * | p2, | ||
| a_point2 const * | p3, | ||
| a_point2 * | pc ) |
compute the circumcenter and squared circumradius of a triangle defined by three 2D points.
Solves for center (x,y) where distances to all three points are equal:
\[ (x_1-x)^2+(y_1-y)^2=(x_2-x)^2+(y_2-y)^2=(x_3-x)^2+(y_3-y)^2 \]
This simplifies to:
\begin{cases} 2(x_2−x_1)dx + 2(y_2−y_1)dy = (x_2-x_1)^2 + (y_2-y_1)^2 \\ 2(x_3−x_1)dx + 2(y_3−y_1)dy = (x_3-x_1)^2 + (y_3-y_1)^2 \end{cases}
Where
\begin{aligned} dx &= x - x_1 \\ dy &= y - y_1 \end{aligned}
Matrix form:
\[ 2\begin{bmatrix} x_{21}&y_{21} \\ x_{31}&y_{31} \end{bmatrix} \begin{bmatrix} dx\\dy \end{bmatrix} =\begin{bmatrix} b_{21} \\ b_{31} \end{bmatrix} \]
Where
\begin{aligned} x_{ji}&=x_j-x_i \\ y_{ji}&=y_j-y_i \\ b_{ji}&=x_{ji}^2+y_{ji}^2 \end{aligned}
Explicit Solution (Cramer's Rule):
\begin{aligned} dx=\frac{b_{21}y_{31}-y_{21}b_{31}}{2(x_{21}y_{31}-y_{21}x_{31})} \\ dy=\frac{x_{21}b_{31}-b_{21}x_{31}}{2(x_{21}y_{31}-y_{21}x_{31})} \end{aligned}
Radius (r):
\[ r = \sqrt{dx^2+dy^2} \]
| [in] | p1 | is the first 2D point on circle |
| [in] | p2 | is the second 2D point on circle |
| [in] | p3 | is the third 2D point on circle |
| [out] | pc | stores the circumcenter |
| 0 | if points are collinear |
set a 2D vector as the difference from point p to point q.