-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrPoint2D.cpp
More file actions
219 lines (206 loc) · 3.48 KB
/
rPoint2D.cpp
File metadata and controls
219 lines (206 loc) · 3.48 KB
1
//#include <iostream.h>#include "rPoint2D.h"#include "rLatLon.h"#include "rLatLonint.h"#include "rPoint.h"#include "rVector.h"using std::ostream;rPoint2D::rPoint2D () {};rPoint2D::rPoint2D (double i,double j){ x = i; y = j;}rPoint2D::rPoint2D (rPoint pt) { *this = pt;}rPoint2D::rPoint2D (rVector pt) { *this = pt;}rPoint2D& rPoint2D::operator=(rPoint2D p){ x = p.x; y = p.y; return (*this);}rPoint2D& rPoint2D::operator=(rLatLon p){/* double x = ((double)p.lonmin+(double)p.lonsec/100.0)*DEGTORAD; double y = ((double)p.latmin+(double)p.latsec/100.0)*DEGTORAD;*/ x = p.lon*DEGTORAD; y = p.lat*DEGTORAD; return (*this);}rPoint2D& rPoint2D::operator=(rLatLonint p){/* double x = ((double)p.lonmin+(double)p.lonsec/100.0)*DEGTORAD; double y = ((double)p.latmin+(double)p.latsec/100.0)*DEGTORAD;*/ x = p.lon*DEGTORAD; y = p.lat*DEGTORAD; return (*this);}rPoint2D& rPoint2D::operator=(rVector &p){ *this = p; return (*this);}rPoint2D& rPoint2D::operator=(rPoint p){ double r,tht,phi; double o,ph;//#define PI 3.14159265358979323 r = sqrt (p.x*p.x + p.y*p.y + p.z*p.z); if (p.x != 0) { o = atan2 (p.y,p.x); } else { if (p.y < 0) { o = -PI/2.0; } else { o = PI/2.0; } }//cerr <<"rVector to rPoint2d "<<x<<" "<<y<<" "<<z<<" "<<r<<" "<<o<<"\n"; if (r != 0.0) { ph = acos (p.z/(r)); } else { ph = 0.0; } phi = PI/2.0-ph; tht = o;//cerr <<"phi:"<<phi*180.0/PI<<" theta:"<<tht*180.0/PI<<endl; x = tht; y = phi; return (*this);}/*rPoint2D::operator rLatLon(){ rLatLon p; p.lon = x*180.0/PI; p.lat = y*180.0/PI; return p;}*/ostream& operator<<(ostream& os, rPoint2D& p){ os << "("; os << p.x <<','<<p.y; os << ")"; return os;} rPoint2D& rPoint2D::set(double i,double j){ x = i; y = j; return (*this);}/*assign an array of three values to the rPoint */rPoint2D& rPoint2D::operator&=(double *p){ x = *p; y = *(p+1); return (*this);}/*void rPoint2D::dout (){ cout <<" x:"<< x <<" y:"<<y<<'\n';}*//* Add two rPoints. */rPoint2D operator+(rPoint2D a,rPoint2D b){ rPoint2D c(a.x+b.x,a.y+b.y); return c;}rPoint2D& rPoint2D::operator+=(rPoint2D b){ x += b.x; y += b.y; return (*this);}rPoint2D& rPoint2D::operator+(double s){ x += s; y += s; return (*this);}rPoint2D& rPoint2D::operator+=(double s){ x += s; y += s; return (*this);}/* Subtract two rPoints. */rPoint2D operator-(rPoint2D a,rPoint2D b){ rPoint2D c(a.x-b.x,a.y-b.y); return c;}rPoint2D& rPoint2D::operator-=(rPoint2D b){ x -= b.x; y -= b.y; return (*this);}rPoint2D& rPoint2D::operator-(double s){ x -= s; y -= s; return (*this);}rPoint2D& rPoint2D::operator-=(double s){ x -= s; y -= s; return (*this);}/* Multiply two rPoints. */rPoint2D operator*(rPoint2D a,rPoint2D b){ rPoint2D c(a.x*b.x,a.y*b.y); return c;}rPoint2D& rPoint2D::operator*=(rPoint2D b){ x *= b.x; y *= b.y; return (*this);}rPoint2D& rPoint2D::operator*(double s){ x *= s; y *= s; return (*this);}rPoint2D& rPoint2D::operator*=(double s){ x *= s; y *= s; return (*this);}/* Divide two rPoints. */rPoint2D operator/(rPoint2D a,rPoint2D b){ rPoint2D c(a.x/b.x,a.y/b.y); return c;}rPoint2D& rPoint2D::operator/=(rPoint2D b){ x /= b.x; y /= b.y; return (*this);}rPoint2D& rPoint2D::operator/(double s){ x /= s; y /= s; return (*this);}rPoint2D& rPoint2D::operator/=(double s){ x /= s; y /= s; return (*this);}