Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
wrap_angles.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file
11 /// @brief Functions to wrap angles in different ranges.
12 /// author Kale Kundert (kale.kundert@ucsf.edu)
13 
14 #ifndef INCLUDED_numeric_wrap_angles_hh
15 #define INCLUDED_numeric_wrap_angles_hh
16 
17 #include <numeric/NumericTraits.hh>
19 
20 namespace numeric {
21 
22 /// @brief Wrap the given angle in the range [0, 2 * pi).
23 /// @details No conversion to radians is implied.
24 template<typename T>
25 inline T wrap_2pi(T const &angle) {
26  return modulo<T>(angle, NumericTraits<T>::pi_2());
27 }
28 
29 /// @brief Wrap the given angle in the range [-pi, pi).
30 /// @details No conversion to radians is implied.
31 template<typename T>
32 inline T wrap_pi(T const &angle) {
33  return wrap_2pi<T>(angle + NumericTraits<T>::pi()) - NumericTraits<T>::pi();
34 }
35 
36 /// @brief Wrap the given angle in the range [0, 360).
37 /// @details No conversion to degrees is implied.
38 template<typename T>
39 inline T wrap_360(T const &angle) {
40  return modulo<T>(angle, 360);
41 }
42 
43 /// @brief Wrap the given angle in the range [-180, 180).
44 /// @details No conversion to degrees is implied.
45 template<typename T>
46 inline T wrap_180(T const &angle) {
47  return modulo<T>(angle + 180, 360) - 180;
48 }
49 
50 } // end namespace numeric
51 
52 #endif
Numeric type traits.
T wrap_180(T const &angle)
Wrap the given angle in the range [-180, 180).
Definition: wrap_angles.hh:46
NumericTraits: Numeric type traits.
T wrap_360(T const &angle)
Wrap the given angle in the range [0, 360).
Definition: wrap_angles.hh:39
def angle
Definition: Equations.py:36
static Type pi_2()
2*pi
T wrap_2pi(T const &angle)
Wrap the given angle in the range [0, 2 * pi).
Definition: wrap_angles.hh:25
T wrap_pi(T const &angle)
Wrap the given angle in the range [-pi, pi).
Definition: wrap_angles.hh:32
Numeric functions.
static Type pi()
pi