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 <cmath>
00033
00034
00035 namespace thor
00036 {
00037
00040
00061 template <typename T>
00062 struct TrigonometricTraits;
00063
00066 template <>
00067 struct TrigonometricTraits<float>
00068 {
00069 typedef float Type;
00070
00071 static Type Sin(Type deg) { return std::sin(DegToRad(deg)); }
00072 static Type Cos(Type deg) { return std::cos(DegToRad(deg)); }
00073 static Type Tan(Type deg) { return std::tan(DegToRad(deg)); }
00074 static Type ArcSin(Type value) { return RadToDeg(std::asin(value)); }
00075 static Type ArcCos(Type value) { return RadToDeg(std::acos(value)); }
00076 static Type ArcTan2(Type valY, Type valX) { return RadToDeg(std::atan2(valY, valX)); }
00077 static Type Sqrt(Type value) { return std::sqrt(value); }
00078
00079 static Type Pi() { return 3.14159265f; }
00080 static Type RadToDeg(Type rad) { return 180 / 3.14159265f * rad; }
00081 static Type DegToRad(Type deg) { return 3.14159265f / 180 * deg; }
00082 };
00083
00086 template <>
00087 struct TrigonometricTraits<double>
00088 {
00089 typedef double Type;
00090
00091 static Type Sin(Type deg) { return std::sin(DegToRad(deg)); }
00092 static Type Cos(Type deg) { return std::cos(DegToRad(deg)); }
00093 static Type Tan(Type deg) { return std::tan(DegToRad(deg)); }
00094 static Type ArcSin(Type value) { return RadToDeg(std::asin(value)); }
00095 static Type ArcCos(Type value) { return RadToDeg(std::acos(value)); }
00096 static Type ArcTan2(Type valY, Type valX) { return RadToDeg(std::atan2(valY, valX)); }
00097 static Type Sqrt(Type value) { return std::sqrt(value); }
00098
00099 static Type Pi() { return 3.14159265; }
00100 static Type RadToDeg(Type rad) { return 180 / 3.14159265 * rad; }
00101 static Type DegToRad(Type deg) { return 3.14159265 / 180 * deg; }
00102 };
00103
00106 template <>
00107 struct TrigonometricTraits<long double>
00108 {
00109 typedef long double Type;
00110
00111 static Type Sin(Type deg) { return std::sin(DegToRad(deg)); }
00112 static Type Cos(Type deg) { return std::cos(DegToRad(deg)); }
00113 static Type Tan(Type deg) { return std::tan(DegToRad(deg)); }
00114 static Type ArcSin(Type value) { return RadToDeg(std::asin(value)); }
00115 static Type ArcCos(Type value) { return RadToDeg(std::acos(value)); }
00116 static Type ArcTan2(Type valY, Type valX) { return RadToDeg(std::atan2(valY, valX)); }
00117 static Type Sqrt(Type value) { return std::sqrt(value); }
00118
00119 static Type Pi() { return 3.14159265l; }
00120 static Type RadToDeg(Type rad) { return 180 / 3.14159265l * rad; }
00121 static Type DegToRad(Type deg) { return 3.14159265l / 180 * deg; }
00122 };
00123
00126 template <typename T>
00127 T ToDegree(T radian)
00128 {
00129 return TrigonometricTraits<T>::RadToDeg(radian);
00130 }
00131
00134 template <typename T>
00135 T ToRadian(T degree)
00136 {
00137 return TrigonometricTraits<T>::DegToRad(degree);
00138 }
00139
00142 extern const float Pi;
00143
00145
00146 }
00147
00148 #endif // THOR_TRIGONOMETRY_HPP