OpendTect-6_4  6.4
angles.h
Go to the documentation of this file.
1 #ifndef angles_h
2 #define angles_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Mar 2009
10  Contents: Angle functions
11  RCS: $Id$
12 ________________________________________________________________________
13 
14  Converting degrees, radians and user degrees to one another.
15  Users (or rather: geologists) have North=0, and then clockwise to E=90,
16  S=180s and W=270.
17 
18 */
19 
20 #include "gendefs.h"
21 #include <math.h>
22 
23 
24 namespace Angle
25 {
26 
27 enum Type { Rad, Deg, UsrDeg };
28 // Generic conversion function see bottom: Angle::convert
29 
30 template <class T>
31 T cPI() { return (T)M_PIl; }
32 
33 template <class T>
34 inline void getFullCircle( Type typ, T& t )
35 {
36  t = typ == Rad ? 2 * cPI<T>() : 360;
37 }
38 
39 
41 template <class T>
42 inline T deg2usrdeg( T deg ) //Make sure deg is defined, otherwise, dead loop
43 {
44  T usrdeg = 90 - deg;
45  while ( usrdeg >= 360 ) usrdeg -= 360;
46  while ( usrdeg < 0 ) usrdeg += 360;
47  return usrdeg;
48 }
49 
50 
52 template <class T>
53 inline T usrdeg2deg( T udeg )
54 {
55  T deg = 90 - udeg;
56  if ( deg < 0 ) deg += 360;
57  return deg;
58 }
59 
60 
61 template <class T>
62 inline T rad2usrdeg( T rad )
63 {
64  return deg2usrdeg( Math::toDegrees(rad) );
65 }
66 
67 
68 template <class T>
69 inline T usrdeg2rad( T udeg )
70 {
71  return Math::toRadians( usrdeg2deg(udeg) );
72 }
73 
74 
75 template <class T>
76 inline T convert( Type inptyp, T val, Type outtyp )
77 {
78  if ( inptyp == outtyp || mIsUdf(val) )
79  return val;
80 
81  switch ( inptyp )
82  {
83  case Rad:
84  val = outtyp == Deg ? Math::toDegrees(val) : rad2usrdeg(val);
85  break;
86  case Deg:
87  val = outtyp == Rad ? Math::toRadians(val) : deg2usrdeg(val);
88  break;
89  case UsrDeg:
90  val = outtyp == Deg ? usrdeg2deg(val) : usrdeg2rad(val);
91  break;
92  }
93 
94  return val;
95 }
96 
97 } // namespace Angle
98 
99 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
Definition: angles.h:27
T cPI()
Definition: angles.h:31
#define M_PIl
Definition: commondefs.h:67
Definition: angles.h:27
float toDegrees(float r)
Definition: math2.h:97
T usrdeg2rad(T udeg)
Definition: angles.h:69
T rad2usrdeg(T rad)
Definition: angles.h:62
Definition: angles.h:24
float toRadians(float d)
Definition: math2.h:99
T usrdeg2deg(T udeg)
User degrees are from North, clockwise.
Definition: angles.h:53
Type
Definition: angles.h:27
void getFullCircle(Type typ, T &t)
Definition: angles.h:34
T convert(Type inptyp, T val, Type outtyp)
Definition: angles.h:76
T deg2usrdeg(T deg)
User degrees are from North, clockwise.
Definition: angles.h:42
Definition: angles.h:27

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019