Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
#include <stdio.h>
#include <time.h>
#include <math.h>
#define PI 3.14159265358979323846
double solar_declination(struct tm *t) {
/* day angle : */
double J = 1.0 + ((double) t->tm_yday);
double tau_d = 2.0 * PI * (J - 1.0) / 365.0;
/* solar declination */
double delta_s = 0.006981 - 0.399912 * cos( tau_d) + 0.070257 * sin( tau_d)
- 0.006758 * cos(2.0 * tau_d) + 0.000907 * sin(2.0 * tau_d)
- 0.002697 * cos(3.0 * tau_d) + 0.001480 * sin(3.0 * tau_d);
return delta_s;
}
int main(void) {
time_t now = time(0);
struct tm *now_tm = gmtime(&now);
double hour = now_tm->tm_hour + (now_tm->tm_min / 60.0) + (now_tm->tm_sec / 3600.0);
double latitude = solar_declination(now_tm);
double longitude = PI - (2.0 * PI * hour / 24.0);
fprintf(stdout, "latitude : %10.5f radians (%10.5f degrees)\n", latitude, latitude * 180.0 / PI);
fprintf(stdout, "longitude : %10.5f radians (%10.5f degrees)\n", longitude, longitude * 180.0 / PI);
return 0;
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Dice Roll Probabilities | 3 | 97 | |
A map including geolocation, multiple markers retrieved from database | 2 | 76 | |
Dual bridge protection | 18 | 107 | |
Currency Conversion? | 1 | 84 |
Join the community of 500,000 technology professionals and ask your questions.