| 1 | /* | 
|---|
| 2 | * Line.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Apr 30, 2010 | 
|---|
| 5 | *      Author: crueger | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef LINE_HPP_ | 
|---|
| 9 | #define LINE_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | #include "LinearAlgebra/Space.hpp" | 
|---|
| 18 |  | 
|---|
| 19 | #include <iosfwd> | 
|---|
| 20 | #include <memory> | 
|---|
| 21 | #include <vector> | 
|---|
| 22 |  | 
|---|
| 23 | class Vector; | 
|---|
| 24 | class Plane; | 
|---|
| 25 | class LinePoint; | 
|---|
| 26 |  | 
|---|
| 27 | class Line : public Space | 
|---|
| 28 | { | 
|---|
| 29 | friend bool operator==(const Line&,const Line&); | 
|---|
| 30 | friend class LinePoint; | 
|---|
| 31 | public: | 
|---|
| 32 | Line(const Vector &_origin, const Vector &_direction); | 
|---|
| 33 | Line(const Line& _src); | 
|---|
| 34 | virtual ~Line(); | 
|---|
| 35 |  | 
|---|
| 36 | Line &operator=(const Line& rhs); | 
|---|
| 37 |  | 
|---|
| 38 | virtual double distance(const Vector &point) const; | 
|---|
| 39 | virtual Vector getClosestPoint(const Vector &point) const; | 
|---|
| 40 |  | 
|---|
| 41 | Vector getDirection() const; | 
|---|
| 42 | Vector getOrigin() const; | 
|---|
| 43 |  | 
|---|
| 44 | std::vector<Vector> getPointsOnLine() const; | 
|---|
| 45 |  | 
|---|
| 46 | Vector getIntersection(const Line& otherLine) const; | 
|---|
| 47 |  | 
|---|
| 48 | Vector rotateVector(const Vector &rhs, double alpha) const; | 
|---|
| 49 | Line rotateLine(const Line &rhs, double alpha) const; | 
|---|
| 50 | Plane rotatePlane(const Plane &rhs, double alpha) const; | 
|---|
| 51 |  | 
|---|
| 52 | Plane getOrthogonalPlane(const Vector &origin) const; | 
|---|
| 53 |  | 
|---|
| 54 | std::vector<Vector> getSphereIntersections() const; | 
|---|
| 55 |  | 
|---|
| 56 | LinePoint getLinePoint(const Vector&) const; | 
|---|
| 57 | LinePoint posEndpoint() const; | 
|---|
| 58 | LinePoint negEndpoint() const; | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | private: | 
|---|
| 63 | std::auto_ptr<Vector> origin; | 
|---|
| 64 | std::auto_ptr<Vector> direction; | 
|---|
| 65 | }; | 
|---|
| 66 |  | 
|---|
| 67 | bool operator==(const Line&,const Line&); | 
|---|
| 68 |  | 
|---|
| 69 | std::ostream & operator << (std::ostream& ost, const Line &m); | 
|---|
| 70 |  | 
|---|
| 71 | /** | 
|---|
| 72 | * Named constructor to make a line through two points | 
|---|
| 73 | */ | 
|---|
| 74 | Line makeLineThrough(const Vector &x1, const Vector &x2); | 
|---|
| 75 |  | 
|---|
| 76 | /** | 
|---|
| 77 | * Class for representing points on a line | 
|---|
| 78 | * These objects allow comparison of points on the same line as well as specifying the | 
|---|
| 79 | * infinite "endpoints" of a line. | 
|---|
| 80 | */ | 
|---|
| 81 | class LinePoint{ | 
|---|
| 82 | friend class Line; | 
|---|
| 83 | friend bool operator==(const LinePoint&, const LinePoint&); | 
|---|
| 84 | friend bool operator<(const LinePoint&, const LinePoint&); | 
|---|
| 85 | public: | 
|---|
| 86 | LinePoint(const LinePoint&); | 
|---|
| 87 | LinePoint& operator=(const LinePoint&); | 
|---|
| 88 | Vector getPoint() const; | 
|---|
| 89 | Line getLine() const; | 
|---|
| 90 | bool isInfinite() const; | 
|---|
| 91 | bool isPosInfinity() const; | 
|---|
| 92 | bool isNegInfinity() const; | 
|---|
| 93 |  | 
|---|
| 94 | private: | 
|---|
| 95 | LinePoint(const Line&,double); | 
|---|
| 96 | Line line; | 
|---|
| 97 | double param; | 
|---|
| 98 | }; | 
|---|
| 99 |  | 
|---|
| 100 | bool operator==(const LinePoint&, const LinePoint&); | 
|---|
| 101 | bool operator<(const LinePoint&, const LinePoint&); | 
|---|
| 102 |  | 
|---|
| 103 | inline bool operator!= (const LinePoint& x, const LinePoint& y) { return !(x==y); } | 
|---|
| 104 | inline bool operator>  (const LinePoint& x, const LinePoint& y) { return y<x; } | 
|---|
| 105 | inline bool operator<= (const LinePoint& x, const LinePoint& y) { return !(y<x); } | 
|---|
| 106 | inline bool operator>= (const LinePoint& x, const LinePoint& y) { return !(x<y); } | 
|---|
| 107 |  | 
|---|
| 108 |  | 
|---|
| 109 | #endif /* LINE_HPP_ */ | 
|---|