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

Data Structures

struct  a_point3
 instance structure for three-dimensional point More...

Macros

#define A_POINT3_C(x, y, z)
#define a_point3_c(x)
#define a_point3_(_, x)

Typedefs

typedef struct a_point3 a_point3

Functions

void a_vector3_set (a_vector3 *ctx, a_point3 const *p, a_point3 const *q)
 set a 3D vector as the difference from point p to point q.
void a_point3_val (a_point3 const *ctx, a_real *x, a_real *y, a_real *z)
 get the cartesian coordinates of a 3D point.
void a_point3_set_val (a_point3 *ctx, a_real x, a_real y, a_real z)
 set the cartesian coordinates of a 3D point.
void a_point3_cyl (a_point3 const *ctx, a_real *rho, a_real *theta, a_real *z)
 get the cylindrical coordinates of a 3D point.
void a_point3_set_cyl (a_point3 *ctx, a_real rho, a_real theta, a_real z)
 set the cylindrical coordinates of a 3D point.
void a_point3_sph (a_point3 const *ctx, a_real *rho, a_real *theta, a_real *alpha)
 get the spherical coordinates of a 3D point.
void a_point3_set_sph (a_point3 *ctx, a_real rho, a_real theta, a_real alpha)
 set the spherical coordinates of a 3D point.
void a_point3_add (a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
 add a 3D vector to a 3D point.
void a_point3_sub (a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
 subtract a 3D vector from a 3D point.
void a_point3_mul (a_point3 const *lhs, a_real rhs, a_point3 *res)
 multiplie a 3D point by a scalar.
void a_point3_div (a_point3 const *lhs, a_real rhs, a_point3 *res)
 divide a 3D point by a scalar.
void a_point3_pos (a_point3 const *ctx, a_vector3 *res)
 convert it into a vector from the origin to the point.
void a_point3_neg (a_point3 const *ctx, a_vector3 *res)
 convert it into a vector from the point to the origin.
a_real a_point3_norm (a_point3 const *ctx)
 compute the magnitude of a 3D point.
a_real a_point3_norm2 (a_point3 const *ctx)
 compute the squared magnitude of a 3D point.
a_real a_point3_dist (a_point3 const *lhs, a_point3 const *rhs)
 compute the distance between two 3D points.
a_real a_point3_dist2 (a_point3 const *lhs, a_point3 const *rhs)
 compute the squared distance between two 3D points.
a_real a_point3_mindist (a_point3 const *ctx, a_point3 const *i_p, a_size i_n, a_point3 *o_p, a_size *o_i)
 compute the minimum distance from a reference point to a point set.
a_real a_point3_maxdist (a_point3 const *ctx, a_point3 const *i_p, a_size i_n, a_point3 *o_p, a_size *o_i)
 compute the maximum distance from a reference point to a point set.
void a_point3_lerp (a_point3 const *lhs, a_point3 const *rhs, a_real val, a_point3 *res)
 compute linear interpolation (LERP) between two 3D points.
a_real a_point3_tricir (a_point3 const *p1, a_point3 const *p2, a_point3 const *p3, a_point3 *pc)
 compute the circumcenter and circumradius of a triangle defined by three 3D points.
a_real a_point3_tricir2 (a_point3 const *p1, a_point3 const *p2, a_point3 const *p3, a_point3 *pc)
 compute the circumcenter and squared circumradius of a triangle defined by three 3D points.
a_real a_point3_tetsph (a_point3 const *p1, a_point3 const *p2, a_point3 const *p3, a_point3 const *p4, a_point3 *pc)
 compute the circumcenter and circumradius of a tetrahedron defined by four 3D points.
a_real a_point3_tetsph2 (a_point3 const *p1, a_point3 const *p2, a_point3 const *p3, a_point3 const *p4, a_point3 *pc)
 compute the circumcenter and squared circumradius of a tetrahedron defined by four 3D points.
int a_point3_cmpxy (a_point3 const *lhs, a_point3 const *rhs)
 compare two 3D points primarily by X, then by Y, and finally by Z.
int a_point3_cmpyx (a_point3 const *lhs, a_point3 const *rhs)
 compare two 3D points primarily by Y, then by X, and finally by Z.
void a_vector3::set (a_point3 const &p, a_point3 const &q)
 set a 3D vector as the difference from point p to point q.

Detailed Description

Macro Definition Documentation

◆ a_point3_

#define a_point3_ ( _,
x )
Value:
a_cast_s(a_point3 _, x)
instance structure for three-dimensional point
Definition point3.h:350

◆ A_POINT3_C

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

constructs a three-dimensional point from cartesian coordinate

◆ a_point3_c

#define a_point3_c ( x)
Value:
a_cast_s(a_point3, x)

static cast to three-dimensional point

Function Documentation

◆ a_point3_cmpxy()

int a_point3_cmpxy ( a_point3 const * lhs,
a_point3 const * rhs )

compare two 3D points primarily by X, then by Y, and finally by Z.

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

◆ a_point3_cmpyx()

int a_point3_cmpyx ( a_point3 const * lhs,
a_point3 const * rhs )

compare two 3D points primarily by Y, then by X, and finally by Z.

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

◆ a_point3_dist()

a_real a_point3_dist ( a_point3 const * lhs,
a_point3 const * rhs )

compute the distance between two 3D points.

In three-dimensional space, let point \(p\) have coordinates \((p_x,p_y,p_z)\) and let point \(q\) have coordinates \((q_x,q_y,q_z)\). Then the distance between \(p\) and \(q\) is given by:

\[ d(p,q)=\sqrt{(p_x-q_x)^2+(p_y-q_y)^2+(p_z-q_z)^2} \]

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

◆ a_point3_dist2()

a_real a_point3_dist2 ( a_point3 const * lhs,
a_point3 const * rhs )

compute the squared distance between two 3D points.

In three-dimensional space, let point \(p\) have coordinates \((p_x,p_y,p_z)\) and let point \(q\) have coordinates \((q_x,q_y,q_z)\). 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+(p_z-q_z)^2 \]

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

◆ a_point3_lerp()

void a_point3_lerp ( a_point3 const * lhs,
a_point3 const * rhs,
a_real val,
a_point3 * res )

compute linear interpolation (LERP) between two 3D points.

Let \(\vec{a}\) and \(\vec{b}\) be two 3D 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_point3_maxdist()

a_real a_point3_maxdist ( a_point3 const * ctx,
a_point3 const * i_p,
a_size i_n,
a_point3 * 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_point3_mindist()

a_real a_point3_mindist ( a_point3 const * ctx,
a_point3 const * i_p,
a_size i_n,
a_point3 * 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_point3_norm()

a_real a_point3_norm ( a_point3 const * ctx)

compute the magnitude of a 3D point.

In three-dimensional space, a point \(\vec{p}\) with coordinates \((x,y,z)\) has a magnitude defined as:

\[ \|\vec{p}\|=\sqrt{x^2+y^2+z^2} \]

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

◆ a_point3_norm2()

a_real a_point3_norm2 ( a_point3 const * ctx)

compute the squared magnitude of a 3D point.

In three-dimensional space, a point \(\vec{p}\) with coordinates \((x,y,z)\) has a squared magnitude defined as:

\[ \|\vec{p}\|^2=x^2+y^2+z^2 \]

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

◆ a_point3_tetsph()

a_real a_point3_tetsph ( a_point3 const * p1,
a_point3 const * p2,
a_point3 const * p3,
a_point3 const * p4,
a_point3 * pc )

compute the circumcenter and circumradius of a tetrahedron defined by four 3D points.

Parameters
[in]p1is the first 3D point on sphere
[in]p2is the second 3D point on sphere
[in]p3is the third 3D point on sphere
[in]p4is the fourth 3D point on sphere
[out]pcstores the circumcenter
Returns
the circumradius
Return values
0if points are coplanar
See also
a_point3_tetsph2

◆ a_point3_tetsph2()

a_real a_point3_tetsph2 ( a_point3 const * p1,
a_point3 const * p2,
a_point3 const * p3,
a_point3 const * p4,
a_point3 * pc )

compute the circumcenter and squared circumradius of a tetrahedron defined by four 3D points.

Solves for center (x,y,z) where distances to all four points are equal:

\begin{aligned} (x_1 - x)^2 + (y_1 - y)^2 + (z_1 - z)^2 &= \\ (x_2 - x)^2 + (y_2 - y)^2 + (z_2 - z)^2 &= \\ (x_3 - x)^2 + (y_3 - y)^2 + (z_3 - z)^2 &= \\ (x_4 - x)^2 + (y_4 - y)^2 + (z_4 - z)^2 \end{aligned}

This simplifies to:

\begin{cases} 2(x_2−x_1)dx + 2(y_2−y_1)dy + 2(z_2−z_1)dz = (x_2−x_1)^2 + (y_2−y_1)^2 + (z_2−z_1)^2 \\ 2(x_3−x_1)dx + 2(y_3−y_1)dy + 2(z_3−z_1)dz = (x_3−x_1)^2 + (y_3−y_1)^2 + (z_3−z_1)^2 \\ 2(x_4−x_1)dx + 2(y_4−y_1)dy + 2(z_4−z_1)dz = (x_4−x_1)^2 + (y_4−y_1)^2 + (z_4−z_1)^2 \end{cases}

Where

\begin{aligned} dx &= x - x_1 \\ dy &= y - y_1 \\ dz &= z - z_1 \end{aligned}

Matrix form:

\[ 2\begin{bmatrix} x_{21}&y_{21}&z_{21} \\ x_{31}&y_{31}&z_{31} \\ x_{41}&y_{41}&z_{41} \end{bmatrix} \begin{bmatrix} dx\\dy\\dz \end{bmatrix} = \begin{bmatrix} b_{21}\\b_{31}\\b_{41} \end{bmatrix} \]

Where

\begin{aligned} x_{ji} &= x_j-x_i \\ y_{ji} &= y_j-y_i \\ z_{ji} &= z_j-z_i \\ b_{ji} &= x_{ji}^2+y_{ji}^2+z_{ji}^2 \end{aligned}

Explicit Solution (Cramer's Rule):

\begin{aligned} dx &= \frac{D_x}{2D} \\ dy &= \frac{D_y}{2D} \\ dz &= \frac{D_z}{2D} \end{aligned}

Where

\begin{aligned} D &= x_{41} \begin{vmatrix} y_{21}&z_{21}\\y_{31}&z_{31} \end{vmatrix} + y_{41} \begin{vmatrix} z_{21}&x_{21}\\z_{31}&x_{31} \end{vmatrix} + z_{41} \begin{vmatrix} x_{21}&y_{21}\\x_{31}&y_{31} \end{vmatrix} \\ D_x &= b_{41} \begin{vmatrix} y_{21}&z_{21}\\y_{31}&z_{31} \end{vmatrix} + y_{41} \begin{vmatrix} z_{21}&b_{21}\\z_{31}&b_{31} \end{vmatrix} + z_{41} \begin{vmatrix} b_{21}&y_{21}\\b_{31}&y_{31} \end{vmatrix} \\ D_y &= x_{41} \begin{vmatrix} b_{21}&z_{21}\\b_{31}&z_{31} \end{vmatrix} + b_{41} \begin{vmatrix} z_{21}&x_{21}\\z_{31}&x_{31} \end{vmatrix} + z_{41} \begin{vmatrix} x_{21}&b_{21}\\x_{31}&b_{31} \end{vmatrix} \\ D_z &= x_{41} \begin{vmatrix} y_{21}&b_{21}\\y_{31}&b_{31} \end{vmatrix} + y_{41} \begin{vmatrix} b_{21}&x_{21}\\b_{31}&x_{31} \end{vmatrix} + b_{41} \begin{vmatrix} x_{21}&y_{21}\\x_{31}&y_{31} \end{vmatrix} \end{aligned}

Radius (r):

\[ r = \sqrt{dx^2+dy^2+dz^2} \]

Parameters
[in]p1is the first 3D point on sphere
[in]p2is the second 3D point on sphere
[in]p3is the third 3D point on sphere
[in]p4is the fourth 3D point on sphere
[out]pcstores the circumcenter
Returns
the squared circumradius
Return values
0if points are coplanar

◆ a_point3_tricir()

a_real a_point3_tricir ( a_point3 const * p1,
a_point3 const * p2,
a_point3 const * p3,
a_point3 * pc )

compute the circumcenter and circumradius of a triangle defined by three 3D points.

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

◆ a_point3_tricir2()

a_real a_point3_tricir2 ( a_point3 const * p1,
a_point3 const * p2,
a_point3 const * p3,
a_point3 * pc )

compute the circumcenter and squared circumradius of a triangle defined by three 3D points.

Solves for center (x,y,z) where distances to all three points are equal:

\[ (x_1-x)^2+(y_1-y)^2+(z_1-z)^2=(x_2-x)^2+(y_2-y)^2+(z_2-z)^2=(x_3-x)^2+(y_3-y)^2+(z_3-z)^2 \]

This simplifies to:

\begin{cases} 2(x_2−x_1)x + 2(y_2−y_1)y + 2(z_2−z_1)z = (x_2^2−x_1^2) + (y_2^2−y_1^2) + (z_2^2−z_1^2) \\ 2(x_3−x_1)x + 2(y_3−y_1)y + 2(z_3−z_1)z = (x_3^2−x_1^2) + (y_3^2−y_1^2) + (z_3^2−z_1^2) \end{cases}

The solution can be expressed in terms of parameters \(k_1\) and \(k_2\):

\begin{cases} x = x_1 + dx = x_1 + k_1(x_2−x_1) + k_2(x_2−x_1) \\ y = y_1 + dy = y_1 + k_1(y_2−y_1) + k_2(y_2−y_1) \\ z = z_1 + dz = z_1 + k_1(z_2−z_1) + k_2(z_2−z_1) \end{cases}

The parameters \(k_1\) and \(k_2\) are found by solving:

\begin{aligned} 2(\vec{v_1}\cdot\vec{v_1})k_1 + 2(\vec{v_1}\cdot\vec{v_2})k_2 = \vec{v_1}\cdot\vec{v_1} \\ 2(\vec{v_1}\cdot\vec{v_2})k_1 + 2(\vec{v_2}\cdot\vec{v_2})k_2 = \vec{v_2}\cdot\vec{v_2} \end{aligned}

Where

\begin{aligned} \vec{v_1}&=(x_2−x_1,y_2−y_1,z_2−z_1) \\ \vec{v_2}&=(x_3−x_1,y_3−y_1,z_3−z_1) \end{aligned}

Matrix form:

\[ 2\begin{bmatrix} a & b \\ b & c \end{bmatrix} \begin{bmatrix} k_1 \\ k_2 \end{bmatrix} =\begin{bmatrix} a \\ c \end{bmatrix} \]

Where

\begin{aligned} a&=\vec{v_1}\cdot\vec{v_1} \\ b&=\vec{v_1}\cdot\vec{v_2} \\ c&=\vec{v_2}\cdot\vec{v_2} \end{aligned}

Explicit Solution (Cramer's Rule):

\begin{aligned} k_1=\frac{c(a-b)}{2(ac-b^2)} \\ k_2=\frac{a(c-b)}{2(ac-b^2)} \end{aligned}

Radius (r):

\[ r = \sqrt{dx^2+dy^2+dz^2} \]

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

◆ set()

void a_vector3::set ( a_point3 const & p,
a_point3 const & q )
inline

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

See also
a_vector3_set