Kstars

angconversion.h
1 /*
2  SPDX-FileCopyrightText: 2011 Akarsh Simha <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef ANGCONVERSION_H
8 #define ANGCONVERSION_H
9 
10 #include <math.h> /* For M_PI */
11 
12 /* Angle conversion macros */
13 #define RADPERDEG (M_PI / 180.0) /* Number of radians in a degree */
14 
15 /* Basic conversions between Degrees, Hours and Radians */
16 inline double deg2rad(double x)
17 {
18  return (x * RADPERDEG);
19 }
20 inline double rad2deg(double x)
21 {
22  return (x / RADPERDEG);
23 }
24 inline double hour2deg(double x)
25 {
26  return (x * 15.0);
27 }
28 inline double deg2hour(double x)
29 {
30  return (x / 15.0);
31 }
32 inline double hour2rad(double x)
33 {
34  return deg2rad(hour2deg(x));
35 }
36 inline double rad2hour(double x)
37 {
38  return deg2hour(rad2deg(x));
39 }
40 
41 /* Convert degrees to arcminutes or arcseconds and back */
42 inline double deg2arcsec(double x)
43 {
44  return (x * 3600.0);
45 }
46 inline double arcsec2deg(double x)
47 {
48  return (x / 3600.0);
49 }
50 inline double deg2arcmin(double x)
51 {
52  return (x * 60.0);
53 }
54 inline double arcmin2deg(double x)
55 {
56  return (x / 60.0);
57 }
58 
59 /* The following are redundant, but anyway */
60 inline double hour2sec(double x)
61 {
62  return (x * 3600.0);
63 }
64 inline double sec2hour(double x)
65 {
66  return (x / 3600.0);
67 }
68 inline double hour2min(double x)
69 {
70  return (x * 60.0);
71 }
72 inline double min2hour(double x)
73 {
74  return (x / 60.0);
75 }
76 
77 /* Convert DMS / HMS to Degrees / Hours */
78 inline double dms2deg(double d, double m, double s)
79 {
80  return (d + m / 60.0 + s / 3600.0);
81 }
82 inline double hms2hour(double h, double m, double s)
83 {
84  return (h + m / 60.0 + s / 3600.0);
85 }
86 
87 void deg2dms(double D, int *d, int *m, float *s)
88 {
89  *d = (int)D;
90  *m = (int)((D - *d) * 60);
91  *s = (int)((D - *d) * 3600 - (*m * 60));
92 }
93 
94 void hour2hms(double H, int *h, int *m, float *s) /* Another redundant function */
95 {
96  *h = (int)H;
97  *m = (int)((H - *h) * 60);
98  *s = (int)((H - *h) * 3600 - (*m * 60));
99 }
100 
101 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.