Giter Site home page Giter Site logo

suncalcnet's Introduction

SunCalc-Net

build

A .NET port of the SunCalc JS lib for calculating sun/moon positions and phases.

Getting Started

The best way to get started is to:

  • Add a Nuget dependency to SunCalcNet.
  • Use SunCalc and MoonCalc class methods.

Usage example

Get position of the sun (azimuth and altitude)

var date = new DateTime(2013, 3, 5, 0, 0, 0, DateTimeKind.Utc);
var lat = 50.5;
var lng = 30.5;

var sunPosition = SunCalc.GetSunPosition(date, lat, lng);

Assert.Equal(-2.5003175907168385, sunPosition.Azimuth, 15);
Assert.Equal(-0.7000406838781611, sunPosition.Altitude, 15);

Get position of the moon (azimuth, altitude, distance and parallactic angle)

var date = new DateTime(2013, 3, 5, 0, 0, 0, DateTimeKind.Utc);
var lat = 50.5;
var lng = 30.5;

var moonPosition = MoonCalc.GetMoonPosition(date, lat, lng);

Assert.Equal(-0.9783999522438226, moonPosition.Azimuth, 15);
Assert.Equal(0.0145514822438922, moonPosition.Altitude, 15);
Assert.Equal(364121.37256256194, moonPosition.Distance, 15);
Assert.Equal(-0.59832117604234014, moonPosition.ParallacticAngle, 15);

Get Sun phases

var date = new DateTime(2013, 3, 5, 0, 0, 0, DateTimeKind.Utc);
var lat = 50.5;
var lng = 30.5;

var sunPhases = SunCalc.GetSunPhases(date, lat, lng).ToList();

foreach (var sunPhase in sunPhases)
{
    ...
}

Get Moon Illumination

var date = new DateTime(2013, 3, 5, 0, 0, 0, DateTimeKind.Utc);

var moonIllum = MoonCalc.GetMoonIllumination(date);

Assert.Equal(0.4848068202456373, moonIllum.Fraction, 15);
Assert.Equal(0.7548368838538762, moonIllum.Phase, 15);
Assert.Equal(1.6732942678578346, moonIllum.Angle, 15);

About Suncalc.js

SunCalc is a tiny BSD-licensed JavaScript library for calculating sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for the given location and time, created by Vladimir Agafonkin (@mourner) as a part of the SunCalc.net project.

Most calculations are based on the formulas given in the excellent Astronomy Answers articles about position of the sun and the planets. You can read about different twilight phases calculated by SunCalc in the Twilight article on Wikipedia.

Sun phases

Currently supported sun phases are:

Phase Description
Sunrise sunrise (top edge of the sun appears on the horizon)
SunriseEnd sunrise ends (bottom edge of the sun touches the horizon)
GoldenHourEnd morning golden hour (soft light, best time for photography) ends
SolarNoon solar noon (sun is in the highest position)
GoldenHour evening golden hour starts
SunsetStart sunset starts (bottom edge of the sun touches the horizon)
Sunset sunset (sun disappears below the horizon, evening civil twilight starts)
Dusk dusk (evening nautical twilight starts)
NauticalDusk nautical dusk (evening astronomical twilight starts)
Night night starts (dark enough for astronomical observations)
Nadir nadir (darkest moment of the night, sun is in the lowest position)
NightEnd night ends (morning astronomical twilight starts)
NauticalDawn nautical dawn (morning nautical twilight starts)
Dawn dawn (morning nautical twilight ends, morning civil twilight starts)

suncalcnet's People

Contributors

kostebudinoski avatar dependabot[bot] avatar t1m0thyj avatar jeffward01 avatar

Stargazers

Haleralex avatar Eric_Lian avatar Lucas avatar  avatar Dendraspis avatar  avatar Roman avatar Will Germany avatar  avatar Wojciech Radaczyński avatar  avatar Volmancer avatar Dawid Płowiec avatar  avatar Florian Untermoser avatar Thaddeus Huxley avatar Jarad Gray avatar JohanNorberg avatar Igor Karatayev avatar Martijn Coppoolse avatar Simon avatar Ekin Caglar avatar Lucas Haley avatar Jose Juan Montes avatar Marcin Badurowicz avatar Animesh Bulusu avatar Willem Hoffman avatar Dennis Maidon avatar  avatar David Brockmeier avatar Charlie Smith avatar  avatar Bruno Garcia avatar

Watchers

 avatar Ekin Caglar avatar Scott Wilson-Billing avatar Simon avatar  avatar

suncalcnet's Issues

Moon Calculations are wrong

I get false data regarding moon calculations, according to MoonCalc.org (and TimeAndDate.com).
Moon rise, set, fraction, phase etc. are wrong for any given date and time.

SunPhase time offset not correct.

Hello Koste,

Your sun phase time is not correct. The offset is not calculated in your phase time.
If your offset is +2 hours or your offset is 4 hours, the phase time is for both the same.

By your moonphase calculation is the offset calculated in your phase time.

Can you look at the sun phase time?

With kind regards Cor

Year in Date Time and it's impact of Sun Position

Hey! :)

First of all it's good to notice, that using SunCalcNet Sun's Analemma is changing through the years (that you can set in DateTime input), so if I increase the number of years it moves the whole Analemma little by little. If you compare year 2000 and 2500 you will see this difference. What I also noticed is a weird huge jump of Sun's Analemma between years 1899 and 1900. For some reason positions earlier than 1899 are completely different than these after. Looking at the source code it looks like it might be the thing with the ToJulianDate method.

Generally let me know which parts of it are probably bugs and which one are features :) Maybe creating some sort of a check if year in DateTime is in acceptable range will make sense.

Best regards,
Wojciech

SunCalc times are wrong

Go to the suncalc.net website, and drag it to Sydney. It is saying that sunrise is at 2pm

Missing Raise time; units

Hello, great library! How to understand Altitude and Azimuth values? What are units, also for others properties? Is it documented somewhere?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.