satgeometry.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1999 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the MASH Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Research Group may be
00019  *    used to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Contributed by Tom Henderson, UCB Daedalus Research Group, June 1999
00035  */
00036 
00037 #ifndef lint
00038 static const char rcsid[] =
00039     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/satellite/satgeometry.cc,v 1.6 2001/05/21 19:27:31 haldar Exp $";
00040 #endif
00041 
00042 #include "satgeometry.h"
00043 #include "satposition.h"
00044 
00045 
00046 static class SatGeometryClass : public TclClass {
00047 public:
00048         SatGeometryClass() : TclClass("SatGeometry") {}
00049         TclObject* create(int, const char*const*) {
00050                 return (new SatGeometry());
00051         }
00052 } class_sat_geometry;
00053 
00054 
00055 // Returns the distance in km between points a and b
00056 double SatGeometry::distance(coordinate a, coordinate b)
00057 {
00058         double a_x, a_y, a_z, b_x, b_y, b_z;     // cartesian
00059     spherical_to_cartesian(a.r, a.theta, a.phi, a_x, a_y, a_z);
00060     spherical_to_cartesian(b.r, b.theta, b.phi, b_x, b_y, b_z);
00061         return (BaseTrace::round(DISTANCE(a_x, a_y, a_z, b_x, b_y, b_z), 1.0E+8));
00062 
00063 
00064 }
00065 
00066 void SatGeometry::spherical_to_cartesian(double R, double Theta,
00067     double Phi, double &X, double &Y, double &Z)
00068 {      
00069     X = R * sin(Theta) * cos (Phi);
00070     Y = R * sin(Theta) * sin (Phi);
00071     Z = R * cos(Theta);
00072 }
00073 
00074 // Propagation delay is the distance divided by the speed of light
00075 double SatGeometry::propdelay(coordinate a, coordinate b)
00076 {
00077     double delay = distance(a, b)/LIGHT;
00078     return (BaseTrace::round(delay, 1.0E+8));
00079 }
00080 
00081 double SatGeometry::get_altitude(coordinate a)
00082 {
00083         return (a.r - EARTH_RADIUS);
00084 }
00085 
00086 // Returns latitude in radians, in the range from -PI/2 to PI/2
00087 double SatGeometry::get_latitude(coordinate a)
00088 {
00089         return (PI/2 - a.theta);
00090 }
00091 
00092 // Returns (earth-centric) longitude corresponding to the position of the node 
00093 // (the input coordinate corresponds to fixed coordinate system, through
00094 // which the Earth rotates, so we have to scale back the effects of rotation).
00095 // The return value ranges from -PI to PI.
00096 double SatGeometry::get_longitude(coordinate coord_)
00097 {
00098         double period = EARTH_PERIOD; // period of earth in seconds
00099         // adjust longitude so that it is earth-centric (i.e., account
00100         // for earth rotating beneath).   
00101         double earth_longitude = fmod((coord_.phi -
00102            (fmod(NOW + SatPosition::time_advance_,period)/period) * 2*PI), 
00103         2*PI);
00104     // Bring earth_longitude to be within (-PI, PI)
00105         if (earth_longitude < (-1*PI))
00106         earth_longitude = 2*PI + earth_longitude;
00107         if (earth_longitude > PI)
00108         earth_longitude = (-(2*PI - earth_longitude));
00109     if (fabs(earth_longitude) < 0.0001)
00110         return 0;   // To avoid trace output of "-0.00"
00111     else
00112         return (earth_longitude);
00113 }       
00114 
00115 // If the satellite is above the elevation mask of the terminal, returns 
00116 // the elevation mask in radians; otherwise, returns 0.
00117 double SatGeometry::check_elevation(coordinate satellite,
00118     coordinate terminal, double elev_mask_)
00119 {
00120     double S = satellite.r;  // satellite radius
00121     double S_2 = satellite.r * satellite.r;  // satellite radius^2
00122     double E = EARTH_RADIUS;
00123     double E_2 = E * E;
00124     double d, theta, alpha;
00125 
00126     d = distance(satellite, terminal);
00127     if (d < sqrt(S_2 - E_2)) {
00128         // elevation angle > 0
00129         theta = acos((E_2+S_2-(d*d))/(2*E*S));
00130         alpha = acos(sin(theta) * S/d);
00131         return ( (alpha > elev_mask_) ? alpha : 0);
00132     } else
00133         return 0;
00134 }
00135 
00136 // This function determines whether two satellites are too far apart
00137 // to establish an ISL between them, due to Earth atmospheric grazing
00138 // (or shadowing by the Earth itself).  Assumes that both satellites nodes
00139 // are at the same altitude.  The line between the two satellites can be
00140 // bisected, and a perpendicular from that point to the Earth's center will
00141 // form a right triangle.  If the length of this perpendicular is less than
00142 // EARTH_RADIUS + ATMOS_MARGIN, the link cannot be established.
00143 //
00144 int SatGeometry::are_satellites_mutually_visible(coordinate first, coordinate second)
00145 {
00146     // if we drop a perpendicular from the ISL to the Earth's surface,
00147     // we have a right triangle.  The atmospheric margin is the minimum
00148     // ISL grazing altitude.
00149     double c, d, min_radius, grazing_radius;
00150     double radius = get_radius(first); // could just use first.r here.
00151     double distance_ = distance(first, second);
00152     c = radius * radius;
00153     d = (distance_/2) * (distance_/2);
00154     grazing_radius = (EARTH_RADIUS + ATMOS_MARGIN);
00155     min_radius = sqrt(c - d);
00156     if (min_radius >= grazing_radius) {
00157         return TRUE;
00158     } else {
00159         return FALSE;
00160     }
00161 }
00162 

Generated on Tue Mar 6 16:47:50 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6