B4J Question Calculation of sun elevation and azimuth

HARRY

Active Member
Licensed User
Longtime User
Hi,
I am working on a project to optimally position a solar cell tablet towards the sun. It involves a Raspberry, programmed with B4J, stepper motors, etc.

I am looking for software to calculate the position of the sun based on date/time, latitude and longitude. On internet I do not find information that is really helpfull.

Does somebody have suggestions or even have experience in this area.

Harry
 

HARRY

Active Member
Licensed User
Longtime User
@Roycefer

Thanks for your reply. I encountered .../SunRelativePosition myself. But the problem is that I have no idea how to incorporate that in a B4J program with a simple UI.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
If you are willing to spend about an hour thinking very carefully about the problem, you could probably do the math yourself. After all, the ancient Greeks did it by scratching sharpened rocks into tree bark while wearing togas.

Consider that the Northern Summer Solstice occurs when the Sun is directly overhead at noon along the Tropic of Cancer. The Northern Winter Solstice occurs when the Sun is directly overhead at noon along the Tropic of Capricorn. You can approximate the noon-overhead-latitude for every day of the year by setting up a sine wave that meets those criteria. With this information, you can get the maximum elevation reached by the Sun at any latitude on any day. The max elevation, along with the location's season, will help you calculate the circle traced through the sky by the Sun from that location's point of view.

There are a few wrinkles with which the ancient Greeks didn't have to deal, namely Daylight Savings Time and leap years. However Java has already taken care of those problems for you. So long as you do all your calculations in "ticks" (i.e. the Unix timestamp as given by DateTime.Now), you don't have to worry too much about that.
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
I have translated the advanced code from the above link to b4j/b4a and it works fine, to a +- half a degree accuracy.
I'll probably add it to Astro library (start again the rusty wheels of Eclipse).
 

Attachments

  • SunAzEl.zip
    2.1 KB · Views: 295
Upvote 0
Top