[342f33f] | 1 | #ifndef VECTOR_HPP_
|
---|
| 2 | #define VECTOR_HPP_
|
---|
| 3 |
|
---|
[357fba] | 4 | using namespace std;
|
---|
| 5 |
|
---|
[f66195] | 6 | /*********************************************** includes ***********************************/
|
---|
| 7 |
|
---|
| 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
[357fba] | 12 |
|
---|
[986ed3] | 13 | #include <iosfwd>
|
---|
[54a746] | 14 |
|
---|
[1bd79e] | 15 | #include <memory>
|
---|
[45ef76] | 16 | #include <vector>
|
---|
[1bd79e] | 17 |
|
---|
[f66195] | 18 | #include "defs.hpp"
|
---|
[57f243] | 19 | #include "LinearAlgebra/Space.hpp"
|
---|
[f66195] | 20 |
|
---|
| 21 | /********************************************** declarations *******************************/
|
---|
[7d96c6] | 22 |
|
---|
[45ef76] | 23 | class Vector;
|
---|
[325390] | 24 | class Matrix;
|
---|
[ce3d2b] | 25 | struct VectorContent;
|
---|
[45ef76] | 26 |
|
---|
| 27 | typedef std::vector<Vector> pointset;
|
---|
| 28 |
|
---|
[342f33f] | 29 | /** Single vector.
|
---|
| 30 | * basically, just a x[3] but with helpful functions
|
---|
| 31 | */
|
---|
[1513a74] | 32 | class Vector : public Space{
|
---|
[325390] | 33 | friend Vector operator*(const Matrix&,const Vector&);
|
---|
[8e17d6] | 34 | friend class Matrix;
|
---|
[1bd79e] | 35 | public:
|
---|
[042f82] | 36 | Vector();
|
---|
[fb73b8] | 37 | Vector(const double x1, const double x2, const double x3);
|
---|
[d74077] | 38 | Vector(const double x[3]);
|
---|
[0a4f7f] | 39 | Vector(const Vector& src);
|
---|
[72e7fa] | 40 | virtual ~Vector();
|
---|
| 41 |
|
---|
[1bd79e] | 42 | // Method implemented by forwarding to the Representation
|
---|
| 43 |
|
---|
[753f02] | 44 | double DistanceSquared(const Vector &y) const;
|
---|
[d4c9ae] | 45 | double DistanceToSpace(const Space& space) const;
|
---|
[753f02] | 46 | double ScalarProduct(const Vector &y) const;
|
---|
| 47 | double Angle(const Vector &y) const;
|
---|
[54a746] | 48 | bool IsZero() const;
|
---|
| 49 | bool IsOne() const;
|
---|
[753f02] | 50 | bool IsNormalTo(const Vector &normal) const;
|
---|
| 51 | bool IsEqualTo(const Vector &a) const;
|
---|
| 52 |
|
---|
| 53 | void AddVector(const Vector &y);
|
---|
| 54 | void SubtractVector(const Vector &y);
|
---|
| 55 | void VectorProduct(const Vector &y);
|
---|
| 56 | void ProjectOntoPlane(const Vector &y);
|
---|
| 57 | void ProjectIt(const Vector &y);
|
---|
| 58 | Vector Projection(const Vector &y) const;
|
---|
| 59 | void ScaleAll(const double *factor);
|
---|
[b5bf84] | 60 | void ScaleAll(const Vector &factor);
|
---|
[776b64] | 61 | void Scale(const double factor);
|
---|
[753f02] | 62 | bool GetOneNormalVector(const Vector &x1);
|
---|
| 63 | bool MakeNormalTo(const Vector &y1);
|
---|
[45ef76] | 64 | std::pair<Vector,Vector> partition(const Vector&) const;
|
---|
| 65 | std::pair<pointset,Vector> partition(const pointset&) const;
|
---|
[a439e5] | 66 | size_t GreatestComponent() const;
|
---|
| 67 | size_t SmallestComponent() const;
|
---|
[2ededc2] | 68 |
|
---|
[0a4f7f] | 69 | // Accessors ussually come in pairs... and sometimes even more than that
|
---|
[753f02] | 70 | double& operator[](size_t i);
|
---|
| 71 | const double& operator[](size_t i) const;
|
---|
[1bd79e] | 72 | double& at(size_t i);
|
---|
| 73 | const double& at(size_t i) const;
|
---|
[0a4f7f] | 74 |
|
---|
| 75 | // Assignment operator
|
---|
[753f02] | 76 | Vector &operator=(const Vector& src);
|
---|
[0a4f7f] | 77 |
|
---|
| 78 | // Access to internal structure
|
---|
[ce3d2b] | 79 | VectorContent* get();
|
---|
[72e7fa] | 80 |
|
---|
[1bd79e] | 81 | // Methods that are derived directly from other methods
|
---|
| 82 | double Norm() const;
|
---|
| 83 | double NormSquared() const;
|
---|
| 84 | void Normalize();
|
---|
| 85 | void Zero();
|
---|
| 86 | void One(const double one);
|
---|
| 87 | void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);
|
---|
| 88 |
|
---|
[72e7fa] | 89 | // operators for mathematical operations
|
---|
| 90 | bool operator==(const Vector& b) const;
|
---|
[fa5a6a] | 91 | bool operator!=(const Vector& b) const;
|
---|
[72e7fa] | 92 | const Vector& operator+=(const Vector& b);
|
---|
| 93 | const Vector& operator-=(const Vector& b);
|
---|
| 94 | Vector const operator+(const Vector& b) const;
|
---|
| 95 | Vector const operator-(const Vector& b) const;
|
---|
[0a4f7f] | 96 |
|
---|
[1513a74] | 97 | // Methods inherited from Space
|
---|
| 98 | virtual double distance(const Vector &point) const;
|
---|
| 99 | virtual Vector getClosestPoint(const Vector &point) const;
|
---|
| 100 |
|
---|
[1bd79e] | 101 | protected:
|
---|
| 102 |
|
---|
[0a4f7f] | 103 | private:
|
---|
[ce3d2b] | 104 | Vector(VectorContent *);
|
---|
| 105 | VectorContent *content;
|
---|
[0a4f7f] | 106 |
|
---|
[342f33f] | 107 | };
|
---|
| 108 |
|
---|
[005e18] | 109 | // some commonly used and fixed vectors
|
---|
| 110 | const extern Vector zeroVec;
|
---|
| 111 | const extern Vector e1;
|
---|
| 112 | const extern Vector e2;
|
---|
| 113 | const extern Vector e3;
|
---|
| 114 |
|
---|
[9c20aa] | 115 | ostream & operator << (ostream& ost, const Vector &m);
|
---|
[b84d5d] | 116 | const Vector& operator*=(Vector& a, const double m);
|
---|
| 117 | Vector const operator*(const Vector& a, const double m);
|
---|
| 118 | Vector const operator*(const double m, const Vector& a);
|
---|
[342f33f] | 119 |
|
---|
| 120 | #endif /*VECTOR_HPP_*/
|
---|