LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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 
lsst::afw::geom::Angle Angle
Definition: misc.h:37
int y
Eigen::Vector2d const cartesianToSpherical(Eigen::Vector3d const &v)
double min
Definition: attributes.cc:216
double max
Definition: attributes.cc:218
Include files required for standard LSST Exception handling.
double const PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:18
lsst::afw::coord::IcrsCoord IcrsCoord
Definition: misc.h:36
int x
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
double asRadians() const
Definition: Angle.h:122
double const TWOPI
Definition: Angle.h:19
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Spatial utility functions.
double const HALFPI
Definition: Angle.h:20
Useful astronomical constants.
Angle const maxAlpha(Angle radius, Angle centerPhi)
Definition: SpatialUtils.cc:79
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