From: curt Date: Sat, 2 May 1998 01:50:09 +0000 (+0000) Subject: polar.[ch] renamed to polar3d.[ch] X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5eef0e61ba484268e638d694bec08673cd52a219;p=simgear.git polar.[ch] renamed to polar3d.[ch] --- diff --git a/Math/Makefile.am b/Math/Makefile.am index 6d743e92..ee3eca0d 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 \ - polar.c polar.h \ + polar3d.c polar3d.h \ vector.c vector.h INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --git a/Math/Makefile.in b/Math/Makefile.in index 28c6909e..695f7e90 100644 --- a/Math/Makefile.in +++ b/Math/Makefile.in @@ -82,7 +82,7 @@ libMath_la_SOURCES = \ fg_random.c fg_random.h \ interpolater.cxx interpolater.hxx \ mat3.h mat3defs.h mat3err.h \ - polar.c polar.h \ + polar3d.c polar3d.h \ vector.c vector.h mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../../Include/config.h @@ -101,7 +101,7 @@ X_PRE_LIBS = @X_PRE_LIBS@ libMath_la_LDFLAGS = libMath_la_LIBADD = libMath_la_OBJECTS = MAT3geom.lo MAT3inv.lo MAT3mat.lo MAT3vec.lo \ -fg_geodesy.lo fg_random.lo interpolater.lo polar.lo vector.lo +fg_geodesy.lo fg_random.lo interpolater.lo polar3d.lo vector.lo CXXFLAGS = @CXXFLAGS@ CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) @@ -119,7 +119,7 @@ TAR = tar GZIP = --best DEP_FILES = .deps/MAT3geom.P .deps/MAT3inv.P .deps/MAT3mat.P \ .deps/MAT3vec.P .deps/fg_geodesy.P .deps/fg_random.P \ -.deps/interpolater.P .deps/polar.P .deps/vector.P +.deps/interpolater.P .deps/polar3d.P .deps/vector.P CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) SOURCES = $(libMath_la_SOURCES) OBJECTS = $(libMath_la_OBJECTS) diff --git a/Math/polar.c b/Math/polar.c deleted file mode 100644 index ad157643..00000000 --- a/Math/polar.c +++ /dev/null @@ -1,124 +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 - - -/* we can save these values between calls for efficiency */ -static double st, ct, sp, cp; - - -/* 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 */ -struct fgCartesianPoint fgPolarToCart(double lon, double lat, double radius) { - struct fgCartesianPoint pnew; - - pnew.x = cos(lon) * cos(lat) * radius; - pnew.y = sin(lon) * cos(lat) * radius; - pnew.z = sin(lat) * radius; - - return(pnew); -} - - -/* Precalculate as much as possible so we can do a batch of transforms - * through the same angles, will rotates a cartesian point about the - * center of the earth by Theta (longitude axis) and Phi (latitude - * axis) */ - -/* Here are the unoptimized transformation equations - - x' = cos(Phi) * cos(Theta) * x + cos(Phi) * sin(Theta) * y + - sin(Phi) * z - y' = -sin(Theta) * x + cos(Theta) * y - z' = -sin(Phi) * sin(Theta) * y - sin(Phi) * cos(Theta) * x + - cos(Phi) * z; - - */ -void fgRotateBatchInit(double Theta, double Phi) { - printf("Theta = %.3f, Phi = %.3f\n", Theta, Phi); - - st = sin(Theta); - ct = cos(Theta); - sp = sin(-Phi); - cp = cos(-Phi); -} - -/* Rotates a cartesian point about the center of the earth by Theta - * (longitude axis) and Phi (latitude axis) */ -struct fgCartesianPoint fgRotateCartesianPoint(struct fgCartesianPoint p) { - struct fgCartesianPoint p1, p2; - - /* printf("start = %.3f %.3f %.3f\n", p.x, p.y, p.z); */ - - /* rotate about the z axis */ - p1.x = ct * p.x - st * p.y; - p1.y = st * p.x + ct * p.y; - p1.z = p.z; - - /* printf("step 1 = %.3f %.3f %.3f\n", p1.x, p1.y, p1.z); */ - - /* rotate new point about y axis */ - p2.x = cp * p1.x + sp * p1.z; - p2.y = p1.y; - p2.z = cp * p1.z - sp * p1.x; - - /* printf("cp = %.5f, sp = %.5f\n", cp, sp); */ - /* printf("(1) = %.5f, (2) = %.5f\n", cp * p1.z, sp * p1.x); */ - - /* printf("step 2 = %.3f %.3f %.3f\n", p2.x, p2.y, p2.z); */ - - return(p2); -} - - -/* $Log$ -/* 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/polar.h b/Math/polar.h deleted file mode 100644 index bf3b1514..00000000 --- a/Math/polar.h +++ /dev/null @@ -1,106 +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 */ -struct fgCartesianPoint fgPolarToCart(double lon, double lat, double radius); - - -/* Precalculate as much as possible so we can do a batch of transforms - * through the same angles, will rotates a cartesian point about the - * center of the earth by Theta (longitude axis) and Phi (latitude - * axis) */ - -/* Here are the unoptimized transformation equations - - x' = cos(Phi) * cos(Theta) * x + cos(Phi) * sin(Theta) * y + - sin(Phi) * z - y' = -sin(Theta) * x + cos(Theta) * y - z' = -sin(Phi) * sin(Theta) * y - sin(Phi) * cos(Theta) * x + - cos(Phi) * z; - - */ -void fgRotateBatchInit(double Theta, double Phi); - - -/* Rotates a cartesian point about the center of the earth by Theta - * (longitude axis) and Phi (latitude axis) */ -struct fgCartesianPoint fgRotateCartesianPoint(struct fgCartesianPoint p); - - -#ifdef __cplusplus -} -#endif - - -#endif /* _POLAR_H */ - - -/* $Log$ -/* 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.c b/Math/polar3d.c new file mode 100644 index 00000000..629cac74 --- /dev/null +++ b/Math/polar3d.c @@ -0,0 +1,88 @@ +/************************************************************************** + * 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 = %.l2f lat = %.l2f radius = %.l2f\n", + pp.lon, pp.lat, pp.radius); + return(pp); +} + + +/* $Log$ +/* 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 new file mode 100644 index 00000000..806f27e5 --- /dev/null +++ b/Math/polar3d.h @@ -0,0 +1,92 @@ +/************************************************************************** + * 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. + * + */