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
/* 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
|| ( (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;
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));
}
}
/* 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
*
*/
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 );
$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!
/* $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 <pbleisch@acm.org> new debug message
* system and commandline/config file processing code.
/* 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
/* 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 );
$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.
/* $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
*
+++ /dev/null
-/**************************************************************************
- * 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 <math.h>
-#include <stdio.h>
-
-#include <Include/fg_constants.h>
-
-#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 <pbleisch@acm.org> 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 <rpk@sgi.com>
- * 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.
- * */
--- /dev/null
+/**************************************************************************
+ * 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 <math.h>
+#include <stdio.h>
+
+#include <Include/fg_constants.h>
+
+#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 <pbleisch@acm.org> 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 <rpk@sgi.com>
+ * 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.
+ * */
+++ /dev/null
-/**************************************************************************
- * 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 <Include/fg_types.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);
-
-
-/* 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 <pbleisch@acm.org> 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 <rpk@sgi.com>
- * 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.
- *
- */
--- /dev/null
+/**************************************************************************
+ * 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 <Include/fg_types.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 */
+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 <pbleisch@acm.org> 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 <rpk@sgi.com>
+ * 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.
+ *
+ */
+++ /dev/null
-/**************************************************************************
- * 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 <math.h>
-#include <stdio.h>
-
-#include <Math/vector.h>
-
-#include <Math/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 <dot> vec) / (normal <dot> 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 <rpk@sgi.com>
- * This should simplify things tremendously.
- *
- * Revision 1.1 1997/12/22 04:13:17 curt
- * Initial revision.
- *
- */
-
-
-
-
-
--- /dev/null
+/**************************************************************************
+ * 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 <math.h>
+#include <stdio.h>
+
+#include <Include/fg_types.h>
+
+#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 <dot> vec) / (normal <dot> 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 <rpk@sgi.com>
+ * This should simplify things tremendously.
+ *
+ * Revision 1.1 1997/12/22 04:13:17 curt
+ * Initial revision.
+ * */
+
+
+
+
+
+++ /dev/null
-/**************************************************************************
- * 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 <Math/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);
-
-
-#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 <rpk@sgi.com>
- * This should simplify things tremendously.
- *
- * Revision 1.1 1997/12/22 04:13:18 curt
- * Initial revision.
- *
- */
--- /dev/null
+/**************************************************************************
+ * 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 <Math/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);
+
+// 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 <rpk@sgi.com>
+ * This should simplify things tremendously.
+ *
+ * Revision 1.1 1997/12/22 04:13:18 curt
+ * Initial revision.
+ *
+ */