From: curt Date: Wed, 8 Jul 1998 14:40:07 +0000 (+0000) Subject: polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dbcecbd3b805ffd4f27d50fa726354a3290789ef;hp=4205c0a38db86c0721f8574dd7007fe49cfde968;p=flightgear.git polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx Updated fg_geodesy comments to reflect that routines expect and produce meters. --- diff --git a/Math/Makefile.am b/Math/Makefile.am index ee3eca0d5..a0fc42f09 100644 --- a/Math/Makefile.am +++ b/Math/Makefile.am @@ -10,7 +10,7 @@ libMath_la_SOURCES = \ fg_random.c fg_random.h \ interpolater.cxx interpolater.hxx \ mat3.h mat3defs.h mat3err.h \ - polar3d.c polar3d.h \ - vector.c vector.h + polar3d.cxx polar3d.hxx \ + vector.cxx vector.hxx INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --git a/Math/fg_geodesy.c b/Math/fg_geodesy.c index e86d8a3ec..c77c3daec 100644 --- a/Math/fg_geodesy.c +++ b/Math/fg_geodesy.c @@ -24,13 +24,13 @@ /* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r) * INPUTS: * lat_geoc Geocentric latitude, radians, + = North - * radius C.G. radius to earth center, ft + * radius C.G. radius to earth center (meters) * * OUTPUTS: * lat_geod Geodetic latitude, radians, + = North - * alt C.G. altitude above mean sea level, ft + * alt C.G. altitude above mean sea level (meters) * sea_level_r radius from earth center to sea level at - * local vertical (surface normal) of C.G. + * local vertical (surface normal) of C.G. (meters) */ void fgGeocToGeod( double lat_geoc, double radius, double @@ -43,12 +43,12 @@ void fgGeocToGeod( double lat_geoc, double radius, double || ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) /* near South pole */ { *lat_geod = lat_geoc; - *sea_level_r = EQUATORIAL_RADIUS_KM*E; + *sea_level_r = EQUATORIAL_RADIUS_M*E; *alt = radius - *sea_level_r; } else { t_lat = tan(lat_geoc); - x_alpha = E*EQUATORIAL_RADIUS_KM/sqrt(t_lat*t_lat + E*E); - mu_alpha = atan2(sqrt(RESQ_KM - x_alpha*x_alpha),E*x_alpha); + x_alpha = E*EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E); + mu_alpha = atan2(sqrt(RESQ_M - x_alpha*x_alpha),E*x_alpha); if (lat_geoc < 0) mu_alpha = - mu_alpha; sin_mu_a = sin(mu_alpha); delt_lambda = mu_alpha - lat_geoc; @@ -56,14 +56,14 @@ void fgGeocToGeod( double lat_geoc, double radius, double l_point = radius - r_alpha; *alt = l_point*cos(delt_lambda); denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a); - rho_alpha = EQUATORIAL_RADIUS_KM*(1-EPS)/ + rho_alpha = EQUATORIAL_RADIUS_M*(1-EPS)/ (denom*denom*denom); delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt); *lat_geod = mu_alpha - delt_mu; lambda_sl = atan( E*E * tan(*lat_geod) ); /* SL geoc. latitude */ sin_lambda_sl = sin( lambda_sl ); *sea_level_r = - sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); + sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); } } @@ -71,11 +71,11 @@ void fgGeocToGeod( double lat_geoc, double radius, double /* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc ) * INPUTS: * lat_geod Geodetic latitude, radians, + = North - * alt C.G. altitude above mean sea level, ft + * alt C.G. altitude above mean sea level (meters) * * OUTPUTS: - * sl_radius SEA LEVEL radius to earth center, ft (add Altitude to - * get true distance from earth center. + * sl_radius SEA LEVEL radius to earth center (meters) + * (add Altitude to get true distance from earth center. * lat_geoc Geocentric latitude, radians, + = North * */ @@ -91,7 +91,7 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, sin_mu = sin(lat_geod); /* Geodetic (map makers') latitude */ cos_mu = cos(lat_geod); *sl_radius = - sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); + sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); py = *sl_radius*sin_lambda_sl + alt*sin_mu; px = *sl_radius*cos_lambda_sl + alt*cos_mu; *lat_geoc = atan2( py, px ); @@ -140,6 +140,11 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, $Header$ $Log$ +Revision 1.6 1998/07/08 14:40:07 curt +polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +Updated fg_geodesy comments to reflect that routines expect and produce + meters. + Revision 1.5 1998/04/25 22:06:23 curt Edited cvs log messages in source files ... bad bad bad! @@ -208,9 +213,14 @@ Initial Flight Gear revision. /* $Log$ -/* Revision 1.5 1998/04/25 22:06:23 curt -/* Edited cvs log messages in source files ... bad bad bad! +/* Revision 1.6 1998/07/08 14:40:07 curt +/* polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +/* Updated fg_geodesy comments to reflect that routines expect and produce +/* meters. /* + * Revision 1.5 1998/04/25 22:06:23 curt + * Edited cvs log messages in source files ... bad bad bad! + * * Revision 1.4 1998/01/27 00:47:59 curt * Incorporated Paul Bleisch's new debug message * system and commandline/config file processing code. diff --git a/Math/fg_geodesy.h b/Math/fg_geodesy.h index a464516da..874acddd8 100644 --- a/Math/fg_geodesy.h +++ b/Math/fg_geodesy.h @@ -23,13 +23,13 @@ extern "C" { /* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r) * INPUTS: * lat_geoc Geocentric latitude, radians, + = North - * radius C.G. radius to earth center, ft + * radius C.G. radius to earth center (meters) * * OUTPUTS: * lat_geod Geodetic latitude, radians, + = North - * alt C.G. altitude above mean sea level, ft + * alt C.G. altitude above mean sea level (meters) * sea_level_r radius from earth center to sea level at - * local vertical (surface normal) of C.G. + * local vertical (surface normal) of C.G. (meters) */ void fgGeocToGeod( double lat_geoc, double radius, double @@ -38,17 +38,17 @@ void fgGeocToGeod( double lat_geoc, double radius, double /* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc ) * INPUTS: * lat_geod Geodetic latitude, radians, + = North - * alt C.G. altitude above mean sea level, ft + * alt C.G. altitude above mean sea level (meters) * * OUTPUTS: - * sl_radius SEA LEVEL radius to earth center, ft (add Altitude to - * get true distance from earth center. + * sl_radius SEA LEVEL radius to earth center (meters) + * (add Altitude to get true distance from earth center. * lat_geoc Geocentric latitude, radians, + = North * */ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, - double *lat_geoc ); + double *lat_geoc ); @@ -94,6 +94,11 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, $Header$ $Log$ +Revision 1.4 1998/07/08 14:40:08 curt +polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +Updated fg_geodesy comments to reflect that routines expect and produce + meters. + Revision 1.3 1998/04/21 17:03:48 curt Prepairing for C++ integration. @@ -160,9 +165,14 @@ Initial Flight Gear revision. /* $Log$ -/* Revision 1.3 1998/04/21 17:03:48 curt -/* Prepairing for C++ integration. +/* Revision 1.4 1998/07/08 14:40:08 curt +/* polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +/* Updated fg_geodesy comments to reflect that routines expect and produce +/* meters. /* + * Revision 1.3 1998/04/21 17:03:48 curt + * Prepairing for C++ integration. + * * Revision 1.2 1998/01/22 02:59:38 curt * Changed #ifdef FILE_H to #ifdef _FILE_H * diff --git a/Math/polar3d.c b/Math/polar3d.c deleted file mode 100644 index 53d8966bd..000000000 --- a/Math/polar3d.c +++ /dev/null @@ -1,91 +0,0 @@ -/************************************************************************** - * polar.c -- routines to deal with polar math and transformations - * - * Written by Curtis Olson, started June 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * (Log is kept at end of this file) - **************************************************************************/ - - -#include -#include - -#include - -#include "polar3d.h" - - -/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat - * must be specified in radians. The FG convention is for distances - * to be specified in meters */ -fgCartesianPoint3d fgPolarToCart3d(fgPolarPoint3d p) { - fgCartesianPoint3d pnew; - - pnew.x = cos(p.lon) * cos(p.lat) * p.radius; - pnew.y = sin(p.lon) * cos(p.lat) * p.radius; - pnew.z = sin(p.lat) * p.radius; - - return(pnew); -} - - -/* Convert a cartesian coordinate to polar coordinates (lon/lat - * specified in radians. Distances are specified in meters. */ -fgPolarPoint3d fgCartToPolar3d(fgCartesianPoint3d cp) { - fgPolarPoint3d pp; - - pp.lon = atan2( cp.y, cp.x ); - pp.lat = FG_PI_2 - atan2( sqrt(cp.x*cp.x + cp.y*cp.y), cp.z ); - pp.radius = sqrt(cp.x*cp.x + cp.y*cp.y + cp.z*cp.z); - - /* printf("lon = %.2f lat = %.2f radius = %.2f\n", - pp.lon, pp.lat, pp.radius); */ - return(pp); -} - - -/* $Log$ -/* Revision 1.2 1998/05/03 00:45:49 curt -/* Commented out a debugging printf. -/* - * Revision 1.1 1998/05/02 01:50:11 curt - * polar.[ch] renamed to polar3d.[ch] - * - * Revision 1.6 1998/04/25 22:06:23 curt - * Edited cvs log messages in source files ... bad bad bad! - * - * Revision 1.5 1998/01/27 00:48:00 curt - * Incorporated Paul Bleisch's new debug message - * system and commandline/config file processing code. - * - * Revision 1.4 1998/01/19 19:27:12 curt - * Merged in make system changes from Bob Kuehne - * This should simplify things tremendously. - * - * Revision 1.3 1997/12/15 23:54:54 curt - * Add xgl wrappers for debugging. - * Generate terrain normals on the fly. - * - * Revision 1.2 1997/07/31 22:52:27 curt - * Working on redoing internal coordinate systems & scenery transformations. - * - * Revision 1.1 1997/07/07 21:02:36 curt - * Initial revision. - * */ diff --git a/Math/polar3d.cxx b/Math/polar3d.cxx new file mode 100644 index 000000000..8052744fb --- /dev/null +++ b/Math/polar3d.cxx @@ -0,0 +1,96 @@ +/************************************************************************** + * polar.cxx -- routines to deal with polar math and transformations + * + * Written by Curtis Olson, started June 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include +#include + +#include + +#include "polar3d.hxx" + + +/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat + * must be specified in radians. The FG convention is for distances + * to be specified in meters */ +fgPoint3d fgPolarToCart3d(fgPoint3d p) { + fgPoint3d pnew; + + pnew.x = cos(p.lon) * cos(p.lat) * p.radius; + pnew.y = sin(p.lon) * cos(p.lat) * p.radius; + pnew.z = sin(p.lat) * p.radius; + + return(pnew); +} + + +/* Convert a cartesian coordinate to polar coordinates (lon/lat + * specified in radians. Distances are specified in meters. */ +fgPoint3d fgCartToPolar3d(fgPoint3d cp) { + fgPoint3d pp; + + pp.lon = atan2( cp.y, cp.x ); + pp.lat = FG_PI_2 - atan2( sqrt(cp.x*cp.x + cp.y*cp.y), cp.z ); + pp.radius = sqrt(cp.x*cp.x + cp.y*cp.y + cp.z*cp.z); + + /* printf("lon = %.2f lat = %.2f radius = %.2f\n", + pp.lon, pp.lat, pp.radius); */ + return(pp); +} + + +/* $Log$ +/* Revision 1.1 1998/07/08 14:40:08 curt +/* polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +/* Updated fg_geodesy comments to reflect that routines expect and produce +/* meters. +/* + * Revision 1.2 1998/05/03 00:45:49 curt + * Commented out a debugging printf. + * + * Revision 1.1 1998/05/02 01:50:11 curt + * polar.[ch] renamed to polar3d.[ch] + * + * Revision 1.6 1998/04/25 22:06:23 curt + * Edited cvs log messages in source files ... bad bad bad! + * + * Revision 1.5 1998/01/27 00:48:00 curt + * Incorporated Paul Bleisch's new debug message + * system and commandline/config file processing code. + * + * Revision 1.4 1998/01/19 19:27:12 curt + * Merged in make system changes from Bob Kuehne + * This should simplify things tremendously. + * + * Revision 1.3 1997/12/15 23:54:54 curt + * Add xgl wrappers for debugging. + * Generate terrain normals on the fly. + * + * Revision 1.2 1997/07/31 22:52:27 curt + * Working on redoing internal coordinate systems & scenery transformations. + * + * Revision 1.1 1997/07/07 21:02:36 curt + * Initial revision. + * */ diff --git a/Math/polar3d.h b/Math/polar3d.h deleted file mode 100644 index 806f27e56..000000000 --- a/Math/polar3d.h +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************************************** - * polar.h -- routines to deal with polar math and transformations - * - * Written by Curtis Olson, started June 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * (Log is kept at end of this file) - **************************************************************************/ - - -#ifndef _POLAR_H -#define _POLAR_H - - -#ifdef __cplusplus -extern "C" { -#endif - - -#include - - -/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat - * must be specified in radians. The FG convention is for distances - * to be specified in meters */ -fgCartesianPoint3d fgPolarToCart3d(fgPolarPoint3d p); - - -/* Convert a cartesian coordinate to polar coordinates (lon/lat - * specified in radians. Distances are specified in meters. */ -fgPolarPoint3d fgCartToPolar3d(fgCartesianPoint3d cp); - - -#ifdef __cplusplus -} -#endif - - -#endif /* _POLAR_H */ - - -/* $Log$ -/* Revision 1.1 1998/05/02 01:50:11 curt -/* polar.[ch] renamed to polar3d.[ch] -/* - * Revision 1.9 1998/04/25 22:06:23 curt - * Edited cvs log messages in source files ... bad bad bad! - * - * Revision 1.8 1998/04/21 17:03:50 curt - * Prepairing for C++ integration. - * - * Revision 1.7 1998/01/27 00:48:00 curt - * Incorporated Paul Bleisch's new debug message - * system and commandline/config file processing code. - * - * Revision 1.6 1998/01/22 02:59:39 curt - * Changed #ifdef FILE_H to #ifdef _FILE_H - * - * Revision 1.5 1998/01/19 19:27:13 curt - * Merged in make system changes from Bob Kuehne - * This should simplify things tremendously. - * - * Revision 1.4 1997/12/15 23:54:55 curt - * Add xgl wrappers for debugging. - * Generate terrain normals on the fly. - * - * Revision 1.3 1997/07/31 22:52:28 curt - * Working on redoing internal coordinate systems & scenery transformations. - * - * Revision 1.2 1997/07/23 21:52:21 curt - * Put comments around the text after an #endif for increased portability. - * - * Revision 1.1 1997/07/07 21:02:37 curt - * Initial revision. - * - */ diff --git a/Math/polar3d.hxx b/Math/polar3d.hxx new file mode 100644 index 000000000..a65579051 --- /dev/null +++ b/Math/polar3d.hxx @@ -0,0 +1,92 @@ +/************************************************************************** + * polar.hxx -- routines to deal with polar math and transformations + * + * Written by Curtis Olson, started June 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#ifndef _POLAR_HXX +#define _POLAR_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + + +/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat + * must be specified in radians. The FG convention is for distances + * to be specified in meters */ +fgPoint3d fgPolarToCart3d(fgPoint3d p); + + +/* Convert a cartesian coordinate to polar coordinates (lon/lat + * specified in radians. Distances are specified in meters. */ +fgPoint3d fgCartToPolar3d(fgPoint3d cp); + + +#endif /* _POLAR_HXX */ + + +/* $Log$ +/* Revision 1.1 1998/07/08 14:40:09 curt +/* polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +/* Updated fg_geodesy comments to reflect that routines expect and produce +/* meters. +/* + * Revision 1.1 1998/05/02 01:50:11 curt + * polar.[ch] renamed to polar3d.[ch] + * + * Revision 1.9 1998/04/25 22:06:23 curt + * Edited cvs log messages in source files ... bad bad bad! + * + * Revision 1.8 1998/04/21 17:03:50 curt + * Prepairing for C++ integration. + * + * Revision 1.7 1998/01/27 00:48:00 curt + * Incorporated Paul Bleisch's new debug message + * system and commandline/config file processing code. + * + * Revision 1.6 1998/01/22 02:59:39 curt + * Changed #ifdef FILE_H to #ifdef _FILE_H + * + * Revision 1.5 1998/01/19 19:27:13 curt + * Merged in make system changes from Bob Kuehne + * This should simplify things tremendously. + * + * Revision 1.4 1997/12/15 23:54:55 curt + * Add xgl wrappers for debugging. + * Generate terrain normals on the fly. + * + * Revision 1.3 1997/07/31 22:52:28 curt + * Working on redoing internal coordinate systems & scenery transformations. + * + * Revision 1.2 1997/07/23 21:52:21 curt + * Put comments around the text after an #endif for increased portability. + * + * Revision 1.1 1997/07/07 21:02:37 curt + * Initial revision. + * + */ diff --git a/Math/vector.c b/Math/vector.c deleted file mode 100644 index 48fb9cd76..000000000 --- a/Math/vector.c +++ /dev/null @@ -1,97 +0,0 @@ -/************************************************************************** - * vector.c -- additional vector routines - * - * Written by Curtis Olson, started December 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * (Log is kept at end of this file) - **************************************************************************/ - - -#include -#include - -#include - -#include - - -/* Map a vector onto the plane specified by normal */ -void map_vec_onto_cur_surface_plane(MAT3vec normal, MAT3vec v0, MAT3vec vec, - MAT3vec result) -{ - MAT3vec 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 vec) / (normal normal) ) * normal */ - - MAT3_SCALE_VEC( u1, - normal, - ( MAT3_DOT_PRODUCT(normal, vec) / - MAT3_DOT_PRODUCT(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 */ - - MAT3_ADD_VEC(tmp, v0, vec); - MAT3_SUB_VEC(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 */ - - MAT3_SUB_VEC(result, v, v0); - /* printf(" result = %.2f, %.2f, %.2f\n", - result[0], result[1], result[2]); */ -} - - -/* $Log$ -/* Revision 1.3 1998/05/07 23:04:28 curt -/* Added a blank formating line! -/* - * Revision 1.2 1998/01/19 19:27:13 curt - * Merged in make system changes from Bob Kuehne - * This should simplify things tremendously. - * - * Revision 1.1 1997/12/22 04:13:17 curt - * Initial revision. - * - */ - - - - - diff --git a/Math/vector.cxx b/Math/vector.cxx new file mode 100644 index 000000000..4da0af44f --- /dev/null +++ b/Math/vector.cxx @@ -0,0 +1,130 @@ +/************************************************************************** + * vector.c -- additional vector routines + * + * Written by Curtis Olson, started December 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include +#include + +#include + +#include "vector.hxx" + +#include "mat3.h" + + +/* Map a vector onto the plane specified by normal */ +void map_vec_onto_cur_surface_plane(MAT3vec normal, MAT3vec v0, MAT3vec vec, + MAT3vec result) +{ + MAT3vec 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 vec) / (normal normal) ) * normal */ + + MAT3_SCALE_VEC( u1, + normal, + ( MAT3_DOT_PRODUCT(normal, vec) / + MAT3_DOT_PRODUCT(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 */ + + MAT3_ADD_VEC(tmp, v0, vec); + MAT3_SUB_VEC(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 */ + + MAT3_SUB_VEC(result, v, v0); + /* printf(" result = %.2f, %.2f, %.2f\n", + result[0], result[1], result[2]); */ +} + + +// Given a point p, and a line through p0 with direction vector d, +// find the shortest distance from the point to the line +double fgPointLine(MAT3vec p, MAT3vec p0, MAT3vec d) { + MAT3vec u, u1, v; + double ud, dd, tmp, dist; + + // u = p - p0 + MAT3_SUB_VEC(u, p, p0); + + // calculate the projection, u1, of u along d. + // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d; + ud = MAT3_DOT_PRODUCT(u, d); + dd = MAT3_DOT_PRODUCT(d, d); + tmp = ud / dd; + + MAT3_SCALE_VEC(u1, d, tmp);; + + // v = u - u1 = vector from closest point on line, p1, to the + // original point, p. + MAT3_SUB_VEC(v, u, u1); + + dist = sqrt(MAT3_DOT_PRODUCT(v, v)); + + return( dist ); +} + + +/* $Log$ +/* Revision 1.1 1998/07/08 14:40:10 curt +/* polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +/* Updated fg_geodesy comments to reflect that routines expect and produce +/* meters. +/* + * Revision 1.3 1998/05/07 23:04:28 curt + * Added a blank formating line! + * + * Revision 1.2 1998/01/19 19:27:13 curt + * Merged in make system changes from Bob Kuehne + * This should simplify things tremendously. + * + * Revision 1.1 1997/12/22 04:13:17 curt + * Initial revision. + * */ + + + + + diff --git a/Math/vector.h b/Math/vector.h deleted file mode 100644 index 097a21245..000000000 --- a/Math/vector.h +++ /dev/null @@ -1,66 +0,0 @@ -/************************************************************************** - * vector.h -- additional vector routines - * - * Written by Curtis Olson, started December 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * (Log is kept at end of this file) - **************************************************************************/ - - -#ifndef _VECTOR_H -#define _VECTOR_H - - -#ifdef __cplusplus -extern "C" { -#endif - - -#include - - -/* Map a vector onto the plane specified by normal */ -void map_vec_onto_cur_surface_plane(MAT3vec normal, MAT3vec v0, MAT3vec vec, - MAT3vec result); - - -#ifdef __cplusplus -} -#endif - - -#endif /* _VECTOR_H */ - - -/* $Log$ -/* Revision 1.4 1998/04/21 17:03:51 curt -/* Prepairing for C++ integration. -/* - * Revision 1.3 1998/01/22 02:59:39 curt - * Changed #ifdef FILE_H to #ifdef _FILE_H - * - * Revision 1.2 1998/01/19 19:27:14 curt - * Merged in make system changes from Bob Kuehne - * This should simplify things tremendously. - * - * Revision 1.1 1997/12/22 04:13:18 curt - * Initial revision. - * - */ diff --git a/Math/vector.hxx b/Math/vector.hxx new file mode 100644 index 000000000..d57a3108a --- /dev/null +++ b/Math/vector.hxx @@ -0,0 +1,70 @@ +/************************************************************************** + * vector.hxx -- additional vector routines + * + * Written by Curtis Olson, started December 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#ifndef _VECTOR_HXX +#define _VECTOR_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + + +/* Map a vector onto the plane specified by normal */ +void map_vec_onto_cur_surface_plane(MAT3vec normal, MAT3vec v0, MAT3vec vec, + MAT3vec result); + +// Given a point p, and a line through p0 with direction vector d, +// find the shortest distance from the point to the line +double fgPointLine(MAT3vec p, MAT3vec p0, MAT3vec d); + + +#endif /* _VECTOR_HXX */ + + +/* $Log$ +/* Revision 1.1 1998/07/08 14:40:10 curt +/* polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx +/* Updated fg_geodesy comments to reflect that routines expect and produce +/* meters. +/* + * Revision 1.4 1998/04/21 17:03:51 curt + * Prepairing for C++ integration. + * + * Revision 1.3 1998/01/22 02:59:39 curt + * Changed #ifdef FILE_H to #ifdef _FILE_H + * + * Revision 1.2 1998/01/19 19:27:14 curt + * Merged in make system changes from Bob Kuehne + * This should simplify things tremendously. + * + * Revision 1.1 1997/12/22 04:13:18 curt + * Initial revision. + * + */