# Object.cpp

Go to the documentation of this file.
```00001 /*
00002  * Copyright (c) 2004 CSIRO ICT Centre
00003  *
00004  * \$Id: Object.cpp 587 2004-12-03 15:06:33Z nch \$
00005  */
00006
00007 #include <iostream>
00008
00009 #include "Constants.h"
00010 #include "Object.h"
00011
00012 double Object::zAlpha = 1.0;
00013
00014
00015 Object::Object(double r, double d)
00016     : ra(r), dec(d)
00017 {
00018 }
00019
00020 void Object::print(std::ostream & os) const
00021 {
00022   os << getRa() << " " << getDec() << " " << getSD() << " "
00023      << getOrthoSD() << " " << getDecSD();
00024 }
00025
00026 double Object::computeDistanceBound(double redSD,
00027                                     double blueSD)
00028 {
00029   return zAlpha * std::sqrt(redSD * redSD + blueSD * blueSD);
00030 }
00031
00032 double Object::computeRACorrection(double radius, double dec)
00033 {
00035 }
00036
00037 /*
00038  * Calculates the great circle distance between two points.
00039  */
00040 double Object::gcDistance(Object const & other) const
00041 {
00042   double distance = 0.0;
00043
00044   if ((getDec() != other.getDec()) ||
00045       (getRa()  != other.getRa()))
00046   {
00047     distance = haversineDistance(other);
00048   }
00049
00050   return distance;
00051 }
00052
00053 /*
00054  * Calculates the great circle distance between two points.
00055  */
00056 double Object::haversineDistance(Object const & other) const
00057 {
00058   double distance = 0.0;
00059
00060   /* The haversine method */
00061   double sinTerm1 = Constants::sinDeg((getDec() - other.getDec())*0.5);
00062   double cosTerm1 = Constants::cosDeg(getDec());
00063   double cosTerm2 = Constants::cosDeg(other.getDec());
00064   double sinTerm2 = Constants::sinDeg((getRa() - other.getRa())*0.5);
00065
00066   double term = std::sqrt(sinTerm1*sinTerm1 + cosTerm1*cosTerm2*sinTerm2*sinTerm2);
00067
00068   if (term >= 1.0)
00069     distance = 180;
00070   else
00071     distance = 2.0 * Constants::asinDeg(term);
00072
00073   /* The cos method - less accurate for small angles */
00074 /*
00075   double cosDistance = Constants::sinDeg(getDec())
00076                      * Constants::sinDeg(other.getDec())
00077                      + Constants::cosDeg(getDec())
00078                      * Constants::cosDeg(other.getDec())
00079                      * Constants::cosDeg(getRa() - other.getRa());
00080
00081   distance = Constants::acosDeg(cosDistance);
00082 */
00083
00084   return distance;
00085 }
00086
00087 /* checks whether the angular separation between two objects is sufficiently
00088  * small that we cannot rule out the possibility that the two objects are
00089  * in fact spatially co-located.
00090  */
00091 bool Object::isSmallSeparation(Object const & other) const
00092 {
00093   bool isClose = false;
00094   if ((getDec() == other.getDec()) &&
00095       (getRa()  == other.getRa()))
00096   {
00097     isClose = true;
00098   }
00099   else
00100   {
00101     double distanceBound = computeDistanceBound(getSD(), other.getSD());
00102
00103     double distance = haversineDistance(other);
00104
00105     isClose = (distance <= distanceBound);
00106   }
00107
00108   return isClose;
00109 }
00110
00111 std::ostream & operator<<(std::ostream & os, Object const & obj)
00112 {
00113   obj.print(os);
00114
00115   return os;
00116 }
```
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  1.6.3