Vector3.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: The world; all models are collected here 00018 * Author: Nate Koenig 00019 * Date: 3 Apr 2007 00020 */ 00021 00022 #ifndef VECTOR3_HH 00023 #define VECTOR3_HH 00024 00025 #include <math.h> 00026 #include <iostream> 00027 #include <fstream> 00028 00029 namespace gazebo 00030 { 00031 namespace math 00032 { 00035 00037 class Vector3 00038 { 00040 public: Vector3(); 00041 00043 public: Vector3( const double &x, const double &y, const double &z ); 00044 00046 public: Vector3( const Vector3 &pt ); 00047 00049 public: virtual ~Vector3(); 00050 00052 public: double Distance( const Vector3 &pt ) const; 00053 00055 public: double GetLength() const; 00056 00058 public: double GetSquaredLength() const; 00059 00061 public: void Normalize(); 00062 00064 public: Vector3 Round(); 00065 00067 public: Vector3 GetRounded() const; 00068 00070 public: inline void Set(double x = 0, double y =0 , double z = 0) 00071 { 00072 this->x = x; 00073 this->y = y; 00074 this->z = z; 00075 } 00076 00078 public: Vector3 GetCrossProd(const Vector3 &pt) const; 00079 00081 public: double GetDotProd(const Vector3 &pt) const; 00082 00084 public: Vector3 GetAbs() const; 00085 00087 public: Vector3 GetPerpendicular() const; 00088 00090 public: static Vector3 GetNormal(const Vector3 &v1, const Vector3 &v2, 00091 const Vector3 &v3); 00092 00095 public: double GetDistToPlane(const Vector3 &_dir, 00096 const Vector3 &_planeNormal, 00097 double _d) const; 00099 public: double GetDistToLine(const Vector3 &_pt1, const Vector3 &_pt2); 00100 00103 public: void SetToMax(const Vector3 & v); 00104 00107 public: void SetToMin(const Vector3 & v); 00108 00110 public: const Vector3 &operator=( const Vector3 &pt ); 00111 00113 public: const Vector3 &operator=( double value ); 00114 00116 public: Vector3 operator+( const Vector3 &pt ) const; 00117 00119 public: const Vector3 &operator+=( const Vector3 &pt ); 00120 00122 public: inline Vector3 operator-( const Vector3 &pt ) const 00123 { 00124 return Vector3(this->x - pt.x, this->y - pt.y, this->z - pt.z); 00125 } 00126 00128 public: const Vector3 &operator-=( const Vector3 &pt ); 00129 00131 public: const Vector3 operator/( const Vector3 &pt ) const; 00132 00134 public: const Vector3 &operator/=( const Vector3 &pt ); 00135 00137 public: const Vector3 operator/( double v ) const; 00138 00140 public: const Vector3 &operator/=( double v ); 00141 00143 public: const Vector3 operator*( const Vector3 &pt ) const; 00144 00146 public: const Vector3 &operator*=( const Vector3 &pt ); 00147 00149 public: const Vector3 operator*( double v ) const; 00150 00152 public: const Vector3 &operator*=( double v ); 00153 00155 public: bool operator==( const Vector3 &pt ) const; 00156 00158 public: bool operator!=( const Vector3 &pt ) const; 00159 00161 public: bool IsFinite() const; 00162 00164 public: inline void Correct() 00165 { 00166 if (!finite(this->x)) 00167 this->x = 0; 00168 if (!finite(this->y)) 00169 this->y = 0; 00170 if (!finite(this->z)) 00171 this->z = 0; 00172 } 00173 00175 public: double operator[](unsigned int index) const; 00176 00178 public: void Round(int _precision); 00179 00181 public: bool Equal( const Vector3 &_v ) const; 00182 00184 public: double x; 00185 00187 public: double y; 00188 00190 public: double z; 00191 00196 public: friend std::ostream &operator<<( std::ostream &out, const gazebo::math::Vector3 &pt ) 00197 { 00198 out << pt.x << " " << pt.y << " " << pt.z; 00199 00200 return out; 00201 } 00202 00207 public: friend std::istream &operator>>( std::istream &in, gazebo::math::Vector3 &pt ) 00208 { 00209 // Skip white spaces 00210 in.setf( std::ios_base::skipws ); 00211 in >> pt.x >> pt.y >> pt.z; 00212 return in; 00213 } 00214 }; 00215 00217 } 00218 00219 } 00220 #endif

1.7.5.1