20#define A_VECTOR3_C(x, y, z) {a_real_c(x), a_real_c(y), a_real_c(z)}
24#define a_vector3_c(x) a_cast_s(a_vector3, x)
25#define a_vector3_(_, x) a_cast_s(a_vector3 _, x)
29#if defined(__cplusplus)
36#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR3_C)
39#define A_INTERN A_PUBLIC extern
400#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR3_C)
403#define A_INTERN static A_INLINE
406#if defined(__cplusplus)
417#if defined(__cplusplus)
643#if defined(LIBA_VECTOR3_C)
646#define A_INTERN A_INLINE
649#if defined(A_HAVE_INLINE) || defined(LIBA_VECTOR3_C)
672 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
677 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
682 a_real_cart2sph(ctx->x, ctx->y, ctx->z, rho, theta, alpha);
686 a_real_sph2cart(rho, theta, alpha, &ctx->x, &ctx->y, &ctx->z);
690 res->x = lhs->x + rhs->x;
691 res->y = lhs->y + rhs->y;
692 res->z = lhs->z + rhs->z;
696 res->x = lhs->x - rhs->x;
697 res->y = lhs->y - rhs->y;
698 res->z = lhs->z - rhs->z;
702 res->x = lhs->x * rhs;
703 res->y = lhs->y * rhs;
704 res->z = lhs->z * rhs;
708 res->x = lhs->x / rhs;
709 res->y = lhs->y / rhs;
710 res->z = lhs->z / rhs;
721 return ctx->x * ctx->x + ctx->y * ctx->y + ctx->z * ctx->z;
726 a_real const x = rhs->x - lhs->x;
727 a_real const y = rhs->y - lhs->y;
728 a_real const z = rhs->z - lhs->z;
729 return x * x + y * y + z * z;
734 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
739 a_real const x = lhs->y * rhs->z - lhs->z * rhs->y;
740 a_real const y = lhs->z * rhs->x - lhs->x * rhs->z;
741 a_real const z = lhs->x * rhs->y - lhs->y * rhs->x;
749 res[0] = lhs->x * rhs->x;
750 res[1] = lhs->x * rhs->y;
751 res[2] = lhs->x * rhs->z;
752 res[3] = lhs->y * rhs->x;
753 res[4] = lhs->y * rhs->y;
754 res[5] = lhs->y * rhs->z;
755 res[6] = lhs->z * rhs->x;
756 res[7] = lhs->z * rhs->y;
757 res[8] = lhs->z * rhs->z;
762 a_real const r = lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
763 return A_ABS(r) < A_REAL_TOL;
769 z = lhs->x * rhs->y - lhs->y * rhs->x;
770 if (!(
A_ABS(z) < A_REAL_TOL)) {
return 0; }
771 y = lhs->z * rhs->x - lhs->x * rhs->z;
772 if (!(
A_ABS(y) < A_REAL_TOL)) {
return 0; }
773 x = lhs->y * rhs->z - lhs->z * rhs->y;
774 if (!(
A_ABS(x) < A_REAL_TOL)) {
return 0; }
780 res->x = lhs->x + (rhs->x - lhs->x) * val;
781 res->y = lhs->y + (rhs->y - lhs->y) * val;
782 res->z = lhs->z + (rhs->z - lhs->z) * val;
786#if defined(LIBA_VECTOR3_C)
789#define A_INTERN static A_INLINE
void set(a_point3 const &p, a_point3 const &q)
set a 3D vector as the difference from point p to point q.
Definition point3.h:340
double a_real
compiler built-in floating-point number type
Definition a.h:1012
void a_vector3_cyl(a_vector3 const *ctx, a_real *rho, a_real *theta, a_real *z)
get the cylindrical coordinates of a 3D vector.
int a_vector3_decom(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *u, a_vector3 *v)
decompose a 3D vector into two orthogonal components relative to a given direction.
void a_vector3_rot(a_vector3 const *ctx, a_vector3 const *dir, a_real angle, a_vector3 *res)
rotate a 3D vector around an arbitrary unit axis using Rodrigues' rotation formula.
int a_vector3_sym1(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res)
reflect vector across the line with direction vector.
void a_vector3_mul(a_vector3 const *lhs, a_real rhs, a_vector3 *res)
multiplie a 3D vector by a scalar.
void a_vector3_lerp(a_vector3 const *lhs, a_vector3 const *rhs, a_real val, a_vector3 *res)
compute linear interpolation (LERP) between two 3D vectors.
void a_vector3_set_cyl(a_vector3 *ctx, a_real rho, a_real theta, a_real z)
set the cylindrical coordinates of a 3D vector.
void a_vector3_set_sph(a_vector3 *ctx, a_real rho, a_real theta, a_real alpha)
set the spherical coordinates of a 3D vector.
a_real a_vector3_dot(a_vector3 const *lhs, a_vector3 const *rhs)
compute the dot product (scalar product) of two 3D vectors.
void a_vector3_rot_(a_vector3 const *ctx, a_vector3 const *dir, a_real sin, a_real cos, a_vector3 *res)
rotate a 3D vector around an arbitrary unit axis using Rodrigues' rotation formula.
void a_vector3_sph(a_vector3 const *ctx, a_real *rho, a_real *theta, a_real *alpha)
get the spherical coordinates of a 3D vector.
void a_vector3_set_val(a_vector3 *ctx, a_real x, a_real y, a_real z)
set the cartesian coordinates of a 3D vector.
a_real a_vector3_norm2(a_vector3 const *ctx)
compute the squared magnitude of a 3D vector.
void a_vector3_outer(a_vector3 const *lhs, a_vector3 const *rhs, a_real res[9])
compute the outer product (tensor product) of two 3D vectors.
a_real a_vector3_set_dir(a_vector3 *ctx, a_real x, a_real y, a_real z)
set the components of a 3D vector and normalize it in place.
void a_vector3_add(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res)
add a 3D vector to a 3D vector.
void a_vector3_cross(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res)
compute the cross product (vector product) of two 3D vectors
void a_vector3_rot2d(a_vector3 const *iu, a_vector3 const *iv, a_real angle, a_vector3 *ou, a_vector3 *ov)
rotate a 2D basis in the plane spanned by two orthogonal vectors.
a_bool a_vector3_isver(a_vector3 const *lhs, a_vector3 const *rhs)
check if two 3D vectors are orthogonal.
a_bool a_vector3_ispar(a_vector3 const *lhs, a_vector3 const *rhs)
check if two 3D vectors are parallel or anti-parallel.
a_real a_vector3_angle(a_vector3 const *lhs, a_vector3 const *rhs)
compute the angle between two 3D vectors in radians.
int a_vector3_proj(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res)
project vector onto the direction of vector.
a_real a_vector3_dist2(a_vector3 const *lhs, a_vector3 const *rhs)
compute the squared distance between two 3D vectors.
int a_vector3_refl(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res)
reflect vector across the plane perpendicular to normal vector.
a_real a_vector3_dist(a_vector3 const *lhs, a_vector3 const *rhs)
compute the distance between two 3D vectors.
int a_vector3_basis(a_vector3 const *ctx, a_vector3 *u, a_vector3 *v)
construct an orthonormal basis from a given 3D direction vector.
a_real a_vector3_norm(a_vector3 const *ctx)
compute the magnitude of a 3D vector.
a_real a_vector3_unit(a_vector3 *ctx)
normalize a 3D vector in-place to unit length.
void a_vector3_neg(a_vector3 const *ctx, a_vector3 *res)
negate a 3D vector.
void a_vector3_div(a_vector3 const *lhs, a_real rhs, a_vector3 *res)
divide a 3D vector by a scalar.
void a_vector3_sub(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res)
subtract a 3D vector from a 3D vector.
void a_vector3_val(a_vector3 const *ctx, a_real *x, a_real *y, a_real *z)
get the cartesian coordinates of a 3D vector.
int a_vector3_perp(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res)
project vector onto the plane perpendicular to normal vector.
#define A_ABS(x)
absolute value of x,
Definition a.h:1062
bool a_bool
type, capable of holding one of the two values: 1 and 0
Definition a.h:320
mathematical algorithm library
instance structure for three-dimensional point
Definition point3.h:350
instance structure for three-dimensional vector
Definition vector3.h:415
a_bool ispar(a_vector3 const &rhs) const
check if two 3D vectors are parallel or anti-parallel.
Definition vector3.h:517
void rot(a_vector3 const &dir, a_real sin, a_real cos, a_vector3 &res) const
rotate a 3D vector around an arbitrary unit axis using Rodrigues' rotation formula.
Definition vector3.h:567
friend a_vector3 operator+(a_vector3 const &lhs, a_vector3 const &rhs)
add a 3D vector to a 3D vector.
Definition vector3.h:587
friend a_vector3 operator*(a_real lhs, a_vector3 const &rhs)
multiplie a 3D vector by a scalar.
Definition vector3.h:610
int proj(a_vector3 const &dir, a_vector3 &res) const
project vector onto the direction of vector.
Definition vector3.h:537
a_real norm2() const
compute the squared magnitude of a 3D vector.
Definition vector3.h:485
void set_cyl(a_real rho, a_real theta, a_real z_)
set the cylindrical coordinates of a 3D vector.
Definition vector3.h:441
void div(a_real rhs, a_vector3 &res) const
divide a 3D vector by a scalar.
Definition vector3.h:471
void sub(a_vector3 const &rhs, a_vector3 &res) const
subtract a 3D vector from a 3D vector.
Definition vector3.h:461
a_real unit()
normalize a 3D vector in-place to unit length.
Definition vector3.h:481
void val(a_real &x_, a_real &y_, a_real &z_) const
get the cartesian coordinates of a 3D vector.
Definition vector3.h:426
int perp(a_vector3 const &dir, a_vector3 &res) const
project vector onto the plane perpendicular to normal vector.
Definition vector3.h:542
friend void operator+=(a_vector3 &lhs, a_vector3 const &rhs)
add a 3D vector to a 3D vector.
Definition vector3.h:585
friend a_vector3 operator^(a_vector3 const &lhs, a_vector3 const &rhs)
compute the cross product (vector product) of two 3D vectors
Definition vector3.h:578
void outer(a_vector3 const &rhs, a_real res[9]) const
compute the outer product (tensor product) of two 3D vectors.
Definition vector3.h:507
void cyl(a_real &rho, a_real &theta, a_real &z_) const
get the cylindrical coordinates of a 3D vector.
Definition vector3.h:436
a_bool isver(a_vector3 const &rhs) const
check if two 3D vectors are orthogonal.
Definition vector3.h:512
friend void operator*=(a_vector3 &lhs, a_real rhs)
multiplie a 3D vector by a scalar.
Definition vector3.h:608
friend void operator-=(a_vector3 &lhs, a_vector3 const &rhs)
subtract a 3D vector from a 3D vector.
Definition vector3.h:594
a_real dist(a_vector3 const &rhs) const
compute the distance between two 3D vectors.
Definition vector3.h:487
int decom(a_vector3 const &dir, a_vector3 &u, a_vector3 &v) const
decompose a 3D vector into two orthogonal components relative to a given direction.
Definition vector3.h:532
int refl(a_vector3 const &dir, a_vector3 &res) const
reflect vector across the plane perpendicular to normal vector.
Definition vector3.h:547
static void rot2d(a_vector3 const &iu, a_vector3 const &iv, a_real angle, a_vector3 &ou, a_vector3 &ov)
rotate a 2D basis in the plane spanned by two orthogonal vectors.
Definition vector3.h:572
a_real dist2(a_vector3 const &rhs) const
compute the squared distance between two 3D vectors.
Definition vector3.h:492
int sym1(a_vector3 const &dir, a_vector3 &res) const
reflect vector across the line with direction vector.
Definition vector3.h:552
a_real dot(a_vector3 const &rhs) const
compute the dot product (scalar product) of two 3D vectors.
Definition vector3.h:497
friend a_vector3 operator*(a_vector3 const &lhs, a_real rhs)
multiplie a 3D vector by a scalar.
Definition vector3.h:617
void mul(a_real rhs, a_vector3 &res) const
multiplie a 3D vector by a scalar.
Definition vector3.h:466
friend a_vector3 operator-(a_vector3 const &rhs)
negate a 3D vector.
Definition vector3.h:634
a_real angle(a_vector3 const &rhs) const
compute the angle between two 3D vectors in radians.
Definition vector3.h:522
friend a_vector3 operator-(a_vector3 const &lhs, a_vector3 const &rhs)
subtract a 3D vector from a 3D vector.
Definition vector3.h:596
a_real norm() const
compute the magnitude of a 3D vector.
Definition vector3.h:483
void neg(a_vector3 &res) const
negate a 3D vector.
Definition vector3.h:476
int basis(a_vector3 &u, a_vector3 &v) const
construct an orthonormal basis from a given 3D direction vector.
Definition vector3.h:527
a_real set_dir(a_real x_, a_real y_, a_real z_)
set the components of a 3D vector and normalize it in place.
Definition vector3.h:421
void lerp(a_vector3 const &rhs, a_real val, a_vector3 &res) const
compute linear interpolation (LERP) between two 3D vectors.
Definition vector3.h:557
void add(a_vector3 const &rhs, a_vector3 &res) const
add a 3D vector to a 3D vector.
Definition vector3.h:456
friend a_real operator*(a_vector3 const &lhs, a_vector3 const &rhs)
compute the dot product (scalar product) of two 3D vectors.
Definition vector3.h:603
void set_sph(a_real rho, a_real theta, a_real alpha)
set the spherical coordinates of a 3D vector.
Definition vector3.h:451
void set_val(a_real x_, a_real y_, a_real z_)
set the cartesian coordinates of a 3D vector.
Definition vector3.h:431
void cross(a_vector3 const &rhs, a_vector3 &res) const
compute the cross product (vector product) of two 3D vectors
Definition vector3.h:502
void sph(a_real &rho, a_real &theta, a_real &alpha) const
get the spherical coordinates of a 3D vector.
Definition vector3.h:446
friend a_vector3 operator/(a_vector3 const &lhs, a_real rhs)
divide a 3D vector by a scalar.
Definition vector3.h:626
void rot(a_vector3 const &dir, a_real angle, a_vector3 &res) const
rotate a 3D vector around an arbitrary unit axis using Rodrigues' rotation formula.
Definition vector3.h:562
friend void operator/=(a_vector3 &lhs, a_real rhs)
divide a 3D vector by a scalar.
Definition vector3.h:624