File indexing completed on 2024-04-28 03:42:51

0001 /*
0002     SPDX-FileCopyrightText: 2011 Akarsh Simha <akarshsimha@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ANGCONVERSION_H
0008 #define ANGCONVERSION_H
0009 
0010 #include <math.h> /* For M_PI */
0011 
0012 /* Angle conversion macros */
0013 #define RADPERDEG (M_PI / 180.0) /* Number of radians in a degree */
0014 
0015 /* Basic conversions between Degrees, Hours and Radians */
0016 inline double deg2rad(double x)
0017 {
0018     return (x * RADPERDEG);
0019 }
0020 inline double rad2deg(double x)
0021 {
0022     return (x / RADPERDEG);
0023 }
0024 inline double hour2deg(double x)
0025 {
0026     return (x * 15.0);
0027 }
0028 inline double deg2hour(double x)
0029 {
0030     return (x / 15.0);
0031 }
0032 inline double hour2rad(double x)
0033 {
0034     return deg2rad(hour2deg(x));
0035 }
0036 inline double rad2hour(double x)
0037 {
0038     return deg2hour(rad2deg(x));
0039 }
0040 
0041 /* Convert degrees to arcminutes or arcseconds and back */
0042 inline double deg2arcsec(double x)
0043 {
0044     return (x * 3600.0);
0045 }
0046 inline double arcsec2deg(double x)
0047 {
0048     return (x / 3600.0);
0049 }
0050 inline double deg2arcmin(double x)
0051 {
0052     return (x * 60.0);
0053 }
0054 inline double arcmin2deg(double x)
0055 {
0056     return (x / 60.0);
0057 }
0058 
0059 /* The following are redundant, but anyway */
0060 inline double hour2sec(double x)
0061 {
0062     return (x * 3600.0);
0063 }
0064 inline double sec2hour(double x)
0065 {
0066     return (x / 3600.0);
0067 }
0068 inline double hour2min(double x)
0069 {
0070     return (x * 60.0);
0071 }
0072 inline double min2hour(double x)
0073 {
0074     return (x / 60.0);
0075 }
0076 
0077 /* Convert DMS / HMS to Degrees / Hours */
0078 inline double dms2deg(double d, double m, double s)
0079 {
0080     return (d + m / 60.0 + s / 3600.0);
0081 }
0082 inline double hms2hour(double h, double m, double s)
0083 {
0084     return (h + m / 60.0 + s / 3600.0);
0085 }
0086 
0087 void deg2dms(double D, int *d, int *m, float *s)
0088 {
0089     *d = (int)D;
0090     *m = (int)((D - *d) * 60);
0091     *s = (int)((D - *d) * 3600 - (*m * 60));
0092 }
0093 
0094 void hour2hms(double H, int *h, int *m, float *s) /* Another redundant function */
0095 {
0096     *h = (int)H;
0097     *m = (int)((H - *h) * 60);
0098     *s = (int)((H - *h) * 3600 - (*m * 60));
0099 }
0100 
0101 #endif