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
300#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR2_C)
303#define A_INTERN static A_INLINE
306#if defined(__cplusplus)
317#if defined(__cplusplus)
475#if defined(LIBA_VECTOR2_C)
478#define A_INTERN A_INLINE
481#if defined(A_HAVE_INLINE) || defined(LIBA_VECTOR2_C)
501 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
505 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
509 res->x = lhs->x + rhs->x;
510 res->y = lhs->y + rhs->y;
514 res->x = lhs->x - rhs->x;
515 res->y = lhs->y - rhs->y;
519 res->x = lhs->x * rhs;
520 res->y = lhs->y * rhs;
524 res->x = lhs->x / rhs;
525 res->y = lhs->y / rhs;
534#if defined(LIBA_VECTOR2_C)
537#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:175
double a_real
compiler built-in floating-point number type
Definition a.h:1012
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.
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).
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:185
instance structure for two-dimensional vector
Definition vector2.h:315
a_real unit()
normalize a 2D vector in-place to unit length.
Definition vector2.h:371
a_bool isver(a_vector2 const &rhs) const
check if two 2D vectors are orthogonal.
Definition vector2.h:385
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:412
void rot(a_real angle, a_vector2 &res) const
rotate a 2D vector by a specified angle (in radians).
Definition vector2.h:408
void pol(a_real &rho, a_real &theta) const
get the polar coordinates of a 2D vector.
Definition vector2.h:336
friend a_vector2 operator*(a_real lhs, a_vector2 const &rhs)
multiplie a 2D vector by a scalar.
Definition vector2.h:442
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:410
friend a_vector2 operator/(a_vector2 const &lhs, a_real rhs)
divide a 2D vector by a scalar.
Definition vector2.h:458
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:435
void div(a_real rhs, a_vector2 &res) const
divide a 2D vector by a scalar.
Definition vector2.h:361
a_real cross(a_vector2 const &rhs) const
compute the cross product (vector product) of two 2D vectors
Definition vector2.h:389
a_real dist2(a_vector2 const &rhs) const
compute the squared distance between two 2D vectors.
Definition vector2.h:381
a_real dist(a_vector2 const &rhs) const
compute the distance between two 2D vectors.
Definition vector2.h:379
int perp(a_vector2 const &dir, a_vector2 &res) const
project vector onto the line perpendicular to vector.
Definition vector2.h:398
a_real dot(a_vector2 const &rhs) const
compute the dot product (scalar product) of two 2D vectors.
Definition vector2.h:377
void add(a_vector2 const &rhs, a_vector2 &res) const
add a 2D vector to a 2D vector.
Definition vector2.h:346
friend a_vector2 operator+(a_vector2 const &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D vector.
Definition vector2.h:419
int refl(a_vector2 const &dir, a_vector2 &res) const
reflect vector across the line with direction vector.
Definition vector2.h:403
a_real norm() const
compute the magnitude of a 2D vector.
Definition vector2.h:373
void val(a_real &x_, a_real &y_) const
get the cartesian coordinates of a 2D vector.
Definition vector2.h:326
friend a_vector2 operator*(a_vector2 const &lhs, a_real rhs)
multiplie a 2D vector by a scalar.
Definition vector2.h:449
void mul(a_real rhs, a_vector2 &res) const
multiplie a 2D vector by a scalar.
Definition vector2.h:356
void neg(a_vector2 &res) const
negate a 2D vector.
Definition vector2.h:366
friend void operator+=(a_vector2 &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D vector.
Definition vector2.h:417
void set_val(a_real x_, a_real y_)
set the cartesian coordinates of a 2D vector.
Definition vector2.h:331
friend a_vector2 operator-(a_vector2 const &rhs)
negate a 2D vector.
Definition vector2.h:466
int proj(a_vector2 const &dir, a_vector2 &res) const
project vector onto the direction of vector.
Definition vector2.h:393
friend void operator/=(a_vector2 &lhs, a_real rhs)
divide a 2D vector by a scalar.
Definition vector2.h:456
friend void operator-=(a_vector2 &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D vector.
Definition vector2.h:426
void sub(a_vector2 const &rhs, a_vector2 &res) const
subtract a 2D vector from a 2D vector.
Definition vector2.h:351
friend void operator*=(a_vector2 &lhs, a_real rhs)
multiplie a 2D vector by a scalar.
Definition vector2.h:440
void outer(a_vector2 const &rhs, a_real res[4]) const
compute the outer product (tensor product) of two 2D vectors.
Definition vector2.h:391
a_bool ispar(a_vector2 const &rhs) const
check if two 2D vectors are parallel or anti-parallel.
Definition vector2.h:387
friend a_vector2 operator-(a_vector2 const &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D vector.
Definition vector2.h:428
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:321
void set_pol(a_real rho, a_real theta)
set the polar coordinates of a 2D vector.
Definition vector2.h:341
a_real norm2() const
compute the squared magnitude of a 2D vector.
Definition vector2.h:375
a_real angle(a_vector2 const &rhs) const
compute the squared distance between two 2D vectors.
Definition vector2.h:383