v3.hpp

Go to the documentation of this file.
00001 /*
00002 **    TP 4ETI CPE Lyon
00003 **    Copyright (C) 2011 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef _V3_HPP_
00021 #define _V3_HPP_
00022 
00023 #include <string>
00024 #include <iostream>
00025 
00026 #include <exception_cpe.hpp>
00027 
00028 namespace cpe
00029 {
00030 
00032     class v3
00033     {
00034     public:
00035 
00036         // ********************************************* //
00037         // ********************************************* //
00038         //  CONSTRUCTORS
00039         // ********************************************* //
00040         // ********************************************* //
00041 
00043         v3();
00045         v3(const double& x,const double& y,const double& z);
00046 
00047         // ********************************************* //
00048         // ********************************************* //
00049         //  Get/set
00050         // ********************************************* //
00051         // ********************************************* //
00052 
00054         const double& x() const;
00056         double& x();
00058         const double& y() const;
00060         double& y();
00062         const double& z() const;
00064         double& z();
00065 
00067         const double& operator[](const size_t& k) const;
00069         double& operator[](const size_t& k);
00071         const double& operator()(const size_t& k) const;
00073         double& operator()(const size_t& k);
00074 
00076         void set_zero();
00077 
00078 
00079         // ********************************************* //
00080         // ********************************************* //
00081         //  Math operation
00082         // ********************************************* //
00083         // ********************************************* //
00084 
00086         double dot(const v3& p) const;
00087 
00089         double norm() const;
00091         double norm2() const;
00093         v3 normalized() const;
00094 
00096         v3 cross(const v3& p) const;
00097 
00098 
00099 
00100 
00101         // ********************************************* //
00102         // ********************************************* //
00103         //  Operator +-*/
00104         // ********************************************* //
00105         // ********************************************* //
00106 
00108         friend v3 operator+(const v3& p1,const v3& p2);
00110         friend v3 operator+(const double& s,const v3& p);
00112         friend v3 operator+(const v3& p,const double& s);
00113 
00115         friend v3 operator-(const v3& p1,const v3& p2);
00117         friend v3 operator-(const double& s,const v3& p);
00119         friend v3 operator-(const v3& p,const double& s);
00120 
00122         friend v3 operator*(const double& s,const v3& p);
00124         friend v3 operator*(const v3& p,const double& s);
00126         friend v3 operator/(const v3& p,const double& s);
00127 
00129         v3& operator+=(const v3& p);
00131         v3& operator+=(const double& s);
00133         v3& operator-=(const v3& p);
00135         v3& operator-=(const double& s);
00137         v3& operator*=(const double& s);
00139         v3& operator/=(const double& s);
00140 
00142         v3 operator-() const;
00143 
00147         v3 product_compontentwise(const v3& p) const;
00152         v3& product_compontentwise_internal(const v3& p);
00154         void scale(const double& sx,const double& sy,const double& sz);
00155 
00156 
00157         // ********************************************* //
00158         // ********************************************* //
00159         //  Output
00160         // ********************************************* //
00161         // ********************************************* //
00162 
00164         std::string to_string() const;
00165 
00167         friend std::ostream& operator<<(std::ostream& stream,const v3& p);
00168 
00169     private:
00170 
00171 
00172         // ********************************************* //
00173         // ********************************************* //
00174         //  Internal parameters
00175         // ********************************************* //
00176         // ********************************************* //
00177 
00179         double internal_x;
00181         double internal_y;
00183         double internal_z;
00184 
00185 
00186         // ********************************************* //
00187         // ********************************************* //
00188         //  Helper
00189         // ********************************************* //
00190         // ********************************************* //
00191 
00193         void assert_size(const size_t& k) const;
00194 
00195     };
00196 
00198     class exception_v3 : public exception_cpe
00199     {
00200     public:
00201 
00203         exception_v3():exception_cpe(){}
00205         exception_v3(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
00206     };
00207 
00208 }
00209 
00210 
00211 
00212 #endif
Generated on Mon Apr 18 20:43:30 2011 by  doxygen 1.6.3