Remove deprecated vector classes - finally!
This commit is contained in:
@@ -24,12 +24,9 @@ lib_LIBRARIES = libsgmath.a
|
||||
include_HEADERS = \
|
||||
interpolater.hxx \
|
||||
leastsqs.hxx \
|
||||
point3d.hxx \
|
||||
polar3d.hxx \
|
||||
sg_geodesy.hxx \
|
||||
sg_random.h \
|
||||
sg_types.hxx \
|
||||
vector.hxx \
|
||||
Math.hxx \
|
||||
SGBox.hxx \
|
||||
SGCMath.hxx \
|
||||
@@ -59,7 +56,6 @@ libsgmath_a_SOURCES = \
|
||||
interpolater.cxx \
|
||||
leastsqs.cxx \
|
||||
sg_random.c \
|
||||
vector.cxx \
|
||||
SGGeod.cxx \
|
||||
SGGeodesy.cxx
|
||||
|
||||
|
||||
@@ -1,438 +0,0 @@
|
||||
/**
|
||||
* \file point3d.hxx
|
||||
* A 3d point class (depricated). This class is depricated and we are
|
||||
* in the process of removing all usage of it in favor of plib's "sg"
|
||||
* library of point, vector, and math routines. Plib's sg lib is less
|
||||
* object oriented, but integrates more seamlessly with opengl.
|
||||
*
|
||||
* Adapted from algebra3 by Jean-Francois Doue, started October 1998.
|
||||
*/
|
||||
|
||||
// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _POINT3D_HXX
|
||||
#define _POINT3D_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
#include "SGMath.hxx"
|
||||
|
||||
const double fgPoint3_Epsilon = 0.0000001;
|
||||
|
||||
enum {PX, PY, PZ}; // axes
|
||||
|
||||
// Kludge for msvc++ 6.0 - requires forward decls of friend functions.
|
||||
class Point3D;
|
||||
std::istream& operator>> ( std::istream&, Point3D& );
|
||||
std::ostream& operator<< ( std::ostream&, const Point3D& );
|
||||
Point3D operator- (const Point3D& p); // -p1
|
||||
bool operator== (const Point3D& a, const Point3D& b); // p1 == p2?
|
||||
|
||||
|
||||
/**
|
||||
* 3D Point class.
|
||||
*/
|
||||
|
||||
class Point3D {
|
||||
|
||||
protected:
|
||||
|
||||
double n[3];
|
||||
|
||||
public:
|
||||
|
||||
/** Default constructor */
|
||||
Point3D();
|
||||
Point3D(const double x, const double y, const double z);
|
||||
explicit Point3D(const double d);
|
||||
Point3D(const Point3D &p);
|
||||
|
||||
static Point3D fromSGGeod(const SGGeod& geod);
|
||||
static Point3D fromSGGeoc(const SGGeoc& geoc);
|
||||
static Point3D fromSGVec3(const SGVec3<double>& cart);
|
||||
static Point3D fromSGVec3(const SGVec3<float>& cart);
|
||||
static Point3D fromSGVec2(const SGVec2<double>& cart);
|
||||
|
||||
// Assignment operators
|
||||
|
||||
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 ); // division by a constant
|
||||
|
||||
void setx(const double x);
|
||||
void sety(const double y);
|
||||
void setz(const double z);
|
||||
void setlon(const double x);
|
||||
void setlat(const double y);
|
||||
void setradius(const double z);
|
||||
void setelev(const double z);
|
||||
|
||||
// Queries
|
||||
|
||||
double& operator [] ( int i); // indexing
|
||||
double operator[] (int i) const; // read-only indexing
|
||||
|
||||
inline const double *get_n() const { return n; };
|
||||
double x() const; // cartesian x
|
||||
double y() const; // cartesian y
|
||||
double z() const; // cartesian z
|
||||
|
||||
double lon() const; // polar longitude
|
||||
double lat() const; // polar latitude
|
||||
double radius() const; // polar radius
|
||||
double elev() const; // geodetic elevation (if specifying a surface point)
|
||||
|
||||
SGGeod toSGGeod(void) const;
|
||||
SGGeoc toSGGeoc(void) const;
|
||||
|
||||
SGVec3d toSGVec3d(void) const;
|
||||
SGVec3f toSGVec3f(void) const;
|
||||
SGVec2f toSGVec2f(void) const;
|
||||
|
||||
// friends
|
||||
friend Point3D operator - (const Point3D& p); // -p1
|
||||
friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2?
|
||||
friend std::istream& operator>> ( std::istream&, Point3D& );
|
||||
friend std::ostream& operator<< ( std::ostream&, const Point3D& );
|
||||
|
||||
// Special functions
|
||||
double distance3D(const Point3D& a) const; // distance between
|
||||
double distance3Dsquared(const Point3D& a) const; // distance between ^ 2
|
||||
};
|
||||
|
||||
|
||||
// input from stream
|
||||
inline std::istream&
|
||||
operator >> ( std::istream& in, Point3D& p)
|
||||
{
|
||||
char c;
|
||||
|
||||
in >> p.n[PX];
|
||||
|
||||
// read past optional comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> p.n[PY];
|
||||
|
||||
// read past optional comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> p.n[PZ];
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
inline std::ostream&
|
||||
operator<< ( std::ostream& out, const Point3D& p )
|
||||
{
|
||||
return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ];
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
//
|
||||
// Point3D Member functions
|
||||
//
|
||||
///////////////////////////
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
inline Point3D::Point3D()
|
||||
{
|
||||
n[PX] = n[PY] = 0.0;
|
||||
n[PZ] = -9999.0;
|
||||
}
|
||||
|
||||
inline Point3D::Point3D(const double x, const double y, const double z)
|
||||
{
|
||||
n[PX] = x; n[PY] = y; n[PZ] = z;
|
||||
}
|
||||
|
||||
inline Point3D::Point3D(const double d)
|
||||
{
|
||||
n[PX] = n[PY] = n[PZ] = d;
|
||||
}
|
||||
|
||||
inline Point3D::Point3D(const Point3D& p)
|
||||
{
|
||||
n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ];
|
||||
}
|
||||
|
||||
inline Point3D Point3D::fromSGGeod(const SGGeod& geod)
|
||||
{
|
||||
Point3D pt;
|
||||
pt.setlon(geod.getLongitudeRad());
|
||||
pt.setlat(geod.getLatitudeRad());
|
||||
pt.setelev(geod.getElevationM());
|
||||
return pt;
|
||||
}
|
||||
|
||||
inline Point3D Point3D::fromSGGeoc(const SGGeoc& geoc)
|
||||
{
|
||||
Point3D pt;
|
||||
pt.setlon(geoc.getLongitudeRad());
|
||||
pt.setlat(geoc.getLatitudeRad());
|
||||
pt.setradius(geoc.getRadiusM());
|
||||
return pt;
|
||||
}
|
||||
|
||||
inline Point3D Point3D::fromSGVec3(const SGVec3<double>& cart)
|
||||
{
|
||||
Point3D pt;
|
||||
pt.setx(cart.x());
|
||||
pt.sety(cart.y());
|
||||
pt.setz(cart.z());
|
||||
return pt;
|
||||
}
|
||||
|
||||
inline Point3D Point3D::fromSGVec3(const SGVec3<float>& cart)
|
||||
{
|
||||
Point3D pt;
|
||||
pt.setx(cart.x());
|
||||
pt.sety(cart.y());
|
||||
pt.setz(cart.z());
|
||||
return pt;
|
||||
}
|
||||
|
||||
inline Point3D Point3D::fromSGVec2(const SGVec2<double>& cart)
|
||||
{
|
||||
Point3D pt;
|
||||
pt.setx(cart.x());
|
||||
pt.sety(cart.y());
|
||||
pt.setz(0);
|
||||
return pt;
|
||||
}
|
||||
|
||||
// ASSIGNMENT OPERATORS
|
||||
|
||||
inline Point3D& Point3D::operator = (const Point3D& p)
|
||||
{
|
||||
n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ]; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator += ( const Point3D& p )
|
||||
{
|
||||
n[PX] += p.n[PX]; n[PY] += p.n[PY]; n[PZ] += p.n[PZ]; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator -= ( const Point3D& p )
|
||||
{
|
||||
n[PX] -= p.n[PX]; n[PY] -= p.n[PY]; n[PZ] -= p.n[PZ]; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator *= ( const double d )
|
||||
{
|
||||
n[PX] *= d; n[PY] *= d; n[PZ] *= d; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator /= ( const double d )
|
||||
{
|
||||
double d_inv = 1./d; n[PX] *= d_inv; n[PY] *= d_inv; n[PZ] *= d_inv;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Point3D::setx(const double x) {
|
||||
n[PX] = x;
|
||||
}
|
||||
|
||||
inline void Point3D::sety(const double y) {
|
||||
n[PY] = y;
|
||||
}
|
||||
|
||||
inline void Point3D::setz(const double z) {
|
||||
n[PZ] = z;
|
||||
}
|
||||
|
||||
inline void Point3D::setlon(const double x) {
|
||||
n[PX] = x;
|
||||
}
|
||||
|
||||
inline void Point3D::setlat(const double y) {
|
||||
n[PY] = y;
|
||||
}
|
||||
|
||||
inline void Point3D::setradius(const double z) {
|
||||
n[PZ] = z;
|
||||
}
|
||||
|
||||
inline void Point3D::setelev(const double z) {
|
||||
n[PZ] = z;
|
||||
}
|
||||
|
||||
// QUERIES
|
||||
|
||||
inline double& Point3D::operator [] ( int i)
|
||||
{
|
||||
assert(! (i < PX || i > PZ));
|
||||
return n[i];
|
||||
}
|
||||
|
||||
inline double Point3D::operator [] ( int i) const {
|
||||
assert(! (i < PX || i > PZ));
|
||||
return n[i];
|
||||
}
|
||||
|
||||
|
||||
inline double Point3D::x() const { return n[PX]; }
|
||||
|
||||
inline double Point3D::y() const { return n[PY]; }
|
||||
|
||||
inline double Point3D::z() const { return n[PZ]; }
|
||||
|
||||
inline double Point3D::lon() const { return n[PX]; }
|
||||
|
||||
inline double Point3D::lat() const { return n[PY]; }
|
||||
|
||||
inline double Point3D::radius() const { return n[PZ]; }
|
||||
|
||||
inline double Point3D::elev() const { return n[PZ]; }
|
||||
|
||||
inline SGGeod Point3D::toSGGeod(void) const
|
||||
{
|
||||
SGGeod geod;
|
||||
geod.setLongitudeRad(lon());
|
||||
geod.setLatitudeRad(lat());
|
||||
geod.setElevationM(elev());
|
||||
return geod;
|
||||
}
|
||||
|
||||
inline SGGeoc Point3D::toSGGeoc(void) const
|
||||
{
|
||||
SGGeoc geoc;
|
||||
geoc.setLongitudeRad(lon());
|
||||
geoc.setLatitudeRad(lat());
|
||||
geoc.setRadiusM(radius());
|
||||
return geoc;
|
||||
}
|
||||
|
||||
inline SGVec3d Point3D::toSGVec3d(void) const
|
||||
{
|
||||
return SGVec3d(x(), y(), z());
|
||||
}
|
||||
|
||||
inline SGVec3f Point3D::toSGVec3f(void) const
|
||||
{
|
||||
return SGVec3f(x(), y(), z());
|
||||
}
|
||||
|
||||
inline SGVec2f Point3D::toSGVec2f(void) const
|
||||
{
|
||||
return SGVec2f(x(), y());
|
||||
}
|
||||
|
||||
// FRIENDS
|
||||
|
||||
inline Point3D operator - (const Point3D& a)
|
||||
{
|
||||
return Point3D(-a.n[PX],-a.n[PY],-a.n[PZ]);
|
||||
}
|
||||
|
||||
inline Point3D operator + (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return Point3D(a) += b;
|
||||
}
|
||||
|
||||
inline Point3D operator - (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return Point3D(a) -= b;
|
||||
}
|
||||
|
||||
inline Point3D operator * (const Point3D& a, const double d)
|
||||
{
|
||||
return Point3D(a) *= d;
|
||||
}
|
||||
|
||||
inline Point3D operator * (const double d, const Point3D& a)
|
||||
{
|
||||
return a*d;
|
||||
}
|
||||
|
||||
inline Point3D operator / (const Point3D& a, const double d)
|
||||
{
|
||||
return Point3D(a) *= (1.0 / d );
|
||||
}
|
||||
|
||||
inline bool operator == (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return
|
||||
fabs(a.n[PX] - b.n[PX]) < fgPoint3_Epsilon &&
|
||||
fabs(a.n[PY] - b.n[PY]) < fgPoint3_Epsilon &&
|
||||
fabs(a.n[PZ] - b.n[PZ]) < fgPoint3_Epsilon;
|
||||
}
|
||||
|
||||
inline bool operator != (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
// Special functions
|
||||
|
||||
inline double
|
||||
Point3D::distance3D(const Point3D& a ) const
|
||||
{
|
||||
double x, y, z;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
inline double
|
||||
Point3D::distance3Dsquared(const Point3D& a ) const
|
||||
{
|
||||
double x, y, z;
|
||||
|
||||
x = n[PX] - a.n[PX];
|
||||
y = n[PY] - a.n[PY];
|
||||
z = n[PZ] - a.n[PZ];
|
||||
|
||||
return(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
|
||||
#endif // _POINT3D_HXX
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* \file polar3d.hxx
|
||||
* Routines to deal with polar math and transformations.
|
||||
*/
|
||||
|
||||
// Written by Curtis Olson, started June 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _POLAR3D_HXX
|
||||
#define _POLAR3D_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include "SGMath.hxx"
|
||||
|
||||
/**
|
||||
* Calculate new lon/lat given starting lon/lat, and offset radial, and
|
||||
* distance. NOTE: starting point is specifed in radians, distance is
|
||||
* specified in meters (and converted internally to radians)
|
||||
* ... assumes a spherical world.
|
||||
* @param orig specified in polar coordinates
|
||||
* @param course offset radial
|
||||
* @param dist offset distance
|
||||
* @return destination point in polar coordinates
|
||||
*/
|
||||
inline Point3D calc_gc_lon_lat(const Point3D& orig, double course, double dist)
|
||||
{ return Point3D::fromSGGeoc(orig.toSGGeoc().advanceRadM(course, dist)); }
|
||||
|
||||
|
||||
/**
|
||||
* Calculate course/dist given two spherical points.
|
||||
* @param start starting point
|
||||
* @param dest ending point
|
||||
* @param course resulting course
|
||||
* @param dist resulting distance
|
||||
*/
|
||||
inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
|
||||
double *course, double *dist )
|
||||
{
|
||||
SGGeoc gs = start.toSGGeoc();
|
||||
SGGeoc gd = dest.toSGGeoc();
|
||||
*course = SGGeoc::courseRad(gs, gd);
|
||||
*dist = SGGeoc::distanceM(gs, gd);
|
||||
}
|
||||
|
||||
#endif // _POLAR3D_HXX
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef _SG_GEODESY_HXX
|
||||
#define _SG_GEODESY_HXX
|
||||
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include "SGMath.hxx"
|
||||
|
||||
// Compatibility header.
|
||||
@@ -52,21 +51,6 @@ inline void sgCartToGeod(const double* xyz, double* lat, double* lon, double* al
|
||||
*alt = geod.getElevationM();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a cartesian point to a geodetic lat/lon/altitude.
|
||||
* Alternate form using Point3D objects.
|
||||
*
|
||||
* @param cartesian point
|
||||
* @return geodetic point
|
||||
*/
|
||||
inline Point3D sgCartToGeod(const Point3D& p)
|
||||
{
|
||||
SGGeod geod;
|
||||
SGGeodesy::SGCartToGeod(SGVec3<double>(p.x(), p.y(), p.z()), geod);
|
||||
return Point3D::fromSGGeod(geod);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a geodetic lat/lon/altitude to a cartesian point.
|
||||
*
|
||||
@@ -84,20 +68,6 @@ inline void sgGeodToCart(double lat, double lon, double alt, double* xyz)
|
||||
xyz[2] = cart(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a geodetic lat/lon/altitude to a cartesian point.
|
||||
* Alternate form using Point3D objects.
|
||||
*
|
||||
* @param geodetic point
|
||||
* @return cartesian point
|
||||
*/
|
||||
inline Point3D sgGeodToCart(const Point3D& geod)
|
||||
{
|
||||
SGVec3<double> cart;
|
||||
SGGeodesy::SGGeodToCart(SGGeod::fromRadM(geod.lon(), geod.lat(), geod.elev()), cart);
|
||||
return Point3D::fromSGVec3(cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a starting position and an offset radial and distance,
|
||||
* calculate an ending positon on a wgs84 ellipsoid.
|
||||
|
||||
@@ -38,28 +38,18 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Point3D;
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
/** STL vector list of ints */
|
||||
typedef vector < int > int_list;
|
||||
typedef std::vector < int > int_list;
|
||||
typedef int_list::iterator int_list_iterator;
|
||||
typedef int_list::const_iterator const_int_list_iterator;
|
||||
|
||||
/** STL vector list of doubles */
|
||||
typedef vector < double > double_list;
|
||||
typedef std::vector < double > double_list;
|
||||
typedef double_list::iterator double_list_iterator;
|
||||
typedef double_list::const_iterator const_double_list_iterator;
|
||||
|
||||
/** STL vector list of Point3D */
|
||||
typedef vector < Point3D > point_list;
|
||||
typedef point_list::iterator point_list_iterator;
|
||||
typedef point_list::const_iterator const_point_list_iterator;
|
||||
|
||||
/** STL vector list of strings */
|
||||
typedef vector < string > string_list;
|
||||
typedef std::vector < std::string > string_list;
|
||||
typedef string_list::iterator string_list_iterator;
|
||||
typedef string_list::const_iterator const_string_list_iterator;
|
||||
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
// vector.cxx -- additional vector routines
|
||||
//
|
||||
// Written by Curtis Olson, started December 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// #include <Include/fg_types.h>
|
||||
|
||||
#include "vector.hxx"
|
||||
|
||||
|
||||
// calculate the projection, p, of u along the direction of d.
|
||||
void sgProjection(sgVec3 p, const sgVec3 u, const sgVec3 d){
|
||||
double denom = sgScalarProductVec3(d,d);
|
||||
if (denom == 0.) sgCopyVec3(p, u);
|
||||
else sgScaleVec3(p, d, sgScalarProductVec3(u,d) / denom);
|
||||
}
|
||||
|
||||
// Same thing, except using double precision
|
||||
void sgProjection(sgdVec3 p, const sgdVec3 u, const sgdVec3 d){
|
||||
double denom = sgdScalarProductVec3(d,d);
|
||||
if (denom == 0.) sgdCopyVec3(p, u);
|
||||
else sgdScaleVec3(p, d, sgdScalarProductVec3(u,d) / denom);
|
||||
}
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the closest point (p1) on the line
|
||||
void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d ) {
|
||||
|
||||
sgVec3 u, u1;
|
||||
|
||||
// u = p - p0
|
||||
sgSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
sgProjection(u1, u, d);
|
||||
|
||||
// calculate the point p1 along the line that is closest to p
|
||||
// p0 = p1 + u1
|
||||
sgAddVec3(p1, p0, u1);
|
||||
}
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the closest point (p1) on the line
|
||||
void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d ) {
|
||||
|
||||
sgdVec3 u, u1;
|
||||
|
||||
// u = p - p0
|
||||
sgdSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
sgProjection(u1, u, d);
|
||||
|
||||
// calculate the point p1 along the line that is closest to p
|
||||
// p0 = p1 + u1
|
||||
sgdAddVec3(p1, p0, u1);
|
||||
}
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the shortest distance (squared) from the point to the line
|
||||
double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d ) {
|
||||
|
||||
sgVec3 u, u1, v;
|
||||
|
||||
// u = p - p0
|
||||
sgSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
sgProjection(u1, u, d);
|
||||
|
||||
// v = u - u1 = vector from closest point on line, p1, to the
|
||||
// original point, p.
|
||||
sgSubVec3(v, u, u1);
|
||||
|
||||
return ( sgScalarProductVec3(v, v) );
|
||||
}
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the shortest distance (squared) from the point to the line
|
||||
double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d ) {
|
||||
|
||||
sgdVec3 u, u1, v;
|
||||
|
||||
// u = p - p0
|
||||
sgdSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
sgProjection(u1, u, d);
|
||||
|
||||
// v = u - u1 = vector from closest point on line, p1, to the
|
||||
// original point, p.
|
||||
sgdSubVec3(v, u, u1);
|
||||
|
||||
return ( sgdScalarProductVec3(v, v) );
|
||||
}
|
||||
|
||||
|
||||
// This is a quicker form of
|
||||
// sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
|
||||
// sgPostMultMat4( sgMat, sgTRANS );
|
||||
void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans )
|
||||
{
|
||||
for( int i=0; i<4; i++) {
|
||||
for( int j=0; j<3; j++ ) {
|
||||
src[i][j] += (src[i][3] * trans[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
/**
|
||||
* \file vector.hxx
|
||||
* Additional vector routines.
|
||||
*/
|
||||
|
||||
// Written by Curtis Olson, started December 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _VECTOR_HXX
|
||||
#define _VECTOR_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <plib/sg.h>
|
||||
|
||||
|
||||
/**
|
||||
* calculate the projection, p, of u along the direction of d.
|
||||
* @param p (out) the projection
|
||||
* @param u (in) the vector to be projected
|
||||
* @param d (in) the direction onto which we project
|
||||
*/
|
||||
void sgProjection(sgVec3 p, const sgVec3 u, const sgVec3 d);
|
||||
void sgProjection(sgdVec3 p, const sgdVec3 u, const sgdVec3 d);
|
||||
|
||||
|
||||
/**
|
||||
* Map i.e. project a vector onto a plane.
|
||||
* @param normal (in) normal vector for the plane
|
||||
* @param v0 (in) a point on the plane
|
||||
* @param vec (in) the vector to map onto the plane
|
||||
* @param result (out) the result vector
|
||||
*/
|
||||
inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
|
||||
sgVec3 v0,
|
||||
sgVec3 vec,
|
||||
sgVec3 result )
|
||||
{
|
||||
sgVec3 u1, v, tmp;
|
||||
|
||||
// calculate a vector "u1" representing the shortest distance from
|
||||
// the plane specified by normal and v0 to a point specified by
|
||||
// "vec". "u1" represents both the direction and magnitude of
|
||||
// this desired distance.
|
||||
|
||||
// u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
|
||||
|
||||
sgScaleVec3( u1,
|
||||
normal,
|
||||
( sgScalarProductVec3(normal, vec) /
|
||||
sgScalarProductVec3(normal, normal)
|
||||
)
|
||||
);
|
||||
|
||||
// printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]);
|
||||
// printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]);
|
||||
// printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]);
|
||||
|
||||
// calculate the vector "v" which is the vector "vec" mapped onto
|
||||
// the plane specified by "normal" and "v0".
|
||||
|
||||
// v = v0 + vec - u1
|
||||
|
||||
sgAddVec3(tmp, v0, vec);
|
||||
sgSubVec3(v, tmp, u1);
|
||||
// printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
|
||||
|
||||
// Calculate the vector "result" which is "v" - "v0" which is a
|
||||
// directional vector pointing from v0 towards v
|
||||
|
||||
// result = v - v0
|
||||
|
||||
sgSubVec3(result, v, v0);
|
||||
// printf(" result = %.2f, %.2f, %.2f\n",
|
||||
// result[0], result[1], result[2]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy and negate a vector.
|
||||
* @param dst (out) result vector
|
||||
* @param src (in) input vector
|
||||
*/
|
||||
inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src )
|
||||
{
|
||||
dst [ 0 ] = -src [ 0 ] ;
|
||||
dst [ 1 ] = -src [ 1 ] ;
|
||||
dst [ 2 ] = -src [ 2 ] ;
|
||||
dst [ 3 ] = -src [ 3 ] ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a point p, and a line through p0 with direction vector d,
|
||||
* find the closest point (p1) on the line (float version).
|
||||
* @param p1 (out) closest point to p on the line
|
||||
* @param p (in) original point
|
||||
* @param p0 (in) point on the line
|
||||
* @param d (in) vector defining line direction
|
||||
*/
|
||||
void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d );
|
||||
|
||||
/**
|
||||
* Given a point p, and a line through p0 with direction vector d,
|
||||
* find the closest point (p1) on the line (double version).
|
||||
* @param p1 (out) closest point to p on the line
|
||||
* @param p (in) original point
|
||||
* @param p0 (in) point on the line
|
||||
* @param d (in) vector defining line direction
|
||||
*/
|
||||
void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d );
|
||||
|
||||
/**
|
||||
* Given a point p, and a line through p0 with direction vector d,
|
||||
* find the shortest distance (squared) from the point to the line (float
|
||||
* version.)
|
||||
* @param p (in) original point
|
||||
* @param p0 (in) point on the line
|
||||
* @param d (in) vector defining line direction
|
||||
* @return shortest distance (squared) from p to line
|
||||
*/
|
||||
double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d );
|
||||
|
||||
/**
|
||||
* Given a point p, and a line through p0 with direction vector d,
|
||||
* find the shortest distance (squared) from the point to the line (double
|
||||
* version.)
|
||||
* @param p (in) original point
|
||||
* @param p0 (in) point on the line
|
||||
* @param d (in) vector defining line direction
|
||||
* @return shortest distance (squared) from p to line
|
||||
*/
|
||||
double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d );
|
||||
|
||||
/**
|
||||
* This is same as:
|
||||
*
|
||||
* <li> sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
|
||||
* <li> sgPostMultMat4( sgMat4 src, sgTRANS );
|
||||
*
|
||||
* @param src starting sgMat4 matrix
|
||||
* @param trans translation vector
|
||||
*/
|
||||
void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans );
|
||||
|
||||
|
||||
#endif // _VECTOR_HXX
|
||||
|
||||
|
||||
Reference in New Issue
Block a user