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
00063 template <typename T>
00064 struct TrigonometricTraits;
00065
00068 template <>
00069 struct TrigonometricTraits<float>
00070 {
00071 typedef float Type;
00072
00073 static Type Sin(Type deg) { return std::sin(DegToRad(deg)); }
00074 static Type Cos(Type deg) { return std::cos(DegToRad(deg)); }
00075 static Type Tan(Type deg) { return std::tan(DegToRad(deg)); }
00076 static Type ArcSin(Type value) { return RadToDeg(std::asin(value)); }
00077 static Type ArcCos(Type value) { return RadToDeg(std::acos(value)); }
00078 static Type ArcTan2(Type valY, Type valX) { return RadToDeg(std::atan2(valY, valX)); }
00079 static Type Sqrt(Type value) { return std::sqrt(value); }
00080
00081 static Type Pi() { return 3.141592653589793238462643383f; }
00082 static Type RadToDeg(Type rad) { return 180 / Pi() * rad; }
00083 static Type DegToRad(Type deg) { return Pi() / 180 * deg; }
00084 };
00085
00088 template <>
00089 struct TrigonometricTraits<double>
00090 {
00091 typedef double Type;
00092
00093 static Type Sin(Type deg) { return std::sin(DegToRad(deg)); }
00094 static Type Cos(Type deg) { return std::cos(DegToRad(deg)); }
00095 static Type Tan(Type deg) { return std::tan(DegToRad(deg)); }
00096 static Type ArcSin(Type value) { return RadToDeg(std::asin(value)); }
00097 static Type ArcCos(Type value) { return RadToDeg(std::acos(value)); }
00098 static Type ArcTan2(Type valY, Type valX) { return RadToDeg(std::atan2(valY, valX)); }
00099 static Type Sqrt(Type value) { return std::sqrt(value); }
00100
00101 static Type Pi() { return 3.141592653589793238462643383; }
00102 static Type RadToDeg(Type rad) { return 180 / Pi() * rad; }
00103 static Type DegToRad(Type deg) { return Pi() / 180 * deg; }
00104 };
00105
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
00128 template <typename T>
00129 T ToDegree(T radian)
00130 {
00131 return TrigonometricTraits<T>::RadToDeg(radian);
00132 }
00133
00136 template <typename T>
00137 T ToRadian(T degree)
00138 {
00139 return TrigonometricTraits<T>::DegToRad(degree);
00140 }
00141
00144 extern const float THOR_API Pi;
00145
00147
00148 }
00149
00150 #endif // THOR_TRIGONOMETRY_HPP