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
372#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR3_C)
375#define A_INTERN static A_INLINE
378#if defined(__cplusplus)
389#if defined(__cplusplus)
587#if defined(LIBA_VECTOR3_C)
590#define A_INTERN A_INLINE
593#if defined(A_HAVE_INLINE) || defined(LIBA_VECTOR3_C)
616 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
621 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
626 a_real_cart2sph(ctx->x, ctx->y, ctx->z, rho, theta, alpha);
630 a_real_sph2cart(rho, theta, alpha, &ctx->x, &ctx->y, &ctx->z);
634 res->x = lhs->x + rhs->x;
635 res->y = lhs->y + rhs->y;
636 res->z = lhs->z + rhs->z;
640 res->x = lhs->x - rhs->x;
641 res->y = lhs->y - rhs->y;
642 res->z = lhs->z - rhs->z;
646 res->x = lhs->x * rhs;
647 res->y = lhs->y * rhs;
648 res->z = lhs->z * rhs;
652 res->x = lhs->x / rhs;
653 res->y = lhs->y / rhs;
654 res->z = lhs->z / rhs;
664#if defined(LIBA_VECTOR3_C)
667#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:183
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.
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_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.
int a_vector3_ortho(a_vector3 const *ctx, a_vector3 *u, a_vector3 *v)
construct an orthonormal basis from a given 3D direction vector.
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.
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.
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:193
instance structure for three-dimensional vector
Definition vector3.h:387
a_bool ispar(a_vector3 const &rhs) const
check if two 3D vectors are parallel or anti-parallel.
Definition vector3.h:469
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:511
friend a_vector3 operator+(a_vector3 const &lhs, a_vector3 const &rhs)
add a 3D vector to a 3D vector.
Definition vector3.h:531
friend a_vector3 operator*(a_real lhs, a_vector3 const &rhs)
multiplie a 3D vector by a scalar.
Definition vector3.h:554
int proj(a_vector3 const &dir, a_vector3 &res) const
project vector onto the direction of vector.
Definition vector3.h:486
a_real norm2() const
compute the squared magnitude of a 3D vector.
Definition vector3.h:457
void set_cyl(a_real rho, a_real theta, a_real z_)
set the cylindrical coordinates of a 3D vector.
Definition vector3.h:413
void div(a_real rhs, a_vector3 &res) const
divide a 3D vector by a scalar.
Definition vector3.h:443
void sub(a_vector3 const &rhs, a_vector3 &res) const
subtract a 3D vector from a 3D vector.
Definition vector3.h:433
a_real unit()
normalize a 3D vector in-place to unit length.
Definition vector3.h:453
void val(a_real &x_, a_real &y_, a_real &z_) const
get the cartesian coordinates of a 3D vector.
Definition vector3.h:398
int perp(a_vector3 const &dir, a_vector3 &res) const
project vector onto the plane perpendicular to normal vector.
Definition vector3.h:491
friend void operator+=(a_vector3 &lhs, a_vector3 const &rhs)
add a 3D vector to a 3D vector.
Definition vector3.h:529
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:522
void outer(a_vector3 const &rhs, a_real res[9]) const
compute the outer product (tensor product) of two 3D vectors.
Definition vector3.h:476
void cyl(a_real &rho, a_real &theta, a_real &z_) const
get the cylindrical coordinates of a 3D vector.
Definition vector3.h:408
a_bool isver(a_vector3 const &rhs) const
check if two 3D vectors are orthogonal.
Definition vector3.h:467
friend void operator*=(a_vector3 &lhs, a_real rhs)
multiplie a 3D vector by a scalar.
Definition vector3.h:552
friend void operator-=(a_vector3 &lhs, a_vector3 const &rhs)
subtract a 3D vector from a 3D vector.
Definition vector3.h:538
a_real dist(a_vector3 const &rhs) const
compute the distance between two 3D vectors.
Definition vector3.h:461
int refl(a_vector3 const &dir, a_vector3 &res) const
reflect vector across the plane perpendicular to normal vector.
Definition vector3.h:496
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:516
a_real dist2(a_vector3 const &rhs) const
compute the squared distance between two 3D vectors.
Definition vector3.h:463
int sym1(a_vector3 const &dir, a_vector3 &res) const
reflect vector across the line with direction vector.
Definition vector3.h:501
a_real dot(a_vector3 const &rhs) const
compute the dot product (scalar product) of two 3D vectors.
Definition vector3.h:459
friend a_vector3 operator*(a_vector3 const &lhs, a_real rhs)
multiplie a 3D vector by a scalar.
Definition vector3.h:561
void mul(a_real rhs, a_vector3 &res) const
multiplie a 3D vector by a scalar.
Definition vector3.h:438
friend a_vector3 operator-(a_vector3 const &rhs)
negate a 3D vector.
Definition vector3.h:578
a_real angle(a_vector3 const &rhs) const
compute the angle between two 3D vectors in radians.
Definition vector3.h:465
int ortho(a_vector3 &u, a_vector3 &v) const
construct an orthonormal basis from a given 3D direction vector.
Definition vector3.h:481
friend a_vector3 operator-(a_vector3 const &lhs, a_vector3 const &rhs)
subtract a 3D vector from a 3D vector.
Definition vector3.h:540
a_real norm() const
compute the magnitude of a 3D vector.
Definition vector3.h:455
void neg(a_vector3 &res) const
negate a 3D vector.
Definition vector3.h:448
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:393
void add(a_vector3 const &rhs, a_vector3 &res) const
add a 3D vector to a 3D vector.
Definition vector3.h:428
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:547
void set_sph(a_real rho, a_real theta, a_real alpha)
set the spherical coordinates of a 3D vector.
Definition vector3.h:423
void set_val(a_real x_, a_real y_, a_real z_)
set the cartesian coordinates of a 3D vector.
Definition vector3.h:403
void cross(a_vector3 const &rhs, a_vector3 &res) const
compute the cross product (vector product) of two 3D vectors
Definition vector3.h:471
void sph(a_real &rho, a_real &theta, a_real &alpha) const
get the spherical coordinates of a 3D vector.
Definition vector3.h:418
friend a_vector3 operator/(a_vector3 const &lhs, a_real rhs)
divide a 3D vector by a scalar.
Definition vector3.h:570
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:506
friend void operator/=(a_vector3 &lhs, a_real rhs)
divide a 3D vector by a scalar.
Definition vector3.h:568