20#define A_VECTOR2_C(x, y) {a_real_c(x), a_real_c(y)}
24#define a_vector2_c(x) a_cast_s(a_vector2, x)
25#define a_vector2_(_, x) a_cast_s(a_vector2 _, x)
29#if defined(__cplusplus)
36#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR2_C)
39#define A_INTERN A_PUBLIC extern
328#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR2_C)
331#define A_INTERN static A_INLINE
334#if defined(__cplusplus)
345#if defined(__cplusplus)
543#if defined(LIBA_VECTOR2_C)
546#define A_INTERN A_INLINE
549#if defined(A_HAVE_INLINE) || defined(LIBA_VECTOR2_C)
569 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
573 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
577 res->x = lhs->x + rhs->x;
578 res->y = lhs->y + rhs->y;
582 res->x = lhs->x - rhs->x;
583 res->y = lhs->y - rhs->y;
587 res->x = lhs->x * rhs;
588 res->y = lhs->y * rhs;
592 res->x = lhs->x / rhs;
593 res->y = lhs->y / rhs;
603 return ctx->x * ctx->x + ctx->y * ctx->y;
608 a_real const x = rhs->x - lhs->x;
609 a_real const y = rhs->y - lhs->y;
610 return x * x + y * y;
615 return lhs->x * rhs->x + lhs->y * rhs->y;
620 return lhs->x * rhs->y - lhs->y * rhs->x;
625 res[0] = lhs->x * rhs->x;
626 res[1] = lhs->x * rhs->y;
627 res[2] = lhs->y * rhs->x;
628 res[3] = lhs->y * rhs->y;
633 a_real const r = lhs->x * rhs->x + lhs->y * rhs->y;
634 return A_ABS(r) < A_REAL_TOL;
639 a_real const r = lhs->x * rhs->y - lhs->y * rhs->x;
640 return A_ABS(r) < A_REAL_TOL;
645 res->x = lhs->x + (rhs->x - lhs->x) * val;
646 res->y = lhs->y + (rhs->y - lhs->y) * val;
651 a_real const x = cos * ctx->x - sin * ctx->y;
652 a_real const y = sin * ctx->x + cos * ctx->y;
658#if defined(LIBA_VECTOR2_C)
661#define A_INTERN static A_INLINE
void set(a_point2 const &p, a_point2 const &q)
set a 2D vector as the difference from point p to point q.
Definition point2.h:254
double a_real
compiler built-in floating-point number type
Definition a.h:1012
int a_vector2_decom(a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *u, a_vector2 *v)
decompose a 2D vector into two orthogonal components relative to a given direction.
void a_vector2_add(a_vector2 const *lhs, a_vector2 const *rhs, a_vector2 *res)
add a 2D vector to a 2D vector.
void a_vector2_set_val(a_vector2 *ctx, a_real x, a_real y)
set the cartesian coordinates of a 2D vector.
a_real a_vector2_set_dir(a_vector2 *ctx, a_real x, a_real y)
set the components of a 2D vector and normalize it in place.
void a_vector2_mul(a_vector2 const *lhs, a_real rhs, a_vector2 *res)
multiplie a 2D vector by a scalar.
void a_vector2_pol(a_vector2 const *ctx, a_real *rho, a_real *theta)
get the polar coordinates of a 2D vector.
void a_vector2_lerp(a_vector2 const *lhs, a_vector2 const *rhs, a_real val, a_vector2 *res)
compute linear interpolation (LERP) between two 2D vectors.
a_bool a_vector2_ispar(a_vector2 const *lhs, a_vector2 const *rhs)
check if two 2D vectors are parallel or anti-parallel.
a_real a_vector2_norm2(a_vector2 const *ctx)
compute the squared magnitude of a 2D vector.
a_bool a_vector2_isver(a_vector2 const *lhs, a_vector2 const *rhs)
check if two 2D vectors are orthogonal.
void a_vector2_set_pol(a_vector2 *ctx, a_real rho, a_real theta)
set the polar coordinates of a 2D vector.
a_real a_vector2_cross(a_vector2 const *lhs, a_vector2 const *rhs)
compute the cross product (vector product) of two 2D vectors
a_real a_vector2_dot(a_vector2 const *lhs, a_vector2 const *rhs)
compute the dot product (scalar product) of two 2D vectors.
a_real a_vector2_norm(a_vector2 const *ctx)
compute the magnitude of a 2D vector.
a_real a_vector2_unit(a_vector2 *ctx)
normalize a 2D vector in-place to unit length.
int a_vector2_proj(a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *res)
project vector onto the direction of vector.
void a_vector2_div(a_vector2 const *lhs, a_real rhs, a_vector2 *res)
divide a 2D vector by a scalar.
a_real a_vector2_dist2(a_vector2 const *lhs, a_vector2 const *rhs)
compute the squared distance between two 2D vectors.
void a_vector2_neg(a_vector2 const *ctx, a_vector2 *res)
negate a 2D vector.
void a_vector2_outer(a_vector2 const *lhs, a_vector2 const *rhs, a_real res[4])
compute the outer product (tensor product) of two 2D vectors.
a_real a_vector2_angle(a_vector2 const *lhs, a_vector2 const *rhs)
compute the angle between two 2D vectors in radians.
void a_vector2_sub(a_vector2 const *lhs, a_vector2 const *rhs, a_vector2 *res)
subtract a 2D vector from a 2D vector.
int a_vector2_perp(a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *res)
project vector onto the line perpendicular to vector.
int a_vector2_refl(a_vector2 const *ctx, a_vector2 const *dir, a_vector2 *res)
reflect vector across the line with direction vector.
void a_vector2_val(a_vector2 const *ctx, a_real *x, a_real *y)
get the cartesian coordinates of a 2D vector.
void a_vector2_rot_(a_vector2 const *ctx, a_real sin, a_real cos, a_vector2 *res)
rotate a 2D vector by a specified angle (in radians).
a_real a_vector2_dist(a_vector2 const *lhs, a_vector2 const *rhs)
compute the distance between two 2D vectors.
void a_vector2_rot(a_vector2 const *ctx, a_real angle, a_vector2 *res)
rotate a 2D vector by a specified angle (in radians).
#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 two-dimensional point
Definition point2.h:264
instance structure for two-dimensional vector
Definition vector2.h:343
a_real unit()
normalize a 2D vector in-place to unit length.
Definition vector2.h:399
a_bool isver(a_vector2 const &rhs) const
check if two 2D vectors are orthogonal.
Definition vector2.h:430
friend a_real operator^(a_vector2 const &lhs, a_vector2 const &rhs)
compute the cross product (vector product) of two 2D vectors
Definition vector2.h:480
void rot(a_real angle, a_vector2 &res) const
rotate a 2D vector by a specified angle (in radians).
Definition vector2.h:470
void pol(a_real &rho, a_real &theta) const
get the polar coordinates of a 2D vector.
Definition vector2.h:364
friend a_vector2 operator*(a_real lhs, a_vector2 const &rhs)
multiplie a 2D vector by a scalar.
Definition vector2.h:510
void rot(a_real sin, a_real cos, a_vector2 &res) const
rotate a 2D vector by a specified angle (in radians).
Definition vector2.h:475
friend a_vector2 operator/(a_vector2 const &lhs, a_real rhs)
divide a 2D vector by a scalar.
Definition vector2.h:526
friend a_real operator*(a_vector2 const &lhs, a_vector2 const &rhs)
compute the dot product (scalar product) of two 2D vectors.
Definition vector2.h:503
void div(a_real rhs, a_vector2 &res) const
divide a 2D vector by a scalar.
Definition vector2.h:389
a_real cross(a_vector2 const &rhs) const
compute the cross product (vector product) of two 2D vectors
Definition vector2.h:420
a_real dist2(a_vector2 const &rhs) const
compute the squared distance between two 2D vectors.
Definition vector2.h:410
a_real dist(a_vector2 const &rhs) const
compute the distance between two 2D vectors.
Definition vector2.h:405
int perp(a_vector2 const &dir, a_vector2 &res) const
project vector onto the line perpendicular to vector.
Definition vector2.h:455
void lerp(a_vector2 const &rhs, a_real val, a_vector2 &res) const
compute linear interpolation (LERP) between two 2D vectors.
Definition vector2.h:465
a_real dot(a_vector2 const &rhs) const
compute the dot product (scalar product) of two 2D vectors.
Definition vector2.h:415
void add(a_vector2 const &rhs, a_vector2 &res) const
add a 2D vector to a 2D vector.
Definition vector2.h:374
friend a_vector2 operator+(a_vector2 const &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D vector.
Definition vector2.h:487
int refl(a_vector2 const &dir, a_vector2 &res) const
reflect vector across the line with direction vector.
Definition vector2.h:460
a_real norm() const
compute the magnitude of a 2D vector.
Definition vector2.h:401
void val(a_real &x_, a_real &y_) const
get the cartesian coordinates of a 2D vector.
Definition vector2.h:354
friend a_vector2 operator*(a_vector2 const &lhs, a_real rhs)
multiplie a 2D vector by a scalar.
Definition vector2.h:517
void mul(a_real rhs, a_vector2 &res) const
multiplie a 2D vector by a scalar.
Definition vector2.h:384
void neg(a_vector2 &res) const
negate a 2D vector.
Definition vector2.h:394
friend void operator+=(a_vector2 &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D vector.
Definition vector2.h:485
void set_val(a_real x_, a_real y_)
set the cartesian coordinates of a 2D vector.
Definition vector2.h:359
friend a_vector2 operator-(a_vector2 const &rhs)
negate a 2D vector.
Definition vector2.h:534
int proj(a_vector2 const &dir, a_vector2 &res) const
project vector onto the direction of vector.
Definition vector2.h:450
friend void operator/=(a_vector2 &lhs, a_real rhs)
divide a 2D vector by a scalar.
Definition vector2.h:524
friend void operator-=(a_vector2 &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D vector.
Definition vector2.h:494
void sub(a_vector2 const &rhs, a_vector2 &res) const
subtract a 2D vector from a 2D vector.
Definition vector2.h:379
friend void operator*=(a_vector2 &lhs, a_real rhs)
multiplie a 2D vector by a scalar.
Definition vector2.h:508
void outer(a_vector2 const &rhs, a_real res[4]) const
compute the outer product (tensor product) of two 2D vectors.
Definition vector2.h:425
a_bool ispar(a_vector2 const &rhs) const
check if two 2D vectors are parallel or anti-parallel.
Definition vector2.h:435
int decom(a_vector2 const &dir, a_vector2 &u, a_vector2 &v) const
decompose a 2D vector into two orthogonal components relative to a given direction.
Definition vector2.h:445
friend a_vector2 operator-(a_vector2 const &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D vector.
Definition vector2.h:496
a_real set_dir(a_real x_, a_real y_)
set the components of a 2D vector and normalize it in place.
Definition vector2.h:349
void set_pol(a_real rho, a_real theta)
set the polar coordinates of a 2D vector.
Definition vector2.h:369
a_real norm2() const
compute the squared magnitude of a 2D vector.
Definition vector2.h:403
a_real angle(a_vector2 const &rhs) const
compute the squared distance between two 2D vectors.
Definition vector2.h:440