00001 /*************************************************************************** 00002 * Copyright (C) 2003-2004 by Raphael Langerhorst * 00003 * raphael-langerhorst@gmx.at * 00004 * * 00005 * Copyright (C) 2004 Gerald Degeneve <gerald.degeneve@gmx.at> * 00006 * * 00007 * Permission is hereby granted, free of charge, to any person obtaining * 00008 * a copy of this software and associated documentation files (the * 00009 * "Software"), to deal in the Software without restriction, including * 00010 * without limitation the rights to use, copy, modify, merge, publish, * 00011 * distribute, sublicense, and/or sell copies of the Software, and to * 00012 * permit persons to whom the Software is furnished to do so, subject to * 00013 * the following conditions: * 00014 * * 00015 * The above copyright notice and this permission notice shall be * 00016 * included in all copies or substantial portions of the Software. * 00017 * * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * 00019 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 00020 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* 00021 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * 00022 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * 00023 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * 00024 * OTHER DEALINGS IN THE SOFTWARE. * 00025 ***************************************************************************/ 00026 00027 #ifndef GVECTOR3H 00028 #define GVECTOR3H 00029 00030 class QString; 00031 00032 namespace GCS 00033 { 00034 00043 class GVector3 00044 { 00045 public: 00046 00050 union 00051 { 00055 struct 00056 { 00060 double x; 00064 double y; 00068 double z; 00069 }; 00070 00074 struct 00075 { 00079 double u; 00083 double v; 00087 double w; 00088 }; 00089 00093 double c[3]; 00094 00095 }; 00096 00097 public: 00098 00102 GVector3(); 00103 00107 GVector3(const double d); 00108 00112 GVector3(const double x, const double y, const double z); 00113 00118 GVector3(const double* component); 00119 00123 GVector3(const GVector3& original); 00124 00129 GVector3(const QString& values); 00130 00134 double length() const; 00135 00139 double lengthsq() const; 00140 00144 GVector3& reset(); 00145 00149 GVector3& set(double x, double y, double z); 00150 00154 GVector3& set(const GVector3& original); 00155 00161 GVector3& normalize(); 00162 00166 GVector3& scaleXYZ(const GVector3& scale); 00167 00173 GVector3& scaleXYZ(double x, double y, double z); 00174 00178 GVector3& add(const GVector3& right); 00179 00183 GVector3& sub(const GVector3& right); 00184 00188 GVector3& mul(double scalar); 00189 00195 double dot(const GVector3& right) const; 00196 00203 GVector3 cross(const GVector3& right) const; 00204 00205 00209 operator double* (); 00210 00214 GVector3& operator = (const GVector3& original); 00215 00220 GVector3 operator + (const GVector3& right) const; 00221 00226 GVector3 operator - (const GVector3& right) const; 00227 00232 GVector3 operator * (double factor) const; 00233 00237 GVector3& operator += (const GVector3& right); 00238 00242 GVector3& operator -= (const GVector3& right); 00243 00248 bool operator == (const GVector3& comp) const; 00249 00250 // geometric operations: 00251 00257 double distanceTo(const GVector3& p) const; 00258 00266 double angleTo(const GVector3& v) const; 00267 00273 GVector3& turnAroundAxis(const GVector3& axis, double angle_rad); 00274 00280 GVector3& projectTo(const GVector3& v); 00281 00285 QString toString() const; 00286 00291 void fromString(const QString& string); 00292 00293 }; 00294 00295 } 00296 00297 #endif
1.4.7