00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef GEOMETRY_H
00031 #define GEOMETRY_H
00032
00033 #include <cmath>
00034 #include <cfloat>
00035 #include <iostream>
00036 #include <string>
00037
00038 #include "earth_geometry.h"
00039
00040
00041 namespace Spherical {
00042 class Point3D;
00043 }
00044 namespace Geocentric {
00045 class Point3D;
00046 }
00047 namespace Geodetic {
00048 class Point3D;
00049 }
00050 namespace Carthesian {
00051 class Point3D;
00052 class Segment3D;
00053 class Vector3D;
00054 class Matrix3D;
00055 }
00056
00060 namespace Carthesian {
00078 bool intersection (const Carthesian::Point3D & p1, const Carthesian::Point3D & p2,
00079 const Carthesian::Point3D & p3, const Carthesian::Point3D & p4,
00080 Carthesian::Point3D & pa, Carthesian::Point3D & pb,
00081 double & mua, double & mub);
00096 bool intersection (const Carthesian::Segment3D & p1p2,
00097 const Carthesian::Segment3D & p3p4,
00098 Carthesian::Segment3D & papb,
00099 double & mua, double & mub);
00106 double angle (const Carthesian::Vector3D & v1, const Carthesian::Vector3D & v2);
00113 double dotproduct (const Carthesian::Vector3D & v1, const Carthesian::Vector3D & v2);
00120 void dotproduct (const Carthesian::Matrix3D & m, const Carthesian::Vector3D & v, Carthesian::Vector3D &vout);
00127 Carthesian::Vector3D dotproduct (const Carthesian::Matrix3D & m, const Carthesian::Vector3D & v);
00134 void crossproduct (const Carthesian::Vector3D & v1, const Carthesian::Vector3D & v2, Carthesian::Vector3D & vout);
00141 Carthesian::Vector3D crossproduct (const Carthesian::Vector3D & v1, const Carthesian::Vector3D & v2);
00149 void rotation_matrix (const Carthesian::Vector3D & axis, const double theta, Carthesian::Matrix3D &matrix);
00158 void rotate (const Carthesian::Vector3D & v, const Carthesian::Vector3D & axis, const double theta, Carthesian::Vector3D & vout);
00167 Carthesian::Vector3D rotate (const Carthesian::Vector3D & v, const Carthesian::Vector3D & axis, const double theta);
00171 class Point3D {
00172 public:
00173 double x;
00174 double y;
00175 double z;
00182 Point3D (double x = 0.0, double y = 0.0, double z = 0.0);
00187 Point3D (const Carthesian::Point3D &p);
00192 Point3D& operator= (const Carthesian::Point3D &p);
00198 const Point3D operator + (const Carthesian::Vector3D & v) const;
00205 friend std::ostream &operator<< (std::ostream &os, const Point3D& p) {
00206 os << "Carthesian::Point3D (" << p.x << ", " << p.y << ", " << p.z << ")";
00207 return os;
00208 };
00215 void set (double x = 0.0, double y = 0.0, double z = 0.0);
00220 Spherical::Point3D to_spherical (void) const;
00225 Geocentric::Point3D to_geocentric (void) const;
00230 Geodetic::Point3D to_geodetic (void) const;
00235 void translate (const Carthesian::Vector3D &v);
00236 };
00237
00241 class Segment3D {
00242 public:
00244 Point3D p1;
00246 Point3D p2;
00252
00258 Segment3D (const Carthesian::Point3D &p1 = Carthesian::Point3D(), const Carthesian::Point3D &p2 = Carthesian::Point3D());
00264
00270 Segment3D (const Geodetic::Point3D &p1, const Geodetic::Point3D &p2);
00275 Segment3D (const Segment3D &s);
00280 Segment3D& operator= (const Segment3D &s);
00286 void set (const Carthesian::Point3D &p1, const Carthesian::Point3D &p2);
00293 friend std::ostream &operator<< (std::ostream &os, const Segment3D& p) {
00294 os << "Carthesian::Segment3D {" << p.get_p1() << " -> " << p.get_p2() << "}";
00295
00296 return os;
00297 };
00302 Point3D get_p1() const {
00303 return p1;
00304 }
00309 Point3D get_p2() const {
00310 return p2;
00311 }
00316 double length () const {
00317 double dx = p2.x - p1.x;
00318 double dy = p2.y - p1.y;
00319 double dz = p2.z - p1.z;
00320 return sqrt ((dx * dx) + (dy * dy) + (dz * dz));
00321 }
00322
00327 Carthesian::Vector3D to_vector () const;
00332 Carthesian::Vector3D to_unit_vector () const;
00333 };
00334
00338 class Vector3D {
00339 public:
00340 double x;
00341 double y;
00342 double z;
00349 Vector3D (double x = 0.0, double y = 0.0, double z = 0.0);
00355 Vector3D (const Carthesian::Point3D &p1, const Carthesian::Point3D &p2);
00360 Vector3D (const Vector3D &v);
00365 Vector3D& operator = (const Vector3D &v);
00370 const Vector3D operator * (const double & val);
00375 const Vector3D operator / (const double & val);
00382 void set (double x = 0.0, double y = 0.0, double z = 0.0);
00389 friend std::ostream &operator<< (std::ostream &os, const Vector3D& p) {
00390 os << "Carthesian::Vector3D [" << p.x << ", " << p.y << ", " << p.z << "]";
00391 return os;
00392 };
00397 double norm ();
00398 };
00402 class Matrix3D {
00403 public:
00404 double xx;
00405 double xy;
00406 double xz;
00407 double yx;
00408 double yy;
00409 double yz;
00410 double zx;
00411 double zy;
00412 double zz;
00425 Matrix3D (double xx = 0.0, double xy = 0.0, double xz = 0.0,
00426 double yx = 0.0, double yy = 0.0, double yz = 0.0,
00427 double zx = 0.0, double zy = 0.0, double zz = 0.0);
00432 Matrix3D (const Matrix3D &v);
00437 Matrix3D& operator= (const Matrix3D &v);
00450 void set (double xx = 0.0, double xy = 0.0, double xz = 0.0,
00451 double yx = 0.0, double yy = 0.0, double yz = 0.0,
00452 double zx = 0.0, double zy = 0.0, double zz = 0.0);
00459 friend std::ostream &operator<< (std::ostream &os, const Matrix3D& m) {
00460 os << "Carthesian::Matrix3D |" << m.xx << ", " << m.xy << ", " << m.xz << std::endl;
00461 os << " |" << m.yx << ", " << m.yy << ", " << m.yz << std::endl;
00462 os << " |" << m.zx << ", " << m.zy << ", " << m.zz << std::endl;
00463 return os;
00464 };
00465 };
00466 }
00467
00471 namespace Spherical {
00475 class Point3D {
00476 public:
00478 double r;
00480 double theta;
00482 double phi;
00489 Point3D (double r = 0.0, double theta = 0.0, double phi = 0.0);
00494 Point3D (const Spherical::Point3D &p);
00499 Point3D& operator= (const Spherical::Point3D &p);
00506 friend std::ostream &operator<< (std::ostream &os, const Point3D& p)
00507 {
00508 os << "Spherical::Point3D (" << p.r << ", " << p.theta << ", " << p.phi << ")";
00509 return os;
00510 }
00517 void set (double r = 0.0, double theta = 0.0, double phi = 0.0);
00522 Carthesian::Point3D to_carthesian (void) const;
00527 Geocentric::Point3D to_geocentric (void) const;
00528 };
00529 }
00530
00534 namespace Geocentric {
00546 const double get_orthodormic_angle ( double lat1, double lon1,
00547 double lat2, double lon2);
00554 const double get_square_plane_dist ( const double dlat, const double dlon );
00563 const double get_square_plane_dist ( const double lat1, const double lon1,
00564 const double lat2, const double lon2 );
00576 const double get_haversine_dist (double lat1, double lon1, double lat2, double lon2);
00580 class Point3D {
00581 public:
00583 double lat;
00585 double lon;
00587 double alt;
00594 Point3D (double lat = 0.0, double lon = 0.0, double alt = 0.0);
00599 Point3D (const Geocentric::Point3D &p);
00604 Point3D& operator= (const Geocentric::Point3D &p);
00611 friend std::ostream &operator<< (std::ostream &os, const Point3D& p) {
00612 os << "Geocentric::Point3D (" << p.lat << ", " << p.lon << ", " << p.alt << ")";
00613 return os;
00614 };
00621 void set (double lat = 0.0, double lon = 0.0, double alt = 0.0);
00626 Spherical::Point3D to_spherical (void) const;
00631 Carthesian::Point3D to_carthesian () const;
00632 };
00633 }
00634
00638 namespace Geodetic {
00642 class Point3D {
00643 public:
00645 double lat;
00647 double lon;
00649 double alt;
00656 Point3D (double lat = 0.0, double lon = 0.0, double alt = 0.0);
00661 Point3D (const Geodetic::Point3D &p);
00666 Point3D& operator= (const Geodetic::Point3D &p);
00673 friend std::ostream &operator<< (std::ostream &os, const Geodetic::Point3D& p) {
00674 os << "Geodetic::Point3D (" << p.lat << ", " << p.lon << ", " << p.alt << ")";
00675 return os;
00676 };
00683 void set (double lat = 0.0, double lon = 0.0, double alt = 0.0);
00688 Spherical::Point3D to_spherical (void) const;
00693 Carthesian::Point3D to_carthesian () const;
00694 };
00695 }
00696
00697
00698 #endif