X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=Math%2Fpoint3d.hxx;h=ba43a8c0799d23ef5f7ab03cf513d641c291bc69;hb=2091bf21447bceb2a769f1da7f2368ed56486bbf;hp=ab30d94e74683a7cc723907f00143f92c13cda82;hpb=c5adb85741158b1d46eb630ec1d6dbd967248c52;p=simgear.git diff --git a/Math/point3d.hxx b/Math/point3d.hxx index ab30d94e..ba43a8c0 100644 --- a/Math/point3d.hxx +++ b/Math/point3d.hxx @@ -25,29 +25,16 @@ #ifndef _POINT3D_HXX #define _POINT3D_HXX + #ifndef __cplusplus # error This library requires C++ #endif -#include - -#include "Include/fg_stl_config.h" - -#ifdef NEEDNAMESPACESTD -using namespace std; -#endif - -/* -#include -#include -#include -*/ - +#include #include -#include - +const double fgPoint3_Epsilon = 0.0000001; enum {PX, PY, PZ}; // axes @@ -70,7 +57,7 @@ public: Point3D(); Point3D(const double x, const double y, const double z); - Point3D(const double d); + explicit Point3D(const double d); Point3D(const Point3D &p); // Assignment operators @@ -78,9 +65,9 @@ public: Point3D& operator = ( const Point3D& p ); // assignment of a Point3D Point3D& operator += ( const Point3D& p ); // incrementation by a Point3D Point3D& operator -= ( const Point3D& p ); // decrementation by a Point3D - Point3D& operator *= ( const double d ); // multiplication by a constant + Point3D& operator *= ( const double d ); // multiplication by a constant Point3D& operator /= ( const double d ); // division by a constant - void setvals(const double x, const double y, const double z); + void setx(const double x); void sety(const double y); void setz(const double z); @@ -100,18 +87,13 @@ public: double elev() const; // geodetic elevation (if specifying a surface point) // friends - friend Point3D operator - (const Point3D& p); // -p1 - friend Point3D operator + (const Point3D& a, const Point3D& b); // p1 + p2 - friend Point3D operator - (const Point3D& a, const Point3D& b); // p1 - p2 - friend Point3D operator * (const Point3D& a, const double d); // p1 * 3.0 - friend Point3D operator * (const double d, const Point3D& a); // 3.0 * p1 - friend Point3D operator / (const Point3D& a, const double d); // p1 / 3.0 - friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2? - friend bool operator != (const Point3D& a, const Point3D& b); // p1 != p2? + friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2? + friend istream& operator>> ( istream&, Point3D& ); + friend ostream& operator<< ( ostream&, const Point3D& ); // Special functions - double distance3D(const Point3D& a, const Point3D& b); // distance between + double distance3D(const Point3D& a) const; // distance between }; @@ -119,10 +101,9 @@ public: inline istream& operator >> ( istream& in, Point3D& p) { - double x, y, z; char c; - in >> x; + in >> p.n[PX]; // read past optional comma while ( in.get(c) ) { @@ -133,7 +114,7 @@ operator >> ( istream& in, Point3D& p) } } - in >> y; + in >> p.n[PY]; // read past optional comma while ( in.get(c) ) { @@ -144,13 +125,17 @@ operator >> ( istream& in, Point3D& p) } } - in >> z; - - p.setvals(x, y, z); + in >> p.n[PZ]; return in; } +inline ostream& +operator<< ( ostream& out, const Point3D& p ) +{ + return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ]; +} + /////////////////////////// // // Point3D Member functions @@ -204,10 +189,6 @@ inline Point3D& Point3D::operator /= ( const double d ) return *this; } -inline void Point3D::setvals(const double x, const double y, const double z) { - n[PX] = x; n[PY] = y; n[PZ] = z; -} - inline void Point3D::setx(const double x) { n[PX] = x; } @@ -258,17 +239,17 @@ inline Point3D operator - (const Point3D& a) inline Point3D operator + (const Point3D& a, const Point3D& b) { - return Point3D(a.n[PX]+ b.n[PX], a.n[PY] + b.n[PY], a.n[PZ] + b.n[PZ]); + return Point3D(a) += b; } inline Point3D operator - (const Point3D& a, const Point3D& b) { - return Point3D(a.n[PX]-b.n[PX], a.n[PY]-b.n[PY], a.n[PZ]-b.n[PZ]); + return Point3D(a) -= b; } inline Point3D operator * (const Point3D& a, const double d) { - return Point3D(d*a.n[PX], d*a.n[PY], d*a.n[PZ]); + return Point3D(a) *= d; } inline Point3D operator * (const double d, const Point3D& a) @@ -278,16 +259,15 @@ inline Point3D operator * (const double d, const Point3D& a) inline Point3D operator / (const Point3D& a, const double d) { - double d_inv = 1./d; - return Point3D(a.n[PX]*d_inv, a.n[PY]*d_inv, a.n[PZ]*d_inv); + return Point3D(a) *= (1.0 / d ); } inline bool operator == (const Point3D& a, const Point3D& b) { return - (a.n[PX] - b.n[PX]) < FG_EPSILON && - (a.n[PY] - b.n[PY]) < FG_EPSILON && - (a.n[PZ] - b.n[PZ]) < FG_EPSILON; + (a.n[PX] - b.n[PX]) < fgPoint3_Epsilon && + (a.n[PY] - b.n[PY]) < fgPoint3_Epsilon && + (a.n[PZ] - b.n[PZ]) < fgPoint3_Epsilon; } inline bool operator != (const Point3D& a, const Point3D& b) @@ -297,13 +277,14 @@ inline bool operator != (const Point3D& a, const Point3D& b) // Special functions -inline double distance3D(const Point3D& a, const Point3D& b) +inline double +Point3D::distance3D(const Point3D& a ) const { double x, y, z; - x = a[PX] - b[PX]; - y = a[PY] - b[PY]; - z = a[PZ] - b[PZ]; + x = n[PX] - a.n[PX]; + y = n[PY] - a.n[PY]; + z = n[PZ] - a.n[PZ]; return sqrt(x*x + y*y + z*z); } @@ -312,6 +293,15 @@ inline double distance3D(const Point3D& a, const Point3D& b) // $Log$ +// Revision 1.4 1998/11/11 00:18:38 curt +// Check for domain error in fgGeoctoGeod() +// +// Revision 1.3 1998/10/20 18:21:49 curt +// Tweaks from Bernie Bright. +// +// Revision 1.2 1998/10/18 01:17:12 curt +// Point3D tweaks. +// // Revision 1.1 1998/10/16 00:50:29 curt // Added point3d.hxx to replace cheezy fgPoint3d struct. //