liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
two-dimensional point
Collaboration diagram for two-dimensional point:

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.

Detailed Description

Macro Definition Documentation

◆ a_point2_

#define a_point2_ ( _,
x )
Value:
a_cast_s(a_point2 _, x)
instance structure for two-dimensional point
Definition point2.h:264

◆ A_POINT2_C

#define A_POINT2_C ( x,
y )
Value:
#define a_real_c(x)
static cast to floating-point number
Definition a.h:1009

constructs a two-dimensional point from cartesian coordinate

◆ a_point2_c

#define a_point2_c ( x)
Value:
a_cast_s(a_point2, x)

static cast to two-dimensional point

Function Documentation

◆ a_point2_cmpx()

int a_point2_cmpx ( a_point2 const * lhs,
a_point2 const * rhs )

compare two 2D points primarily by X-coordinate, then by Y-coordinate.

Parameters
[in]lhsis left-hand side 2D point
[in]rhsis right-hand side 2D point
Returns
relationship between 2D points
Return values
>0if lhs is greater than rhs
<0if lhs is less than rhs
0if lhs is equal to rhs

◆ a_point2_cmpy()

int a_point2_cmpy ( a_point2 const * lhs,
a_point2 const * rhs )

compare two 2D points primarily by Y-coordinate, then by X-coordinate.

Parameters
[in]lhsis left-hand side 2D point
[in]rhsis right-hand side 2D point
Returns
relationship between 2D points
Return values
>0if lhs is greater than rhs
<0if lhs is less than rhs
0if lhs is equal to rhs

◆ a_point2_dist()

a_real a_point2_dist ( a_point2 const * lhs,
a_point2 const * 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} \]

Parameters
[in]lhsis left-hand side 2D point
[in]rhsis right-hand side 2D point
Returns
the distance between two 2D points

◆ a_point2_dist2()

a_real a_point2_dist2 ( a_point2 const * lhs,
a_point2 const * rhs )

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 \]

Parameters
[in]lhsis left-hand side 2D point
[in]rhsis right-hand side 2D point
Returns
the squared distance between two 2D points

◆ a_point2_lerp()

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.

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 \]

Parameters
[in]lhspoints to the starting point
[in]rhspoints to the ending point
[in]valis the interpolation factor
[out]resstores the interpolated point

◆ a_point2_maxdist()

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.

Parameters
[in]ctxpoints to the reference point
[in]i_ppoints to the points in memory
[in]i_nnumber of the points in memory
[out]o_pstores the farthest point; may be NULL
[out]o_istores the index of the farthest point; may be NULL
Returns
the maximum distance from a reference point to a point set
Return values
-inffailure

◆ a_point2_mindist()

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.

Parameters
[in]ctxpoints to the reference point
[in]i_ppoints to the points in memory
[in]i_nnumber of the points in memory
[out]o_pstores the nearest point; may be NULL
[out]o_istores the index of the nearest point; may be NULL
Returns
the minimum distance from a reference point to a point set
Return values
+inffailure

◆ a_point2_norm()

a_real a_point2_norm ( a_point2 const * ctx)

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} \]

Parameters
[in]ctxpoints to the input point
Returns
the magnitude of the point

◆ a_point2_norm2()

a_real a_point2_norm2 ( a_point2 const * ctx)

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 \]

Parameters
[in]ctxpoints to the input point
Returns
the squared magnitude of the point

◆ a_point2_tricir()

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.

Parameters
[in]p1is the first 2D point on circle
[in]p2is the second 2D point on circle
[in]p3is the third 2D point on circle
[out]pcstores the circumcenter
Returns
the circumradius
Return values
0if points are collinear
See also
a_point2_tricir2

◆ a_point2_tricir2()

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} \]

Parameters
[in]p1is the first 2D point on circle
[in]p2is the second 2D point on circle
[in]p3is the third 2D point on circle
[out]pcstores the circumcenter
Returns
the squared circumradius
Return values
0if points are collinear

◆ set()

void a_vector2::set ( a_point2 const & p,
a_point2 const & q )
inline

set a 2D vector as the difference from point p to point q.

See also
a_vector2_set