Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
angle.functions.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 numeric/angle.functions.hh
11 /// @brief Trigonometric functions
12 /// @author Frank M. D'Ippolito (Objexx@objexx.com)
13 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
14 
15 
16 #ifndef INCLUDED_numeric_angle_functions_hh
17 #define INCLUDED_numeric_angle_functions_hh
18 
19 
20 // Package headers
22 #include <numeric/NumericTraits.hh>
23 
24 // C++ headers
25 #include <cmath>
26 
27 
28 namespace numeric {
29 
30 
31 /// @brief Principal value of angle in radians on ( -pi, pi ]
32 template< typename T >
33 inline
34 T
36 {
38 }
39 
40 
41 /// @brief Principal value of angle in radians on ( -pi, pi ]
42 template< typename T >
43 inline
44 T
46 {
48 }
49 
50 
51 /// @brief Principal value of angle in degrees on ( -180, 180 ]
52 template< typename T >
53 inline
54 T
56 {
57  return remainder( angle, T( 360.0 ) );
58 }
59 
60 
61 /// @brief Positive principal value of angle in radians on [ 0, 2*pi )
62 template< typename T >
63 inline
64 T
66 {
67  return modulo( angle, numeric::NumericTraits< T >::pi_2() );
68 }
69 
70 
71 /// @brief Positive principal value of angle in radians on [ 0, 2*pi )
72 template< typename T >
73 inline
74 T
76 {
77  return modulo( angle, numeric::NumericTraits< T >::pi_2() );
78 }
79 
80 
81 /// @brief Positive principal value of angle in degrees on [ 0, 360 )
82 template< typename T >
83 inline
84 T
86 {
87  return modulo( angle, T( 360.0 ) );
88 }
89 
90 
91 /// @brief Nearest periodic value of angle to a base angle in radians
92 template< typename T >
93 inline
94 T
95 nearest_angle( T const & angle, T const & base_angle )
96 {
97  return angle - ( nearest_ssize( ( angle - base_angle ) / numeric::NumericTraits< T >::pi_2() ) * numeric::NumericTraits< T >::pi_2() );
98 }
99 
100 
101 /// @brief Nearest periodic value of angle to a base angle in radians
102 template< typename T >
103 inline
104 T
105 nearest_angle_radians( T const & angle, T const & base_angle )
106 {
107  return angle - ( nearest_ssize( ( angle - base_angle ) / numeric::NumericTraits< T >::pi_2() ) * numeric::NumericTraits< T >::pi_2() );
108 }
109 
110 
111 /// @brief Nearest periodic value of angle to a base angle in degrees
112 template< typename T >
113 inline
114 T
115 nearest_angle_degrees( T const & angle, T const & base_angle )
116 {
117  return angle - ( nearest_ssize( ( angle - base_angle ) / T( 360.0 ) ) * T( 360.0 ) );
118 }
119 
120 
121 } // namespace numeric
122 
123 
124 #endif // INCLUDED_numeric_angle_functions_HH
T nearest_angle_radians(T const &angle, T const &base_angle)
Nearest periodic value of angle to a base angle in radians.
Numeric type traits.
T principal_angle(T const &angle)
Principal value of angle in radians on ( -pi, pi ].
T principal_angle_radians(T const &angle)
Principal value of angle in radians on ( -pi, pi ].
NumericTraits: Numeric type traits.
T principal_angle_degrees(T const &angle)
Principal value of angle in degrees on ( -180, 180 ].
T remainder(T const &x, T const &y)
Remainder of x with respect to division by y that is of smallest magnitude.
def angle
Definition: Equations.py:36
T nonnegative_principal_angle_degrees(T const &angle)
Positive principal value of angle in degrees on [ 0, 360 )
static Type pi_2()
2*pi
T nearest_angle_degrees(T const &angle, T const &base_angle)
Nearest periodic value of angle to a base angle in degrees.
T modulo(T const &x, T const &y)
x(mod y) mathematical modulo returning magnitude < | y | and sign of y
SSize nearest_ssize(T const &x)
nearest_ssize( x ): Nearest SSize
T nearest_angle(T const &angle, T const &base_angle)
Nearest periodic value of angle to a base angle in radians.
T nonnegative_principal_angle(T const &angle)
Positive principal value of angle in radians on [ 0, 2*pi )
Numeric functions.
T nonnegative_principal_angle_radians(T const &angle)
Positive principal value of angle in radians on [ 0, 2*pi )