1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/****************************************************************************
Xplanet 0.94 - render an image of a planet into an X window
Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
****************************************************************************/
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
#include "Location.h"
#include "util.h"
Location::Location(const double r)
{
lon = 0.;
lat = 0.;
range = r;
}
Location::Location(const double latitude, const double longitude,
const double r)
{
lat = latitude;
lon = drem(longitude, TWO_PI);
range = r;
}
void
Location::setXYZ(const double a, const double b, const double c)
{
x = a;
y = b;
z = c;
range = sqrt(x*x + y*y + z*z);
}
double
Location::dot(const Location &l1)
{
return(x * l1.x + y * l1.y + z * l1.z);
}
void
Location::rotate(const double a[3][3])
{
double newx = a[0][0] * x + a[0][1] * y + a[0][2] * z;
double newy = a[1][0] * x + a[1][1] * y + a[1][2] * z;
double newz = a[2][0] * x + a[2][1] * y + a[2][2] * z;
x = newx;
y = newy;
z = newz;
}
void
Location::sphericalToRectangular()
{
double cos_lat = cos(lat);
x = range * cos(lon) * cos_lat;
y = range * sin(lon) * cos_lat;
z = range * sin(lat);
}
void
Location::rectangularToSpherical()
{
if (range == 0)
{
lat = 0;
lon = 0;
return;
}
lat = M_PI_2 - acos(z/range);
lon = atan2(y,x);
}
void
Location::print() const
{
cout << "x = " << x << "\ty = " << y << "\tz = " << z << endl
<< "lon = " << lon/deg_to_rad << "\tlat = " << lat/deg_to_rad
<< "\trange = " << range << endl;
}
|