Back to index

nux  3.0.0
Line3D.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef LINE3D_H
00024 #define LINE3D_H
00025 
00026 #include "Vector3.h"
00027 
00028 namespace nux
00029 {
00030 
00031   template<typename T>
00032   class Line3D
00033   {
00034   public:
00035     Line3D();
00036     ~Line3D();
00037     Line3D (const Line3D &line);
00038     Line3D (T lx_start, T ly_start, T lz_start,
00039             T lx_end, T ly_end, T lz_end);
00040     Line3D (const Vector3 &pt, Vector3 v);
00041 
00042     const Line3D<T>& operator = (const Line3D<T>&);
00043     bool operator == (const Line3D<T>& line) const;
00044 
00045     float Length() const;
00046     const Vec3<T> GetDirectionVector() const;
00047     const Vec3<T> GetStartPoint() const;
00048     const Vec3<T> GetEndPoint() const;
00049 
00050   private:
00051     T x_start, y_start, z_start;
00052     T x_end, y_end, z_end;
00053 
00054   };
00055 
00056   template<typename T>
00057   Line3D<T>::Line3D()
00058   {
00059     x_start = y_start = z_start = x_end = y_end = z_end = 0;
00060   }
00061 
00062   template<typename T>
00063   Line3D<T>::~Line3D()
00064   {
00065 
00066   }
00067 
00068   template<typename T>
00069   Line3D<T>::Line3D (const Line3D &line)
00070   {
00071     x_start = line.x_start;
00072     x_end   = line.x_end;
00073     y_start = line.y_start;
00074     y_end   = line.y_end;
00075     z_start = line.z_start;
00076     z_end   = line.z_end;
00077   }
00078 
00079   template<typename T>
00080   Line3D<T>::Line3D (T lx_start, T ly_start, T lz_start,
00081                      T lx_end, T ly_end, T lz_end)
00082   {
00083     x_start = lx_start;
00084     x_end   = lx_end;
00085     y_start = ly_start;
00086     y_end   = ly_end;
00087     z_start = lz_start;
00088     z_end   = lz_end;
00089   }
00090 
00091   template<typename T>
00092   Line3D<T>::Line3D (const Vector3 &pt, Vector3 v)
00093   {
00094     x_start = pt.x;
00095     y_start = pt.y;
00096     z_start = pt.z;
00097 
00098     x_end   = x_start + v.x;
00099     y_end   = y_start + v.y;
00100     z_end   = y_start + v.z;
00101   }
00102 
00103   template<typename T>
00104   const Line3D<T>& Line3D<T>::operator = (const Line3D<T>& Line)
00105   {
00106     x_start = Line.x_start;
00107     y_start = Line.y_start;
00108     z_start = Line.z_start;
00109     x_end = Line.x_end;
00110     y_end = Line.y_end;
00111     z_end = Line.z_end;
00112 
00113   }
00114 
00115   template<typename T>
00116   bool Line3D<T>::operator == (const Line3D &line) const
00117   {
00118     if ( (x_start  == line.x_start) &&
00119          (y_start == line.y_start) &&
00120          (z_start == line.z_start) &&
00121          (x_end   == line.x_end)   &&
00122          (y_end   == line.y_end)   &&
00123          (z_end   == line.z_end) )
00124     {
00125       return true;
00126     }
00127     else
00128     {
00129       return false;
00130     }
00131   }
00132 
00133   template<typename T>
00134   float Line3D<T>::Length() const
00135   {
00136     float l;
00137     l = (float) std::sqrt ( (x_end - x_start) * (x_end - x_start) +
00138                             (y_end - y_start) * (y_end - y_start) +
00139                             (z_end - z_start) * (z_end - z_start) );
00140 
00141     return l;
00142   }
00143 
00144   template<typename T>
00145   const Vec3<T> Line3D<T>::GetDirectionVector() const
00146   {
00147     return Vec3<T> (x_start - x_end, y_start - y_end, z_start - z_end);
00148   }
00149 
00150   template<typename T>
00151   const Vec3<T> Line3D<T>::GetStartPoint() const
00152   {
00153     Vec3<T> p (x_start, y_start, z_start);
00154     return p;
00155   }
00156 
00157   template<typename T>
00158   const Vec3<T> Line3D<T>::GetEndPoint() const
00159   {
00160     Vec3<T> p (x_end, y_end, z_end);
00161     return p;
00162   }
00163 
00164 }
00165 
00166 #endif // LINE3D_H