v3.hpp

Go to the documentation of this file.
00001 /*
00002 **    TP 4ETI CPE Lyon
00003 **    Copyright (C) 2012 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 namespace cpe
00027 {
00028 
00030     class v3
00031     {
00032     public:
00033 
00034         // ********************************************* //
00035         // ********************************************* //
00036         //  CONSTRUCTORS
00037         // ********************************************* //
00038         // ********************************************* //
00039 
00041         v3();
00043         v3(const double& x,const double& y,const double& z);
00044 
00045         // ********************************************* //
00046         // ********************************************* //
00047         //  Get/set
00048         // ********************************************* //
00049         // ********************************************* //
00050 
00052         const double& x() const;
00054         double& x();
00056         const double& y() const;
00058         double& y();
00060         const double& z() const;
00062         double& z();
00063 
00065         const double& operator[](const size_t& k) const;
00067         double& operator[](const size_t& k);
00069         const double& operator()(const size_t& k) const;
00071         double& operator()(const size_t& k);
00072 
00074         void set_zero();
00075 
00076 
00077         // ********************************************* //
00078         // ********************************************* //
00079         //  Math operation
00080         // ********************************************* //
00081         // ********************************************* //
00082 
00084         double dot(const v3& p) const;
00085 
00087         double norm() const;
00089         double norm2() const;
00091         v3 normalized() const;
00092 
00094         v3 cross(const v3& p) const;
00095 
00096 
00097 
00098 
00099         // ********************************************* //
00100         // ********************************************* //
00101         //  Operator +-*/
00102         // ********************************************* //
00103         // ********************************************* //
00104 
00106         friend v3 operator+(const v3& p1,const v3& p2);
00108         friend v3 operator+(const double& s,const v3& p);
00110         friend v3 operator+(const v3& p,const double& s);
00111 
00113         friend v3 operator-(const v3& p1,const v3& p2);
00115         friend v3 operator-(const double& s,const v3& p);
00117         friend v3 operator-(const v3& p,const double& s);
00118 
00120         friend v3 operator*(const double& s,const v3& p);
00122         friend v3 operator*(const v3& p,const double& s);
00124         friend v3 operator/(const v3& p,const double& s);
00125 
00127         v3& operator+=(const v3& p);
00129         v3& operator+=(const double& s);
00131         v3& operator-=(const v3& p);
00133         v3& operator-=(const double& s);
00135         v3& operator*=(const double& s);
00137         v3& operator/=(const double& s);
00138 
00140         v3 operator-() const;
00141 
00145         v3 product_compontentwise(const v3& p) const;
00150         v3& product_compontentwise_internal(const v3& p);
00151 
00152 
00153         // ********************************************* //
00154         // ********************************************* //
00155         //  Output
00156         // ********************************************* //
00157         // ********************************************* //
00158 
00160         std::string to_string() const;
00161 
00163         friend std::ostream& operator<<(std::ostream& stream,const v3& p);
00164 
00165     private:
00166 
00167 
00168         // ********************************************* //
00169         // ********************************************* //
00170         //  Internal parameters
00171         // ********************************************* //
00172         // ********************************************* //
00173 
00175         double internal_x;
00177         double internal_y;
00179         double internal_z;
00180 
00181 
00182         // ********************************************* //
00183         // ********************************************* //
00184         //  Helper
00185         // ********************************************* //
00186         // ********************************************* //
00187 
00189         void assert_size(const size_t& k) const throw(std::exception);
00190 
00191     };
00192 
00193 }
00194 
00195 
00196 
00197 #endif
Generated on Mon Feb 27 17:40:02 2012 by  doxygen 1.6.3