Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/coordConv/html/include_2coord_conv_2math_utils_8cc_source.html
Дата изменения: Thu May 7 21:42:46 2015
Дата индексирования: Sun Apr 10 05:26:02 2016
Кодировка:

Поисковые слова: clouds
lsst.coordConv: include/coordConv/mathUtils.cc Source File
lsst.coordConv  unknown
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
mathUtils.cc
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 #include <stdexcept>
5 #include <iostream>
6 #include <iomanip>
7 /*
8 Define inline math utilities
9 */
10 namespace coordConv {
11 
12  inline void rot2D(double &rotX, double &rotY, double x, double y, double ang) {
13  double sinAng = sind(ang);
14  double cosAng = cosd(ang);
15 
16  rotX = cosAng * x - sinAng * y;
17  rotY = sinAng * x + cosAng * y;
18  }
19 
20  inline double wrapPos(double ang) {
21  // put angle into range (-360, 360), then finish the job
22  double wrappedAng = std::fmod(ang, 360);
23  if (wrappedAng < 0) {
24  wrappedAng += 360;
25  }
26  if (wrappedAng == 360) {
27  // this can happen if wrappedAng is so small that wrappedAng + 360 rounds to 360
28  wrappedAng = 0;
29  };
30  return wrappedAng;
31  }
32 
33  inline double wrapCtr(double ang) {
34  // put angle into range (-360, 360), then finish the job
35  double wrappedAng = std::fmod(ang, 360);
36  if (wrappedAng >= 180) {
37  wrappedAng -= 360;
38  if (wrappedAng < -180) {
39  // handle roundoff error
40  wrappedAng = -180;
41  }
42  } else if (wrappedAng < -180) {
43  wrappedAng += 360;
44  if (wrappedAng >= 180) {
45  // handle roundoff error
46  wrappedAng = -180;
47  }
48  }
49  return wrappedAng;
50  }
51 
52  inline double wrapNear(double ang, double refAng) {
53  double wrappedAng = refAng + wrapCtr(ang - refAng);
54 
55  // roundoff error can cause slightly out-of-range values; the following fixes those
56  // (and even seems to preserve ang - refAng < 180, though I'm not sure why)
57  if (wrappedAng - refAng >= 180) {
58  wrappedAng -= 360;
59  }
60  // avoid if-else in case wrappedAng -= 360 results in wrappedAng - refAng slightly less than -180;
61  // maximum relative roundoff error for addition is 2 epsilon
62  if (wrappedAng - refAng < -180) {
63  wrappedAng -= wrappedAng * 2.0 * DoubleEpsilon;
64  }
65  return wrappedAng;
66  }
67 }
double wrapNear(double ang, double refAng)
Definition: mathUtils.cc:52
double cosd(double ang)
cosine of angle in degrees
Definition: mathUtils.h:55
double wrapCtr(double ang)
Definition: mathUtils.cc:33
const double DoubleEpsilon
Definition: mathUtils.h:13
double sind(double ang)
sine of angle in degrees
Definition: mathUtils.h:52
void rot2D(double &rotX, double &rotY, double x, double y, double ang)
Definition: mathUtils.cc:12
double wrapPos(double ang)
Definition: mathUtils.cc:20