liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
vector3.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_VECTOR3_H
7#define LIBA_VECTOR3_H
8
9#include "a.h"
10#include "math.h"
11
17
18/* clang-format off */
20#define A_VECTOR3_C(x, y, z) {a_real_c(x), a_real_c(y), a_real_c(z)}
21/* clang-format on */
22
24#define a_vector3_c(x) a_cast_s(a_vector3, x)
25#define a_vector3_(_, x) a_cast_s(a_vector3 _, x)
26
27typedef struct a_vector3 a_vector3;
28
29#if defined(__cplusplus)
30namespace a
31{
32typedef struct a_vector3 vector3;
33} /* namespace a */
34extern "C" {
35#endif /* __cplusplus */
36#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR3_C)
38#undef A_INTERN
39#define A_INTERN A_PUBLIC extern
41#endif /* A_HAVE_INLINE */
42
51A_INTERN void a_vector3_val(a_vector3 const *ctx, a_real *x, a_real *y, a_real *z);
55A_INTERN void a_vector3_set_val(a_vector3 *ctx, a_real x, a_real y, a_real z);
59A_INTERN void a_vector3_cyl(a_vector3 const *ctx, a_real *rho, a_real *theta, a_real *z);
63A_INTERN void a_vector3_set_cyl(a_vector3 *ctx, a_real rho, a_real theta, a_real z);
67A_INTERN void a_vector3_sph(a_vector3 const *ctx, a_real *rho, a_real *theta, a_real *alpha);
71A_INTERN void a_vector3_set_sph(a_vector3 *ctx, a_real rho, a_real theta, a_real alpha);
72
76A_INTERN void a_vector3_add(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res);
80A_INTERN void a_vector3_sub(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res);
84A_INTERN void a_vector3_mul(a_vector3 const *lhs, a_real rhs, a_vector3 *res);
88A_INTERN void a_vector3_div(a_vector3 const *lhs, a_real rhs, a_vector3 *res);
92A_INTERN void a_vector3_neg(a_vector3 const *ctx, a_vector3 *res);
93
110A_EXTERN a_real a_vector3_norm(a_vector3 const *ctx);
121A_INTERN a_real a_vector3_norm2(a_vector3 const *ctx);
135A_EXTERN a_real a_vector3_dist(a_vector3 const *lhs, a_vector3 const *rhs);
149A_INTERN a_real a_vector3_dist2(a_vector3 const *lhs, a_vector3 const *rhs);
163A_INTERN a_real a_vector3_dot(a_vector3 const *lhs, a_vector3 const *rhs);
180A_INTERN void a_vector3_cross(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res);
197A_INTERN void a_vector3_outer(a_vector3 const *lhs, a_vector3 const *rhs, a_real res[9]);
205A_INTERN a_bool a_vector3_isver(a_vector3 const *lhs, a_vector3 const *rhs);
213A_INTERN a_bool a_vector3_ispar(a_vector3 const *lhs, a_vector3 const *rhs);
229A_EXTERN a_real a_vector3_angle(a_vector3 const *lhs, a_vector3 const *rhs);
230
252A_EXTERN int a_vector3_basis(a_vector3 const *ctx, a_vector3 *u, a_vector3 *v);
253
266A_EXTERN int a_vector3_decom(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *u, a_vector3 *v);
267
283A_EXTERN int a_vector3_proj(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res);
299A_EXTERN int a_vector3_perp(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res);
315A_EXTERN int a_vector3_refl(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res);
331A_EXTERN int a_vector3_sym1(a_vector3 const *ctx, a_vector3 const *dir, a_vector3 *res);
332
345A_INTERN void a_vector3_lerp(a_vector3 const *lhs, a_vector3 const *rhs, a_real val, a_vector3 *res);
346
362A_EXTERN void a_vector3_rot_(a_vector3 const *ctx, a_vector3 const *dir, a_real sin, a_real cos, a_vector3 *res);
377A_EXTERN void a_vector3_rot(a_vector3 const *ctx, a_vector3 const *dir, a_real angle, a_vector3 *res);
397A_EXTERN void a_vector3_rot2d(a_vector3 const *iu, a_vector3 const *iv, a_real angle,
398 a_vector3 *ou, a_vector3 *ov);
399
400#if !defined A_HAVE_INLINE || defined(LIBA_VECTOR3_C)
402#undef A_INTERN
403#define A_INTERN static A_INLINE
405#endif /* A_HAVE_INLINE */
406#if defined(__cplusplus)
407} /* extern "C" */
408#endif /* __cplusplus */
409
410struct a_point3;
415{
416 a_real x, y, z;
417#if defined(__cplusplus)
419 A_INLINE void set(a_point3 const &p, a_point3 const &q);
421 A_INLINE a_real set_dir(a_real x_, a_real y_, a_real z_)
422 {
423 return a_vector3_set_dir(this, x_, y_, z_);
424 }
425
426 A_INLINE void val(a_real &x_, a_real &y_, a_real &z_) const
427 {
428 a_vector3_val(this, &x_, &y_, &z_);
429 }
430
431 A_INLINE void set_val(a_real x_, a_real y_, a_real z_)
432 {
433 a_vector3_set_val(this, x_, y_, z_);
434 }
435
436 A_INLINE void cyl(a_real &rho, a_real &theta, a_real &z_) const
437 {
438 a_vector3_cyl(this, &rho, &theta, &z_);
439 }
440
441 A_INLINE void set_cyl(a_real rho, a_real theta, a_real z_)
442 {
443 a_vector3_set_cyl(this, rho, theta, z_);
444 }
445
446 A_INLINE void sph(a_real &rho, a_real &theta, a_real &alpha) const
447 {
448 a_vector3_sph(this, &rho, &theta, &alpha);
449 }
450
451 A_INLINE void set_sph(a_real rho, a_real theta, a_real alpha)
452 {
453 a_vector3_set_sph(this, rho, theta, alpha);
454 }
455
456 A_INLINE void add(a_vector3 const &rhs, a_vector3 &res) const
457 {
458 a_vector3_add(this, &rhs, &res);
459 }
460
461 A_INLINE void sub(a_vector3 const &rhs, a_vector3 &res) const
462 {
463 a_vector3_sub(this, &rhs, &res);
464 }
465
466 A_INLINE void mul(a_real rhs, a_vector3 &res) const
467 {
468 a_vector3_mul(this, rhs, &res);
469 }
470
471 A_INLINE void div(a_real rhs, a_vector3 &res) const
472 {
473 a_vector3_div(this, rhs, &res);
474 }
475
476 A_INLINE void neg(a_vector3 &res) const
477 {
478 a_vector3_neg(this, &res);
479 }
480
481 A_INLINE a_real unit() { return a_vector3_unit(this); }
483 A_INLINE a_real norm() const { return a_vector3_norm(this); }
485 A_INLINE a_real norm2() const { return a_vector3_norm2(this); }
487 A_INLINE a_real dist(a_vector3 const &rhs) const
488 {
489 return a_vector3_dist(this, &rhs);
490 }
491
492 A_INLINE a_real dist2(a_vector3 const &rhs) const
493 {
494 return a_vector3_dist2(this, &rhs);
495 }
496
497 A_INLINE a_real dot(a_vector3 const &rhs) const
498 {
499 return a_vector3_dot(this, &rhs);
500 }
501
502 A_INLINE void cross(a_vector3 const &rhs, a_vector3 &res) const
503 {
504 a_vector3_cross(this, &rhs, &res);
505 }
506
507 A_INLINE void outer(a_vector3 const &rhs, a_real res[9]) const
508 {
509 a_vector3_outer(this, &rhs, res);
510 }
511
512 A_INLINE a_bool isver(a_vector3 const &rhs) const
513 {
514 return a_vector3_isver(this, &rhs);
515 }
516
517 A_INLINE a_bool ispar(a_vector3 const &rhs) const
518 {
519 return a_vector3_ispar(this, &rhs);
520 }
521
522 A_INLINE a_real angle(a_vector3 const &rhs) const
523 {
524 return a_vector3_angle(this, &rhs);
525 }
526
527 A_INLINE int basis(a_vector3 &u, a_vector3 &v) const
528 {
529 return a_vector3_basis(this, &u, &v);
530 }
531
532 A_INLINE int decom(a_vector3 const &dir, a_vector3 &u, a_vector3 &v) const
533 {
534 return a_vector3_decom(this, &dir, &u, &v);
535 }
536
537 A_INLINE int proj(a_vector3 const &dir, a_vector3 &res) const
538 {
539 return a_vector3_proj(this, &dir, &res);
540 }
541
542 A_INLINE int perp(a_vector3 const &dir, a_vector3 &res) const
543 {
544 return a_vector3_perp(this, &dir, &res);
545 }
546
547 A_INLINE int refl(a_vector3 const &dir, a_vector3 &res) const
548 {
549 return a_vector3_refl(this, &dir, &res);
550 }
551
552 A_INLINE int sym1(a_vector3 const &dir, a_vector3 &res) const
553 {
554 return a_vector3_sym1(this, &dir, &res);
555 }
556
557 A_INLINE void lerp(a_vector3 const &rhs, a_real val, a_vector3 &res) const
558 {
559 a_vector3_lerp(this, &rhs, val, &res);
560 }
561
562 A_INLINE void rot(a_vector3 const &dir, a_real angle, a_vector3 &res) const
563 {
564 a_vector3_rot(this, &dir, angle, &res);
565 }
566
567 A_INLINE void rot(a_vector3 const &dir, a_real sin, a_real cos, a_vector3 &res) const
568 {
569 a_vector3_rot_(this, &dir, sin, cos, &res);
570 }
571
572 static A_INLINE void rot2d(a_vector3 const &iu, a_vector3 const &iv, a_real angle,
573 a_vector3 &ou, a_vector3 &ov)
574 {
575 a_vector3_rot2d(&iu, &iv, angle, &ou, &ov);
576 }
577
578 friend A_INLINE a_vector3 operator^(a_vector3 const &lhs, a_vector3 const &rhs)
579 {
580 a_vector3 res;
581 a_vector3_cross(&lhs, &rhs, &res);
582 return res;
583 }
584
585 friend A_INLINE void operator+=(a_vector3 &lhs, a_vector3 const &rhs) { a_vector3_add(&lhs, &rhs, &lhs); }
587 friend A_INLINE a_vector3 operator+(a_vector3 const &lhs, a_vector3 const &rhs)
588 {
589 a_vector3 res;
590 a_vector3_add(&lhs, &rhs, &res);
591 return res;
592 }
593
594 friend A_INLINE void operator-=(a_vector3 &lhs, a_vector3 const &rhs) { a_vector3_sub(&lhs, &rhs, &lhs); }
596 friend A_INLINE a_vector3 operator-(a_vector3 const &lhs, a_vector3 const &rhs)
597 {
598 a_vector3 res;
599 a_vector3_sub(&lhs, &rhs, &res);
600 return res;
601 }
602
603 friend A_INLINE a_real operator*(a_vector3 const &lhs, a_vector3 const &rhs)
604 {
605 return a_vector3_dot(&lhs, &rhs);
606 }
607
608 friend A_INLINE void operator*=(a_vector3 &lhs, a_real rhs) { a_vector3_mul(&lhs, rhs, &lhs); }
610 friend A_INLINE a_vector3 operator*(a_real lhs, a_vector3 const &rhs)
611 {
612 a_vector3 res;
613 a_vector3_mul(&rhs, lhs, &res);
614 return res;
615 }
616
617 friend A_INLINE a_vector3 operator*(a_vector3 const &lhs, a_real rhs)
618 {
619 a_vector3 res;
620 a_vector3_mul(&lhs, rhs, &res);
621 return res;
622 }
623
624 friend A_INLINE void operator/=(a_vector3 &lhs, a_real rhs) { a_vector3_div(&lhs, rhs, &lhs); }
626 friend A_INLINE a_vector3 operator/(a_vector3 const &lhs, a_real rhs)
627 {
628 a_vector3 res;
629 a_vector3_div(&lhs, rhs, &res);
630 return res;
631 }
632 friend A_INLINE a_vector3 operator+(a_vector3 const &rhs) { return rhs; }
634 friend A_INLINE a_vector3 operator-(a_vector3 const &rhs)
635 {
636 a_vector3 res;
637 a_vector3_neg(&rhs, &res);
638 return res;
639 }
640#endif /* __cplusplus */
641};
642
643#if defined(LIBA_VECTOR3_C)
645#undef A_INTERN
646#define A_INTERN A_INLINE
648#endif /* LIBA_VECTOR3_C */
649#if defined(A_HAVE_INLINE) || defined(LIBA_VECTOR3_C)
650
652{
653 ctx->x = x;
654 ctx->y = y;
655 ctx->z = z;
656 return a_vector3_unit(ctx);
657}
658A_INTERN void a_vector3_val(a_vector3 const *ctx, a_real *x, a_real *y, a_real *z)
659{
660 *x = ctx->x;
661 *y = ctx->y;
662 *z = ctx->z;
663}
664A_INTERN void a_vector3_set_val(a_vector3 *ctx, a_real x, a_real y, a_real z)
665{
666 ctx->x = x;
667 ctx->y = y;
668 ctx->z = z;
669}
670A_INTERN void a_vector3_cyl(a_vector3 const *ctx, a_real *rho, a_real *theta, a_real *z)
671{
672 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
673 *z = ctx->z;
674}
675A_INTERN void a_vector3_set_cyl(a_vector3 *ctx, a_real rho, a_real theta, a_real z)
676{
677 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
678 ctx->z = z;
679}
680A_INTERN void a_vector3_sph(a_vector3 const *ctx, a_real *rho, a_real *theta, a_real *alpha)
681{
682 a_real_cart2sph(ctx->x, ctx->y, ctx->z, rho, theta, alpha);
683}
684A_INTERN void a_vector3_set_sph(a_vector3 *ctx, a_real rho, a_real theta, a_real alpha)
685{
686 a_real_sph2cart(rho, theta, alpha, &ctx->x, &ctx->y, &ctx->z);
687}
688A_INTERN void a_vector3_add(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res)
689{
690 res->x = lhs->x + rhs->x;
691 res->y = lhs->y + rhs->y;
692 res->z = lhs->z + rhs->z;
693}
694A_INTERN void a_vector3_sub(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res)
695{
696 res->x = lhs->x - rhs->x;
697 res->y = lhs->y - rhs->y;
698 res->z = lhs->z - rhs->z;
699}
700A_INTERN void a_vector3_mul(a_vector3 const *lhs, a_real rhs, a_vector3 *res)
701{
702 res->x = lhs->x * rhs;
703 res->y = lhs->y * rhs;
704 res->z = lhs->z * rhs;
705}
706A_INTERN void a_vector3_div(a_vector3 const *lhs, a_real rhs, a_vector3 *res)
707{
708 res->x = lhs->x / rhs;
709 res->y = lhs->y / rhs;
710 res->z = lhs->z / rhs;
711}
712A_INTERN void a_vector3_neg(a_vector3 const *ctx, a_vector3 *res)
713{
714 res->x = -ctx->x;
715 res->y = -ctx->y;
716 res->z = -ctx->z;
717}
718
719A_INTERN a_real a_vector3_norm2(a_vector3 const *ctx)
720{
721 return ctx->x * ctx->x + ctx->y * ctx->y + ctx->z * ctx->z;
722}
723
724A_INTERN a_real a_vector3_dist2(a_vector3 const *lhs, a_vector3 const *rhs)
725{
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;
730}
731
732A_INTERN a_real a_vector3_dot(a_vector3 const *lhs, a_vector3 const *rhs)
733{
734 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
735}
736
737A_INTERN void a_vector3_cross(a_vector3 const *lhs, a_vector3 const *rhs, a_vector3 *res)
738{
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;
742 res->x = x;
743 res->y = y;
744 res->z = z;
745}
746
747A_INTERN void a_vector3_outer(a_vector3 const *lhs, a_vector3 const *rhs, a_real res[9])
748{
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;
758}
759
760A_INTERN a_bool a_vector3_isver(a_vector3 const *lhs, a_vector3 const *rhs)
761{
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;
764}
765
766A_INTERN a_bool a_vector3_ispar(a_vector3 const *lhs, a_vector3 const *rhs)
767{
768 a_real x, y, z;
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; }
775 return 1;
776}
777
778A_INTERN void a_vector3_lerp(a_vector3 const *lhs, a_vector3 const *rhs, a_real val, a_vector3 *res)
779{
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;
783}
784
785#endif /* A_HAVE_INLINE */
786#if defined(LIBA_VECTOR3_C)
788#undef A_INTERN
789#define A_INTERN static A_INLINE
791#endif /* LIBA_VECTOR3_C */
792
794
795#endif /* a/vector3.h */
algorithm library
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