Changeset 565 in Sophya for trunk/SophyaLib/Samba/vector3d.cc
- Timestamp:
- Nov 10, 1999, 3:01:46 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Samba/vector3d.cc
r264 r565 2 2 #include "vector3d.h" 3 3 #include "utilgeom.h" 4 5 Vector3d::Vector3d() 4 //++ 5 // Class Vector3d 6 // 7 // include vector3d.h utilgeom.h longlat.h math.h 8 // 9 // 10 // 3-D geometry. 11 // All computations are made with angles in radians and with spherical 12 // coordinates theta, phi. 13 // 14 // Concerning Euler's angles, the reference is : 15 // 16 // "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley 17 //-- 18 //++ 19 // Titre Constructors 20 //-- 21 //++ 22 Vector3d::Vector3d() 23 // 24 //-- 6 25 { 7 26 Setxyz(1.,0.,0.); 8 27 } 9 28 //++ 10 29 Vector3d::Vector3d(double x, double y, double z) 30 // 31 //-- 11 32 { 12 33 _x=x; … … 15 36 xyz2ThetaPhi(); 16 37 } 17 38 //++ 18 39 Vector3d::Vector3d(double theta, double phi) 40 // 41 //-- 19 42 { 20 43 _theta=mod(theta,M_PI); // dans [0;pi] … … 22 45 ThetaPhi2xyz(); 23 46 } 24 47 //++ 25 48 Vector3d::Vector3d(const LongLat& ll) 49 // 50 //-- 26 51 { 27 52 _theta=ll.Theta(); // dans [0;pi] … … 29 54 ThetaPhi2xyz(); 30 55 } 31 56 //++ 32 57 Vector3d::Vector3d(const Vector3d& v) 58 // 59 //-- 33 60 { 34 61 _x=v._x; … … 38 65 _phi=v._phi; 39 66 } 40 41 void Vector3d::SetThetaPhi(double theta, double phi) 67 //++ 68 // Titre Public methods 69 //-- 70 //++ 71 void Vector3d::SetThetaPhi(double theta, double phi) 72 // 73 //-- 42 74 { 43 75 _theta=mod(theta,M_PI); … … 45 77 ThetaPhi2xyz(); 46 78 } 47 79 //++ 48 80 void Vector3d::Setxyz(double x, double y, double z) 81 // 82 //-- 49 83 { 50 84 _x=x; … … 53 87 xyz2ThetaPhi(); 54 88 } 55 89 //++ 56 90 void Vector3d::ThetaPhi2xyz() 91 // 92 //-- 57 93 { 58 94 _x=sin(_theta)*cos(_phi); … … 60 96 _z=cos(_theta); 61 97 } 62 98 //++ 63 99 void Vector3d::xyz2ThetaPhi() 100 // 101 //-- 64 102 { 65 103 double norm=this->Norm(); … … 77 115 } 78 116 } 79 117 //++ 80 118 Vector3d& Vector3d::Normalize() 119 // 120 //-- 81 121 { 82 122 double norm=this->Norm(); … … 85 125 return *this; 86 126 } 87 127 //++ 88 128 double Vector3d::Norm() const 129 // 130 //-- 89 131 { 90 132 return sqrt(_x*_x+_y*_y+_z*_z); 91 133 } 92 134 //++ 93 135 double Vector3d::Psc(const Vector3d& v) const 136 // 137 // dot product 138 //-- 94 139 { 95 140 return _x*v._x+_y*v._y+_z*v._z; 96 141 } 97 142 //++ 98 143 double Vector3d::SepAngle(const Vector3d& v) const 144 // 145 // angular gap between 2 vectors in [0,Pi] 146 //-- 99 147 { 100 148 double n1=this->Norm(); … … 109 157 return ret; 110 158 } 111 159 //++ 112 160 Vector3d Vector3d::Vect(const Vector3d& v) const 161 // 162 // vector product 163 //-- 113 164 { 114 165 double xo=_y*v._z-_z*v._y; … … 117 168 return Vector3d(xo,yo,zo); 118 169 } 119 120 Vector3d Vector3d::VperpPhi() const // vecteur perpendiculaire de meme phi 170 //++ 171 Vector3d Vector3d::VperpPhi() const 172 // 173 // perpendicular vector, with equal phi 174 //-- 121 175 { 122 176 double theta; … … 125 179 return Vector3d(theta,_phi); 126 180 } 127 128 Vector3d Vector3d::VperpTheta() const // vecteur perpendiculaire de meme theta 181 //++ 182 Vector3d Vector3d::VperpTheta() const 183 // 184 // perpendicular vector with equal theta 185 //-- 129 186 { 130 187 double phi=mod(_phi+pi_over_2,pi2); // on tourne phi de pi/2 … … 147 204 return temp; 148 205 } 149 206 //++ 150 207 Vector3d Vector3d::ETheta() const 208 // 209 //-- 151 210 { 152 211 Vector3d temp=this->Vect(EPhi()); … … 155 214 } 156 215 157 216 //++ 158 217 Vector3d Vector3d::Euler(double phi, double theta, double psi) const 218 // 219 // Euler's rotations 220 //-- 159 221 { 160 222 double cpsi=cos(psi); … … 173 235 return Vector3d(xnew,ynew,znew); 174 236 } 175 237 //++ 176 238 Vector3d Vector3d::InvEuler(double phi, double theta, double psi) const 239 // 240 // inverse rotation 241 //-- 177 242 { 178 243 double cpsi=cos(psi); … … 191 256 return Vector3d(xnew,ynew,znew); 192 257 } 193 258 //++ 194 259 Vector3d Vector3d::Rotate(const Vector3d& omega, double phi) 260 // 261 // rotation of angle phi around an axis omega (Maxwell's rule) 262 //-- 195 263 { 196 264 Vector3d rotationaxis=omega; … … 200 268 Vector3d rotate=n*rotationaxis+(myself-n*rotationaxis)*cos(phi)-(myself^rotationaxis)*sin(phi); 201 269 return rotate; 202 } 203 204 Vector3d& Vector3d::operator+=(const Vector3d& v) 270 } 271 //++ 272 void Vector3d::Print(ostream& os) const 273 // 274 //-- 275 { 276 os << "Vector3: (X,Y,Z)= (" << _x << ", " << _y << ", " << _z 277 << ") --- Theta,Phi= " << _theta << ", " << _phi << "\n" 278 << "Norme = " << this->Norm() << endl; 279 } 280 //++ 281 // Titre Operators 282 //-- 283 //++ 284 Vector3d& Vector3d::operator += (const Vector3d& v) 285 // 286 //-- 205 287 { 206 288 *this=*this+v; 207 289 return *this; 208 290 } 209 210 Vector3d& Vector3d::operator-=(const Vector3d& v) 291 //++ 292 Vector3d& Vector3d::operator -= (const Vector3d& v) 293 // 294 //-- 211 295 { 212 296 *this=*this-v; 213 297 return *this; 214 298 } 215 216 Vector3d& Vector3d::operator+=(double d) 299 //++ 300 Vector3d& Vector3d::operator += (double d) 301 // 302 //-- 217 303 { 218 304 Setxyz(_x+d,_y+d,_z+d); 219 305 return *this; 220 306 } 221 222 Vector3d& Vector3d::operator/=(double d) 307 //++ 308 Vector3d& Vector3d::operator /= (double d) 309 // 310 //-- 223 311 { 224 312 if( d != 0. ) Setxyz(_x/d,_y/d,_z/d); … … 226 314 return *this; 227 315 } 228 229 Vector3d& Vector3d::operator*=(double d) 316 //++ 317 Vector3d& Vector3d::operator *= (double d) 318 // 319 //-- 230 320 { 231 321 Setxyz(_x*d,_y*d,_z*d); 232 322 return *this; 233 323 } 234 235 Vector3d Vector3d::operator^(const Vector3d& v) const 324 //++ 325 Vector3d Vector3d::operator ^ (const Vector3d& v) const 326 // 327 // vector product 328 //-- 236 329 { 237 330 return this->Vect(v); 238 331 } 239 240 Vector3d Vector3d::operator+(double d) const 332 //++ 333 Vector3d Vector3d::operator + (double d) const 334 // 335 //-- 241 336 { 242 337 return Vector3d(_x+d,_y+d,_z+d); 243 338 } 244 245 Vector3d Vector3d::operator+(const Vector3d& v) const 339 //++ 340 Vector3d Vector3d::operator + (const Vector3d& v) const 341 // 342 //-- 246 343 { 247 344 return Vector3d(_x+v._x,_y+v._y,_z+v._z); 248 345 } 249 250 Vector3d Vector3d::operator-(double d) const 346 //++ 347 Vector3d Vector3d::operator - (double d) const 348 // 349 //-- 251 350 { 252 351 return *this+(-d); 253 352 } 254 255 Vector3d Vector3d::operator-(const Vector3d& v) const 353 //++ 354 Vector3d Vector3d::operator - (const Vector3d& v) const 355 // 356 //-- 256 357 { 257 358 return *this+(v*(-1.)); 258 359 } 259 260 Vector3d Vector3d::operator*(double d) const 360 //++ 361 Vector3d Vector3d::operator * (double d) const 362 // 363 //-- 261 364 { 262 365 return Vector3d(d*_x,d*_y,d*_z); 263 366 } 264 265 double Vector3d::operator*(const Vector3d& v) const 367 //++ 368 double Vector3d::operator * (const Vector3d& v) const 369 // 370 // dot product 371 //-- 266 372 { 267 373 return this->Psc(v); 268 374 } 269 270 Vector3d Vector3d::operator/(double d) const 375 //++ 376 Vector3d Vector3d::operator / (double d) const 377 // 378 //-- 271 379 { 272 380 Vector3d ret=*this; … … 275 383 return ret; 276 384 } 277 278 Vector3d& Vector3d::operator=(const Vector3d& v) 385 //++ 386 Vector3d& Vector3d::operator = (const Vector3d& v) 387 // 388 //-- 279 389 { 280 390 if( this != &v ) … … 288 398 return *this; 289 399 } 400 //++ 401 bool Vector3d::operator == (const Vector3d& v) 402 // 403 //-- 404 { 405 return (this==&v); 406 } 290 407 291 bool Vector3d::operator==(const Vector3d& v)292 {293 return (this==&v);294 }295 296 void Vector3d::Print(ostream& os) const297 {298 os << "Vector3: (X,Y,Z)= (" << _x << ", " << _y << ", " << _z299 << ") --- Theta,Phi= " << _theta << ", " << _phi << "\n"300 << "Norme = " << this->Norm() << endl;301 }
Note:
See TracChangeset
for help on using the changeset viewer.