head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.39; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.56; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.02; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.58; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# polar3d.cxx

    00001 // polar.cxx -- routines to deal with polar math and transformations
    00002 //
    00003 // Written by Curtis Olson, started June 1997.
    00004 //
    00005 // Copyright (C) 1997  Curtis L. Olson  - curt@@infoplane.com
    00006 //
    00007 // This library is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU Library General Public
    00009 // License as published by the Free Software Foundation; either
    00010 // version 2 of the License, or (at your option) any later version.
    00011 //
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015 // Library General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Library General Public
    00018 // License along with this library; if not, write to the
    00019 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020 // Boston, MA  02111-1307, USA.
    00021 //
    00022 // $Id: polar3d.cxx,v 1.6 2001/03/24 03:20:47 curt Exp $
    00023
    00024
    00025 #include <math.h>
    00026 #include <stdio.h>
    00027
    00028 #include <simgear/constants.h>
    00029
    00030 #include "polar3d.hxx"
    00031
    00032
    00033 // Find the Altitude above the Ellipsoid (WGS84) given the Earth
    00034 // Centered Cartesian coordinate vector Distances are specified in
    00035 // meters.
    00036 double fgGeodAltFromCart(const Point3D& cp)
    00037 {
    00038     double t_lat, x_alpha, mu_alpha;
    00039     double lat_geoc, radius;
    00040     double result;
    00041
    00042     lat_geoc = SGD_PI_2 - atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() );
    00043     radius = sqrt( cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z() );
    00044
    00045     if( ( (SGD_PI_2 - lat_geoc) < SG_ONE_SECOND )        // near North pole
    00046         || ( (SGD_PI_2 + lat_geoc) < SG_ONE_SECOND ) )   // near South pole
    00047     {
    00048         result = radius - SG_EQUATORIAL_RADIUS_M*E;
    00049     } else {
    00050         t_lat = tan(lat_geoc);
    00051         x_alpha = E*SG_EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E);
    00052         mu_alpha = atan2(sqrt(SG_EQ_RAD_SQUARE_M - x_alpha*x_alpha),E*x_alpha);
    00053         if (lat_geoc < 0) {
    00054             mu_alpha = - mu_alpha;
    00055         }
    00056         result = (radius - x_alpha/cos(lat_geoc))*cos(mu_alpha - lat_geoc);
    00057     }
    00058
    00059     return(result);
    00060 }
    00061
    00062

@ 1.3 log @Oops, try again. @ text @d71 1 a71 1