Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00028
00029 #ifndef THOR_TRIGONOMETRY_HPP
00030 #define THOR_TRIGONOMETRY_HPP
00031
00032 #include <Thor/Config.hpp>
00033
00034 #include <cmath>
00035
00036
00037 namespace thor
00038 {
00039
00042
00064 template <typename T>
00065 struct TrigonometricTraits
00066 {
00067 };
00068
00069
00070 template <>
00071 struct TrigonometricTraits<float>
00072 {
00073 typedef float Type;
00074
00075 static Type sin(Type deg) { return std::sin(degToRad(deg)); }
00076 static Type cos(Type deg) { return std::cos(degToRad(deg)); }
00077 static Type tan(Type deg) { return std::tan(degToRad(deg)); }
00078 static Type arcSin(Type value) { return radToDeg(std::asin(value)); }
00079 static Type arcCos(Type value) { return radToDeg(std::acos(value)); }
00080 static Type arcTan2(Type valY, Type valX) { return radToDeg(std::atan2(valY, valX)); }
00081 static Type sqrt(Type value) { return std::sqrt(value); }
00082
00083 static Type pi() { return 3.141592653589793238462643383f; }
00084 static Type radToDeg(Type rad) { return 180 / pi() * rad; }
00085 static Type degToRad(Type deg) { return pi() / 180 * deg; }
00086 };
00087
00088
00089 template <>
00090 struct TrigonometricTraits<double>
00091 {
00092 typedef double Type;
00093
00094 static Type sin(Type deg) { return std::sin(degToRad(deg)); }
00095 static Type cos(Type deg) { return std::cos(degToRad(deg)); }
00096 static Type tan(Type deg) { return std::tan(degToRad(deg)); }
00097 static Type arcSin(Type value) { return radToDeg(std::asin(value)); }
00098 static Type arcCos(Type value) { return radToDeg(std::acos(value)); }
00099 static Type arcTan2(Type valY, Type valX) { return radToDeg(std::atan2(valY, valX)); }
00100 static Type sqrt(Type value) { return std::sqrt(value); }
00101
00102 static Type pi() { return 3.141592653589793238462643383; }
00103 static Type radToDeg(Type rad) { return 180 / pi() * rad; }
00104 static Type degToRad(Type deg) { return pi() / 180 * deg; }
00105 };
00106
00107
00108 template <>
00109 struct TrigonometricTraits<long double>
00110 {
00111 typedef long double Type;
00112
00113 static Type sin(Type deg) { return std::sin(degToRad(deg)); }
00114 static Type cos(Type deg) { return std::cos(degToRad(deg)); }
00115 static Type tan(Type deg) { return std::tan(degToRad(deg)); }
00116 static Type arcSin(Type value) { return radToDeg(std::asin(value)); }
00117 static Type arcCos(Type value) { return radToDeg(std::acos(value)); }
00118 static Type arcTan2(Type valY, Type valX) { return radToDeg(std::atan2(valY, valX)); }
00119 static Type sqrt(Type value) { return std::sqrt(value); }
00120
00121 static Type pi() { return 3.141592653589793238462643383l; }
00122 static Type radToDeg(Type rad) { return 180 / pi() * rad; }
00123 static Type degToRad(Type deg) { return pi() / 180 * deg; }
00124 };
00125
00126
00127
00128
00131 template <typename T>
00132 T toDegree(T radian)
00133 {
00134 return TrigonometricTraits<T>::radToDeg(radian);
00135 }
00136
00139 template <typename T>
00140 T toRadian(T degree)
00141 {
00142 return TrigonometricTraits<T>::degToRad(degree);
00143 }
00144
00147 extern const float THOR_API Pi;
00148
00150
00151 }
00152
00153 #endif // THOR_TRIGONOMETRY_HPP