LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
SpatialUtils.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
29 
30 #include <cfloat>
31 
32 #include "lsst/pex/exceptions.h"
33 #include "lsst/ap/constants.h"
34 
35 using lsst::pex::exceptions::InvalidParameterError;
36 using lsst::pex::exceptions::RuntimeError;
37 
44 
45 
46 namespace lsst { namespace ap { namespace utils {
47 
57  if (min > max) {
58  if (max < 0.0 || min >= TWOPI) {
59  throw LSST_EXCEPT(InvalidParameterError,
60  "Invalid longitude angle interval");
61  }
62  } else if (max - min >= TWOPI) {
63  min = 0.0 * radians;
64  max = TWOPI * radians;
65  } else if (min < 0.0 || max >= TWOPI) {
66  // range reduce
67  min.wrap();
68  max.wrap();
69  }
70 }
71 
80  Angle radius,
81  Angle centerPhi
82 ) {
83  static const double POLE_EPSILON = 1e-7;
84 
85  if (radius < 0.0 || radius > HALFPI) {
86  throw LSST_EXCEPT(InvalidParameterError,
87  "radius must be in range [0, PI/2] deg");
88  }
89  if (radius == 0.0) {
90  return 0.0 * radians;
91  }
92  centerPhi = clampPhi(centerPhi);
93  if (std::fabs(centerPhi.asRadians()) + radius.asRadians() > HALFPI - POLE_EPSILON) {
94  return PI*(1 + 2.0*DBL_EPSILON) * radians;
95  }
96  double y = std::sin(radius.asRadians());
97  double x = std::sqrt(std::fabs(std::cos(centerPhi.asRadians() - radius.asRadians()) *
98  std::cos(centerPhi.asRadians() + radius.asRadians())));
99  return std::fabs(std::atan(y / x)) * radians;
100 }
101 
127  Eigen::Vector3d &p,
128  Eigen::Vector3d &v,
129  Angle ra,
130  Angle decl,
131  double muRa,
132  double muDecl,
133  double vRadial,
134  Angle parallax
135 ) {
136  // distance (AU)
137  double r = 1.0 / parallax.asRadians();
138 
139  // convert to position and velocity vector (AU, AU/day)
140  double sinRa = sin(ra.asRadians());
141  double cosRa = cos(ra.asRadians());
142  double sinDecl = sin(decl.asRadians());
143  double cosDecl = cos(decl.asRadians());
144  double s = r*cosDecl;
145  double t = r*muDecl*sinDecl;
146  double u = cosDecl*vRadial;
147  p = Eigen::Vector3d(s*cosRa, s*sinRa, r*sinDecl);
148  v = Eigen::Vector3d(cosRa*u - p.y()*muRa - cosRa*t,
149  sinRa*u + p.x()*muRa - sinRa*t,
150  sinDecl*vRadial + s*muDecl);
151  if (v.squaredNorm() > 0.25*C_AU_PER_DAY*C_AU_PER_DAY) {
152  throw LSST_EXCEPT(RuntimeError,
153  "star velocity vector magnitude exceeds half "
154  "the speed of light");
155  }
156 }
157 
161 Eigen::Vector2d const cartesianToSpherical(Eigen::Vector3d const &v) {
162  double d2 = v.x()*v.x() + v.y()*v.y();
163  double theta = (d2 == 0.0) ? 0.0 : std::atan2(v.y(), v.x());
164  double phi = (v.z() == 0.0) ? 0.0 : std::atan2(v.z(), std::sqrt(d2));
165  return Eigen::Vector2d(theta, phi);
166 }
167 
168 }}} // namespace lsst::ap::utils
169 
int y
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
lsst::afw::coord::IcrsCoord IcrsCoord
Definition: misc.h:41
double const TWOPI
Definition: Angle.h:19
Eigen::Vector2d const cartesianToSpherical(Eigen::Vector3d const &v)
double min
Definition: attributes.cc:216
double asRadians() const
Definition: Angle.h:122
double max
Definition: attributes.cc:218
int x
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Spatial utility functions.
lsst::afw::geom::Angle Angle
Definition: misc.h:42
double const HALFPI
Definition: Angle.h:20
double const PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:18
Angle const maxAlpha(Angle radius, Angle centerPhi)
Definition: SpatialUtils.cc:79
Include files required for standard LSST Exception handling.
Useful astronomical constants.
void positionAndVelocity(Eigen::Vector3d &p, Eigen::Vector3d &v, Angle ra, Angle decl, double muRa, double muDecl, double vRadial, Angle parallax)
void thetaRangeReduce(Angle &min, Angle &max)
Definition: SpatialUtils.cc:56
lsst::afw::geom::Angle const clampPhi(lsst::afw::geom::Angle const a)
Definition: SpatialUtils.h:45
float POLE_EPSILON
Definition: geometry.py:35