Vector4.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: 4 tuple
00018  * Author: Nate Koenig
00019  * Date: 19 Aug 2008
00020  */
00021 
00022 #ifndef VECTOR4_HH
00023 #define VECTOR4_HH
00024 
00025 #include <iostream>
00026 #include <fstream>
00027 #include "math/Matrix4.hh"
00028 
00029 namespace gazebo
00030 {
00031     namespace math
00032   {
00035     
00037     class Vector4
00038     {
00040       public: Vector4();
00041     
00043       public: Vector4( const double &x, const double &y, const double &z, const double &w );
00044     
00046       public: Vector4( const Vector4 &pt );
00047     
00049       public: virtual ~Vector4();
00050     
00052       public: double Distance( const Vector4 &pt ) const;
00053     
00055       public: double GetLength() const;
00056     
00058       public: double GetSquaredLength() const;
00059     
00061       public: void Normalize();
00062     
00064       public: void Set(double x = 0, double y =0 , double z = 0, double w=0);
00065     
00067       public: const Vector4 &operator=( const Vector4 &pt );
00068     
00070       public: const Vector4 &operator=( double value );
00071     
00073       public: Vector4 operator+( const Vector4 &pt ) const;
00074     
00076       public: const Vector4 &operator+=( const Vector4 &pt );
00077     
00079       public: Vector4 operator-( const Vector4 &pt ) const;
00080     
00082       public: const Vector4 &operator-=( const Vector4 &pt );
00083     
00085       public: const Vector4 operator/( const Vector4 &pt ) const;
00086     
00088       public: const Vector4 &operator/=( const Vector4 &pt );
00089     
00091       public: const Vector4 operator/( double v ) const;
00092     
00094       public: const Vector4 &operator/=( double v );
00095     
00097       public: const Vector4 operator*( const Vector4 &pt ) const;
00098 
00099       public: const Vector4 operator*( const Matrix4 &_m ) const;
00100     
00102       public: const Vector4 &operator*=( const Vector4 &pt );
00103     
00105       public: const Vector4 operator*( double v ) const;
00106     
00108       public: const Vector4 &operator*=( double v );
00109     
00111       public: bool operator==( const Vector4 &pt ) const;
00112     
00114       public: bool operator!=( const Vector4 &pt ) const;
00115     
00117       public: bool IsFinite() const;
00118     
00120       public: double operator[](unsigned int index) const;
00121     
00123       public: double x;
00124     
00126       public: double y;
00127     
00129       public: double z;
00130     
00132       public: double w;
00133     
00138       public: friend std::ostream &operator<<( std::ostream &out, const gazebo::math::Vector4 &pt )
00139       {
00140         out << pt.x << " " << pt.y << " " << pt.z << " " << pt.w;
00141     
00142         return out;
00143       }
00144     
00149       public: friend std::istream &operator>>( std::istream &in, gazebo::math::Vector4 &pt )
00150       {
00151         // Skip white spaces
00152         in.setf( std::ios_base::skipws );
00153         in >> pt.x >> pt.y >> pt.z >> pt.w;
00154         return in;
00155       }
00156     };
00158   }
00159 }
00160 #endif