Kstars

angconversion.h
1/*
2 SPDX-FileCopyrightText: 2011 Akarsh Simha <akarshsimha@gmail.com>
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 */
16inline double deg2rad(double x)
17{
18 return (x * RADPERDEG);
19}
20inline double rad2deg(double x)
21{
22 return (x / RADPERDEG);
23}
24inline double hour2deg(double x)
25{
26 return (x * 15.0);
27}
28inline double deg2hour(double x)
29{
30 return (x / 15.0);
31}
32inline double hour2rad(double x)
33{
34 return deg2rad(hour2deg(x));
35}
36inline double rad2hour(double x)
37{
38 return deg2hour(rad2deg(x));
39}
40
41/* Convert degrees to arcminutes or arcseconds and back */
42inline double deg2arcsec(double x)
43{
44 return (x * 3600.0);
45}
46inline double arcsec2deg(double x)
47{
48 return (x / 3600.0);
49}
50inline double deg2arcmin(double x)
51{
52 return (x * 60.0);
53}
54inline double arcmin2deg(double x)
55{
56 return (x / 60.0);
57}
58
59/* The following are redundant, but anyway */
60inline double hour2sec(double x)
61{
62 return (x * 3600.0);
63}
64inline double sec2hour(double x)
65{
66 return (x / 3600.0);
67}
68inline double hour2min(double x)
69{
70 return (x * 60.0);
71}
72inline double min2hour(double x)
73{
74 return (x / 60.0);
75}
76
77/* Convert DMS / HMS to Degrees / Hours */
78inline double dms2deg(double d, double m, double s)
79{
80 return (d + m / 60.0 + s / 3600.0);
81}
82inline double hms2hour(double h, double m, double s)
83{
84 return (h + m / 60.0 + s / 3600.0);
85}
86
87void 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
94void 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-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:01:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.