| 1 | #ifndef VECTOR_HPP_
|
|---|
| 2 | #define VECTOR_HPP_
|
|---|
| 3 |
|
|---|
| 4 | using namespace std;
|
|---|
| 5 |
|
|---|
| 6 | #include "helpers.hpp"
|
|---|
| 7 |
|
|---|
| 8 | #include <gsl/gsl_vector.h>
|
|---|
| 9 | #include <gsl/gsl_multimin.h>
|
|---|
| 10 |
|
|---|
| 11 | class Vector;
|
|---|
| 12 |
|
|---|
| 13 | /** Single vector.
|
|---|
| 14 | * basically, just a x[3] but with helpful functions
|
|---|
| 15 | */
|
|---|
| 16 | class Vector {
|
|---|
| 17 | public:
|
|---|
| 18 | double x[NDIM];
|
|---|
| 19 |
|
|---|
| 20 | Vector();
|
|---|
| 21 | Vector(double x1, double x2, double x3);
|
|---|
| 22 | ~Vector();
|
|---|
| 23 |
|
|---|
| 24 | double Distance(const Vector *y) const;
|
|---|
| 25 | double DistanceSquared(const Vector *y) const;
|
|---|
| 26 | double PeriodicDistance(const Vector *y, const double *cell_size) const;
|
|---|
| 27 | double PeriodicDistanceSquared(const Vector *y, const double *cell_size) const;
|
|---|
| 28 | double ScalarProduct(const Vector *y) const;
|
|---|
| 29 | double Norm() const;
|
|---|
| 30 | double NormSquared() const;
|
|---|
| 31 | double Angle(const Vector *y) const;
|
|---|
| 32 | bool IsZero() const;
|
|---|
| 33 | bool IsOne() const;
|
|---|
| 34 | bool IsNormalTo(const Vector *normal) const;
|
|---|
| 35 |
|
|---|
| 36 | void AddVector(const Vector *y);
|
|---|
| 37 | void SubtractVector(const Vector *y);
|
|---|
| 38 | void CopyVector(const Vector *y);
|
|---|
| 39 | void CopyVector(const Vector y);
|
|---|
| 40 | void RotateVector(const Vector *y, const double alpha);
|
|---|
| 41 | void VectorProduct(const Vector *y);
|
|---|
| 42 | void ProjectOntoPlane(const Vector *y);
|
|---|
| 43 | void ProjectIt(const Vector *y);
|
|---|
| 44 | Vector Projection(const Vector *y) const;
|
|---|
| 45 | void Zero();
|
|---|
| 46 | void One(double one);
|
|---|
| 47 | void Init(double x1, double x2, double x3);
|
|---|
| 48 | void Normalize();
|
|---|
| 49 | void Translate(const Vector *x);
|
|---|
| 50 | void Mirror(const Vector *x);
|
|---|
| 51 | void Scale(double **factor);
|
|---|
| 52 | void Scale(double *factor);
|
|---|
| 53 | void Scale(double factor);
|
|---|
| 54 | void MatrixMultiplication(double *M);
|
|---|
| 55 | double * InverseMatrix(double *A);
|
|---|
| 56 | void InverseMatrixMultiplication(double *M);
|
|---|
| 57 | void KeepPeriodic(ofstream *out, double *matrix);
|
|---|
| 58 | void LinearCombinationOfVectors(const Vector *x1, const Vector *x2, const Vector *x3, double *factors);
|
|---|
| 59 | double CutsPlaneAt(Vector *A, Vector *B, Vector *C);
|
|---|
| 60 | bool GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector *Origin, Vector *LineVector);
|
|---|
| 61 | bool GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *Normal = NULL);
|
|---|
| 62 | bool GetOneNormalVector(const Vector *x1);
|
|---|
| 63 | bool MakeNormalVector(const Vector *y1);
|
|---|
| 64 | bool MakeNormalVector(const Vector *y1, const Vector *y2);
|
|---|
| 65 | bool MakeNormalVector(const Vector *x1, const Vector *x2, const Vector *x3);
|
|---|
| 66 | bool SolveSystem(Vector *x1, Vector *x2, Vector *y, double alpha, double beta, double c);
|
|---|
| 67 | bool LSQdistance(Vector **vectors, int dim);
|
|---|
| 68 | void AskPosition(double *cell_size, bool check);
|
|---|
| 69 | bool Output(ofstream *out) const;
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | ostream & operator << (ostream& ost, const Vector &m);
|
|---|
| 73 | bool operator==(const Vector& a, const Vector& b);
|
|---|
| 74 | Vector& operator+=(Vector& a, const Vector& b);
|
|---|
| 75 | Vector& operator-=(Vector& a, const Vector& b);
|
|---|
| 76 | Vector& operator*=(Vector& a, const double m);
|
|---|
| 77 | Vector& operator*(const Vector& a, const double m);
|
|---|
| 78 | Vector& operator*(const double m, const Vector& a);
|
|---|
| 79 | Vector& operator+(const Vector& a, const Vector& b);
|
|---|
| 80 | Vector& operator-(const Vector& a, const Vector& b);
|
|---|
| 81 |
|
|---|
| 82 | // some algebraic matrix stuff
|
|---|
| 83 | #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]) //!< hard-coded determinant of a 3x3 matrix
|
|---|
| 84 | #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | #endif /*VECTOR_HPP_*/
|
|---|