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