arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

ray2.h

Go to the documentation of this file.
00001 /*
00002 * $Id: ray2.h,v 1.2 2003/09/15 17:15:31 jmk Exp $
00003 */
00004 ///////////////////////////////////////////////////////////////////////////
00005 //              _____________  ______________________    __   __  _____
00006 //             /  ________  |  |   ___   ________   /   |  \ /  \   |
00007 //            |  |       |  |_ |  |_ |  |       /  /    \__  |      |
00008 //            |  |  ___  |  || |  || |  |      /  /        | |      |
00009 //            |  | |   \ |  || |  || |  |     /  /      \__/ \__/ __|__
00010 //            |  | |_@  ||  || |  || |  |    /  /          Institute
00011 //            |  |___/  ||  ||_|  || |  |   /  /_____________________
00012 //             \_______/  \______/ | |__|  /___________________________
00013 //                        |  |__|  |
00014 //                         \______/
00015 //                    University of Utah       
00016 //                           2002
00017 ///////////////////////////////////////////////////////////////////////////
00018 
00019 
00020 #ifndef __GUTZ_RAY_2_H
00021 #define __GUTZ_RAY_2_H
00022 
00023 #include "vec2.h"
00024 // intersect2D<>() comes from here:
00025 #include "mathExt.h"
00026 
00027 namespace gutz {
00028 
00029 template< class T >
00030 class ray2 {
00031 public:
00032    ray2() : p(vec2<T>(0,0)), d(vec2<T>(0,1)) {}
00033    ray2(const vec2<T> &pos, const vec2<T> &dir) : p(pos), d(dir) {}
00034    ray2(const ray2 &r) : d(r.d), p(r.p) {}
00035 
00036    inline
00037    ray2 &operator=(const ray2 &r) { d=r.d; p=r.p; return *this; }
00038 
00039    ~ray2() {}
00040 
00041    /// get a position on ray given t
00042    inline
00043    vec2<T> pos(const T &t) const
00044    { return vec2<T>(p.x + d.x * t, p.y + d.y * t); }
00045 
00046    /// intersect for t value
00047    inline
00048    T intersect(const ray2 &r) const
00049    {
00050       return intersect2D<T>(p.x,   p.y,   d.x,   d.y, 
00051                             r.p.x, r.p.y, r.d.x, r.d.y);
00052    }
00053 
00054    /// intersect for a position
00055    inline
00056    vec2<T> intersectPos(const ray2 &r) const
00057    { return pos(intersect(r)); }
00058 
00059 
00060 public:
00061    vec2<T>  p;  /// position 
00062    vec2<T>  d;  /// direction
00063 
00064 };
00065 
00066 }
00067 
00068 
00069 #endif
00070 

Send questions, comments, and bug reports to:
jmk