Solved

Calculate Sun Position in Lat/Lon from Date/time

Posted on 2008-06-20
3
2,446 Views
Last Modified: 2010-05-18
I am developing an application that automates the 3D Globe control provided by ESRI.

ESRI use this globe themselves in there ArcGlobe application, and within this app it is possible to specify a date/time and plot the sun against the globe.

I wish to replicate this functionality in my application, however ESRI do not appear to have exposed this functionality in the API.

As far as I am aware it is only possible to set the sun position directly as a Lat/Lon

What I need is either :
a) a pointer to the ESRI API to get Sun Lat/Lon from Date/Time

or

b) code to derive the Sun Lat/Lon from Date/Time.

Note: I do not wish the Sun Azimuth/Altitute I have found these calculations many times. I wont the Lat/Lon position that the sun is directly above. As shown on this site : http://www.fourmilab.ch/cgi-bin/Earth

Thanks in Advance

G
0
Comment
Question by:Gordonp
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
Comment Utility
I've quickly written the following code. I assume that's what you intended ? The precision is relatively good (using Spencer's algorithm), but could be better with more accurate formula's (like Michalsky's almanac algorithm for example, from his "The Astronomical Almanac's algorithm for approximate solar position" paper).
#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;

}

Open in new window

0
 
LVL 3

Author Comment

by:Gordonp
Comment Utility
This appears to be exactly what I'm after. Just need to check it out, and I'll be back to Accept if formally.
0
 
LVL 3

Author Closing Comment

by:Gordonp
Comment Utility
Thanks for your help
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Probability Distribution 2 45
Sampling 3 38
Should CArray be used for a list of pointers in C++? 19 88
Math homework question 5 60
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now