- Main Page
- Classes
- Files

- File List
- File Members

# src/vectorMath/tray.h

Go to the documentation of this file.

    00001 #ifndef tray_h
    00002 #define tray_h
    00003
    00004 #include <iostream>
    00005 #include "mathex.h"
    00006 #include "tvector.h"
    00007
    00008 using std::ostream;
    00009 using std::istream;
    00010
    00012 //  Class Line
    00014
    00015 class TRay
    00016 {
    00017     private:
    00018         TVector _P1; // Any point on the line
    00019         TVector _V; // Direction of the line
    00020
    00021         // Input and output
    00022         ostream &write(ostream &out) const;
    00023         istream &read(istream &in);
    00024
    00025       // Close
    00026
    00027     public:
    00028         // Constructors
    00029         TRay() {}
    00030
    00031         // Line betwen two points OR point and a direction
    00032         TRay(const TVector &point1, const TVector &point2);
    00033
    00034         // Adjacent points on both lines
    00035         bool adjacentPoints(const TRay &ray, TVector &point1, TVector &point2) const;
    00036
    00037         // Unary operator
    00038         static TRay &invert(const TRay &r, TRay &result) { result._P1 = r._P1; TVector::invert(r._V, result._V); return result; }
    00039         TRay operator-() const { TRay tmp; return invert(*this, tmp); }
    00040
    00041         // Selectors
    00042         TVector P() const { return _P1; }
    00043         TVector V() const { return _V; }
    00044         int isValid() const { return V().isUnit() && P().isValid(); }
    00045
    00046         // Distances
    00047         double dist(const TRay &ray) const;
    00048         double dist(const TVector &point) const;
    00049
    00050         // Streaming
    00051         friend ostream &operator<<(ostream &out, const TRay &o) { return o.write(out); }
    00052         friend istream &operator>>(istream &in, TRay &o) { return o.read(in); }
    00053 };
    00054 #endif