FRC Paradigm Shift #1259
Documentation for the 2021 Robot
Util.cpp
Go to the documentation of this file.
1 #include "common/Util.h"
2 
3 
4 double Util::DegreesToRadians(double theta)
5 {
6  return theta * (2 * wpi::math::pi) / 360.0;
7 }
8 
9 double Util::RadiansToDegrees(double theta)
10 {
11  return theta * 360.0 / (2 * wpi::math::pi);
12 }
13 
14 // Convert any angle theta in radians to its equivalent on the interval [0, 2pi]
15 double Util::ZeroTo2PiRads(double theta)
16 {
17  theta = fmod(theta, 2 * wpi::math::pi);
18  if (theta < 0)
19  theta += 2 * wpi::math::pi;
20 
21  return theta;
22 }
23 
24 // Convert any angle theta in degrees to its equivalent on the interval [0, 360]
25 double Util::ZeroTo360Degs(double theta)
26 {
27  theta = fmod(theta, 360.0);
28  if (theta < 0)
29  theta += 360.0;
30 
31  return theta;
32 }
33 
34 // Convert any angle theta in radians to its equivalent on the interval [-pi, pi]
35 double Util::NegPiToPiRads(double theta)
36 {
37  theta = ZeroTo2PiRads(theta);
38  if (theta > wpi::math::pi)
39  theta -= 2 * wpi::math::pi;
40  else if (theta < -1.0 * wpi::math::pi)
41  theta += 2 * wpi::math::pi;
42 
43  return theta;
44 }
45 
46 double Util::GetAverage(vector<double> numbers)
47 {
48  double sum = 0.0;
49 
50  for (auto n : numbers)
51  sum += n;
52 
53  return sum / numbers.size();
54 }
static double NegPiToPiRads(double theta)
Definition: Util.cpp:35
static double RadiansToDegrees(double theta)
Convert any angle theta in radians to degrees.
Definition: Util.cpp:9
static double DegreesToRadians(double theta)
Convert any angle theta in degrees to radians.
Definition: Util.cpp:4
static double ZeroTo2PiRads(double theta)
Definition: Util.cpp:15
static double GetAverage(vector< double > numbers)
Definition: Util.cpp:46
static double ZeroTo360Degs(double theta)
Definition: Util.cpp:25