angle.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Includes
13 *****************************************************************************/
14 
15 #include <cmath>
16 #include "../../include/ecl/geometry/angle.hpp"
17 #include <ecl/math/constants.hpp>
18 
19 /*****************************************************************************
20 ** Namespaces
21 *****************************************************************************/
22 
23 namespace ecl {
24 
25 /*****************************************************************************
26 ** Implementation [Functions]
27 *****************************************************************************/
28 
29 const float& wrap_angle(float &angle) {
30  if ( ( angle <= pi ) && ( angle >= -pi ) ) {
31  return angle; // nothing to do.
32  }
33  if ( angle < 0.0 ) {
34  angle = fmodf(angle-pi,2.0*pi)+pi;
35  } else {
36  angle = fmodf(angle+pi,2.0*pi)-pi;
37  }
38  return angle;
39 }
40 float wrap_angle(const float &angle) {
41  float wrapped;
42  if ( ( angle <= pi ) && ( angle >= -pi ) ) {
43  wrapped = angle;
44  } else if ( angle < 0.0 ) {
45  wrapped = fmodf(angle-pi,2.0*pi)+pi;
46  } else {
47  wrapped = fmodf(angle+pi,2.0*pi)-pi;
48  }
49  return wrapped;
50 }
51 
52 const double& wrap_angle(double &angle) {
53  if ( ( angle <= pi ) && ( angle >= -pi ) ) {
54  return angle; // nothing to do.
55  }
56  if ( angle < 0.0 ) {
57  angle = fmod(angle-pi,2.0*pi)+pi;
58  } else {
59  angle = fmod(angle+pi,2.0*pi)-pi;
60  }
61  return angle;
62 }
63 
64 double wrap_angle(const double &angle) {
65  double wrapped;
66  if ( ( angle <= pi ) && ( angle >= -pi ) ) {
67  wrapped = angle;
68  } else if ( angle < 0.0 ) {
69  wrapped = fmod(angle-pi,2.0*pi)+pi;
70  } else {
71  wrapped = fmod(angle+pi,2.0*pi)-pi;
72  }
73  return wrapped;
74 }
75 
76 } // namespace ecl
ecl::pi
const double pi
ecl::wrap_angle
const ecl_geometry_PUBLIC float & wrap_angle(float &angle)
Wrap the angle on -pi,pi (float types).
Definition: angle.cpp:33
constants.hpp
ecl
Embedded control libraries.


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:39