Tweaks from Bernie Bright.
This commit is contained in:
parent
75bc07dc42
commit
bb70329c25
@ -25,23 +25,16 @@
|
|||||||
#ifndef _POINT3D_HXX
|
#ifndef _POINT3D_HXX
|
||||||
#define _POINT3D_HXX
|
#define _POINT3D_HXX
|
||||||
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
# error This library requires C++
|
# error This library requires C++
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <Misc/fgstream.hxx>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Include/fg_stl_config.h"
|
|
||||||
|
|
||||||
#ifdef NEEDNAMESPACESTD
|
|
||||||
using namespace std;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <Include/fg_constants.h>
|
const double fgPoint3_Epsilon = 0.0000001;
|
||||||
|
|
||||||
|
|
||||||
enum {PX, PY, PZ}; // axes
|
enum {PX, PY, PZ}; // axes
|
||||||
|
|
||||||
@ -64,7 +57,7 @@ public:
|
|||||||
|
|
||||||
Point3D();
|
Point3D();
|
||||||
Point3D(const double x, const double y, const double z);
|
Point3D(const double x, const double y, const double z);
|
||||||
Point3D(const double d);
|
explicit Point3D(const double d);
|
||||||
Point3D(const Point3D &p);
|
Point3D(const Point3D &p);
|
||||||
|
|
||||||
// Assignment operators
|
// Assignment operators
|
||||||
@ -72,7 +65,7 @@ public:
|
|||||||
Point3D& operator = ( const Point3D& p ); // assignment of a Point3D
|
Point3D& operator = ( const Point3D& p ); // assignment of a Point3D
|
||||||
Point3D& operator += ( const Point3D& p ); // incrementation by a Point3D
|
Point3D& operator += ( const Point3D& p ); // incrementation by a Point3D
|
||||||
Point3D& operator -= ( const Point3D& p ); // decrementation 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
|
Point3D& operator /= ( const double d ); // division by a constant
|
||||||
|
|
||||||
void setx(const double x);
|
void setx(const double x);
|
||||||
@ -94,44 +87,23 @@ public:
|
|||||||
double elev() const; // geodetic elevation (if specifying a surface point)
|
double elev() const; // geodetic elevation (if specifying a surface point)
|
||||||
|
|
||||||
// friends
|
// friends
|
||||||
|
|
||||||
friend Point3D operator - (const Point3D& p); // -p1
|
friend Point3D operator - (const Point3D& p); // -p1
|
||||||
friend Point3D operator + (const Point3D& a, const Point3D& b); // p1 + p2
|
friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2?
|
||||||
friend Point3D operator - (const Point3D& a, const Point3D& b); // p1 - p2
|
friend istream& operator>> ( istream&, Point3D& );
|
||||||
friend Point3D operator * (const Point3D& a, const double d); // p1 * 3.0
|
friend ostream& operator<< ( ostream&, const Point3D& );
|
||||||
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?
|
|
||||||
|
|
||||||
// Special functions
|
// Special functions
|
||||||
double distance3D(const Point3D& a, const Point3D& b); // distance between
|
double distance3D(const Point3D& a) const; // distance between
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// output to stream
|
|
||||||
inline ostream&
|
|
||||||
operator << ( ostream& out, Point3D& p)
|
|
||||||
{
|
|
||||||
double x, y, z;
|
|
||||||
|
|
||||||
x = p.x();
|
|
||||||
y = p.y();
|
|
||||||
z = p.z();
|
|
||||||
|
|
||||||
out << x << " " << y << " " << z;
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// input from stream
|
// input from stream
|
||||||
inline istream&
|
inline istream&
|
||||||
operator >> ( istream& in, Point3D& p)
|
operator >> ( istream& in, Point3D& p)
|
||||||
{
|
{
|
||||||
double x, y, z;
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
in >> x;
|
in >> p.n[PX];
|
||||||
|
|
||||||
// read past optional comma
|
// read past optional comma
|
||||||
while ( in.get(c) ) {
|
while ( in.get(c) ) {
|
||||||
@ -142,7 +114,7 @@ operator >> ( istream& in, Point3D& p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
in >> y;
|
in >> p.n[PY];
|
||||||
|
|
||||||
// read past optional comma
|
// read past optional comma
|
||||||
while ( in.get(c) ) {
|
while ( in.get(c) ) {
|
||||||
@ -153,13 +125,17 @@ operator >> ( istream& in, Point3D& p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
in >> z;
|
in >> p.n[PZ];
|
||||||
|
|
||||||
p = Point3D(x, y, z);
|
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ostream&
|
||||||
|
operator<< ( ostream& out, const Point3D& p )
|
||||||
|
{
|
||||||
|
return out << p.n[PX] << ',' << p.n[PY] << ',' << p.n[PZ];
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
//
|
//
|
||||||
// Point3D Member functions
|
// Point3D Member functions
|
||||||
@ -263,17 +239,17 @@ inline Point3D operator - (const Point3D& a)
|
|||||||
|
|
||||||
inline Point3D operator + (const Point3D& a, const Point3D& 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 Point3D& 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)
|
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)
|
inline Point3D operator * (const double d, const Point3D& a)
|
||||||
@ -283,16 +259,15 @@ inline Point3D operator * (const double d, const Point3D& a)
|
|||||||
|
|
||||||
inline Point3D operator / (const Point3D& a, const double d)
|
inline Point3D operator / (const Point3D& a, const double d)
|
||||||
{
|
{
|
||||||
double d_inv = 1./d;
|
return Point3D(a) *= (1.0 / d );
|
||||||
return Point3D(a.n[PX]*d_inv, a.n[PY]*d_inv, a.n[PZ]*d_inv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator == (const Point3D& a, const Point3D& b)
|
inline bool operator == (const Point3D& a, const Point3D& b)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(a.n[PX] - b.n[PX]) < FG_EPSILON &&
|
(a.n[PX] - b.n[PX]) < fgPoint3_Epsilon &&
|
||||||
(a.n[PY] - b.n[PY]) < FG_EPSILON &&
|
(a.n[PY] - b.n[PY]) < fgPoint3_Epsilon &&
|
||||||
(a.n[PZ] - b.n[PZ]) < FG_EPSILON;
|
(a.n[PZ] - b.n[PZ]) < fgPoint3_Epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator != (const Point3D& a, const Point3D& b)
|
inline bool operator != (const Point3D& a, const Point3D& b)
|
||||||
@ -302,13 +277,14 @@ inline bool operator != (const Point3D& a, const Point3D& b)
|
|||||||
|
|
||||||
// Special functions
|
// Special functions
|
||||||
|
|
||||||
inline double distance3D(const Point3D& a, const Point3D& b)
|
inline double
|
||||||
|
Point3D::distance3D(const Point3D& a ) const
|
||||||
{
|
{
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
|
|
||||||
x = a[PX] - b[PX];
|
x = n[PX] - a.n[PX];
|
||||||
y = a[PY] - b[PY];
|
y = n[PY] - a.n[PY];
|
||||||
z = a[PZ] - b[PZ];
|
z = n[PZ] - a.n[PZ];
|
||||||
|
|
||||||
return sqrt(x*x + y*y + z*z);
|
return sqrt(x*x + y*y + z*z);
|
||||||
}
|
}
|
||||||
@ -317,6 +293,9 @@ inline double distance3D(const Point3D& a, const Point3D& b)
|
|||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.3 1998/10/20 18:21:49 curt
|
||||||
|
// Tweaks from Bernie Bright.
|
||||||
|
//
|
||||||
// Revision 1.2 1998/10/18 01:17:12 curt
|
// Revision 1.2 1998/10/18 01:17:12 curt
|
||||||
// Point3D tweaks.
|
// Point3D tweaks.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user