/*************************************************************************** spherical.cpp W. Michael Brown ------------------- Stuff for working spherical coordinates __________________________________________________________________________ Part of the Math Library __________________________________________________________________________ begin : Tue Aug 29 2006 copyright : (C) 2006 by W. Michael Brown email : wmbrown@sandia.gov ***************************************************************************/ #include "spherical.h" // Empty construct. Not necessarily initialized to [0 0] template Ball::Ball() { } // Assign theta and phi to the value template Ball::Ball(numtyp value) : theta(value), phi(value) { } // Assignment Constructor template Ball::Ball(numtyp thet, numtyp ph) : theta(thet), phi(ph) { } // Convert from cartesian template Ball::Ball(const ThreeD &pt) { theta=atan2(pt.y,pt.x); if (theta<0) theta+=TWOPI; phi=acos(pt.z/pt.norm()); } template numtyp & Ball::operator[](unsigned i) { if (i==THETA) return theta; else return phi; } template ostream & operator<< (ostream &out, const Ball &t) { out << t.theta << " " << t.phi; return out; } template istream & operator>> (istream &in, Ball &t) { in >> t.theta >> t.phi; return in; } // Distance between two points (along arc) template numtyp Ball::dist(const Ball &two) const { double dot=cPt(*this).dot(cPt(two)); if (dot>1.0) dot=1.0; return acos(dot); } // Distance squared between two points template numtyp Ball::dist2(const Ball &two) const { numtyp d=dist(two); return d*d; } // Add both angles template void Ball::operator += (const Ball &two) { theta+=two.theta; phi+=two.phi; } // Add to both angles template Ball Ball::operator + (const numtyp two) const { return Ball(theta+two,phi+two); } // Multiply both angles template Ball Ball::operator * (const numtyp two) const { return Ball(theta*two,phi*two); } // Divide both angles template void Ball::operator /= (const numtyp two) { theta/=two; phi/=two; } // Add both angles template Ball Ball::operator + (const Ball &two) { return Ball(theta+two.theta,phi+two.phi); } // Move coordinates into array template void Ball::to_array(numtyp *array) { *array=theta; array++; *array=phi; } // Set coordinates from array template void Ball::from_array(numtyp *array) { theta=*array; array++; phi=*array; } // Returns 2 template unsigned Ball::dimensionality() { return 2; } // Returns true template bool Ball::check_bounds(numtyp min,numtyp max) { return true; } template class Ball; template class Ball; template ostream & operator<< (ostream &out, const Ball &t); template ostream & operator<< (ostream &out, const Ball &t); template istream & operator>> (istream &in, Ball &t); template istream & operator>> (istream &in, Ball &t);