public HorizontalCoordinates ToHorizontalCoordinates(Radian latitude, Radian longitude, DateTime utcTime)
        {
            var hourAngle = new SunInfoCalculator(utcTime).HourAngle(longitude);

            double rightSide1 = Math.Sin(latitude.Value) * Math.Sin(Declination.Value) +
                                Math.Cos(latitude.Value) * Math.Cos(Declination.Value) * Math.Cos(hourAngle.Value);

            double rightSide2 = Math.Cos(latitude.Value) * Math.Sin(Declination.Value) -
                                Math.Sin(latitude.Value) * Math.Cos(Declination.Value) * Math.Cos(hourAngle.Value);

            double rightSide3 = -Math.Cos(Declination.Value) * Math.Sin(hourAngle.Value);

            PolarCoordinates polarCoordinates = new CartesianCoordinates(rightSide2, rightSide3).ToPolarCoordinates();
            var azimuth = polarCoordinates.Angle;
            if (azimuth.Value < 0)
            {
                azimuth = new Degree(360.0).ToRadian() - (-azimuth);
            }

            polarCoordinates = new CartesianCoordinates(polarCoordinates.Radius, rightSide1).ToPolarCoordinates();
            var altitude = polarCoordinates.Angle;

            double mustBe1 = polarCoordinates.Radius;

            return new HorizontalCoordinates(azimuth, altitude);
        }
Exemple #2
0
 public SunData Get(DateTime utcDateTime, Degree latitude, Degree longitude)
 {
     _calculator.SetTime(utcDateTime);
     var data = new SunData();
     data.JulianDate = _calculator.JulianDate;
     data.UtcTime = utcDateTime;
     data.LocalTime = utcDateTime.ToLocalTime();
     data.SunEarthDistAU = _calculator.SunEarthDistance;
     data.SunEarthDistKm = _calculator.SunEarthDistanceKm;
     data.AxialTilt = _calculator.AxialTilt;
     Radian rightAscension = _calculator.RightAscension;
     data.RightAscension = rightAscension.ToDegree().ToTimeSpan();
     Radian declination = _calculator.Declination;
     data.Declination = declination.ToDegree();
     data.AngularDiameter = _calculator.AngularDiameter.ToDegree();
     data.HourAngle = _calculator.HourAngle(longitude.ToRadian()).ToDegree().ToTimeSpan();
     var equatorialCoordinates = new EquatorialCoordinates(rightAscension, declination);
     var horizontalCoordinates = equatorialCoordinates.ToHorizontalCoordinates(latitude.ToRadian(), longitude.ToRadian(), utcDateTime);
     data.Azimuth = horizontalCoordinates.Azimuth.ToDegree();
     data.Altitude = horizontalCoordinates.Altitude.ToDegree();
     data.ShadowRatio = Utils.GetShadowRatio(data.Altitude);
     data.Sunrise = _calculator.Sunrise(longitude, latitude);
     data.Transit = _calculator.SolarTransit(longitude);
     data.Sunset = _calculator.Sunset(longitude, latitude);
     return data;
 }
Exemple #3
0
 public static double GetShadowRatio(Degree altitude)
 {
     var complementAngle = (new Degree(90) - altitude);
     if ((complementAngle.Value < 0) || (complementAngle.Value > 90))
     {
         return double.NaN;
     }
     return Math.Tan(complementAngle.ToRadian().Value);
 }
Exemple #4
0
        public Location()
        {
            InitializeComponent();
            if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.UseGps))
            {
                _useGps = (bool)PhoneApplicationService.Current.State[StateKeys.UseGps];
            }
            if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.CurrLatitude))
            {
                _latitude = (Degree)PhoneApplicationService.Current.State[StateKeys.CurrLatitude];
            }
            if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.CurrLongitude))
            {
                _longitude = (Degree)PhoneApplicationService.Current.State[StateKeys.CurrLongitude];
            }

            _latDeg = _latitude.Degrees;
            _latMin = _latitude.Minutes;
            _latSec = (short?) Math.Round(_latitude.Seconds);

            textBoxLatDeg.Text = _latDeg.Value.ToString(CultureInfo.InvariantCulture);
            textBoxLatMin.Text = _latMin.Value.ToString(CultureInfo.InvariantCulture);
            textBoxLatSec.Text = _latSec.Value.ToString(CultureInfo.InvariantCulture);

            pickerLatEmisph.SelectedIndex = _latitude.IsNegative ? 1 : 0;

            _lonDeg = _longitude.Degrees;
            _lonMin = _longitude.Minutes;
            _lonSec = (short?)Math.Round(_longitude.Seconds);

            textBoxLonDeg.Text = _lonDeg.Value.ToString(CultureInfo.InvariantCulture);
            textBoxLonMin.Text = _lonMin.Value.ToString(CultureInfo.InvariantCulture);
            textBoxLonSec.Text = _lonSec.Value.ToString(CultureInfo.InvariantCulture);

            pickerLonEmisph.SelectedIndex = _longitude.IsNegative ? 1 : 0;

            checkBoxUseGps.IsChecked = _useGps;

            EnableControls();
        }
Exemple #5
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.CurrLocalDateTime))
     {
         _currUtcDateTime = ((DateTime)PhoneApplicationService.Current.State[StateKeys.CurrLocalDateTime]).ToUniversalTime();
         _realTime = false;
     }
     bool useGps = true;
     if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.UseGps))
     {
         useGps = ((bool)PhoneApplicationService.Current.State[StateKeys.UseGps]);
     }
     if (!useGps)
     {
         if(_useGps)
         {
             _geoCoordinateWatcher.Stop();
         }
         if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.CurrLatitude))
         {
             _currLatitude = ((Degree) PhoneApplicationService.Current.State[StateKeys.CurrLatitude]);
         }
         if (PhoneApplicationService.Current.State.ContainsKey(StateKeys.CurrLongitude))
         {
             _currLongitude = ((Degree) PhoneApplicationService.Current.State[StateKeys.CurrLongitude]);
         }
         _useGps = false;
     }
     else
     {
         if(!_useGps)
         {
             _geoCoordinateWatcher.Start();
         }
         _useGps = true;
     }
     RefreshInfo();
 }
Exemple #6
0
 private double ApproximateSolarNoon(Degree longitude)
 {
     return 2451545.0009 + (-longitude.Value / 360.0) + JulianCycleSince2000(longitude);
 }
Exemple #7
0
 public static string GetLongitudeString(Degree longitude)
 {
     string emisphere = longitude.Value > 0 ? "E" : (longitude.Value < 0 ? "W" : "E/W");
     return String.Format("{0}° {1}' {2}\" {3}", longitude.Degrees.ToString("00"), longitude.Minutes.ToString("00"), longitude.Seconds.ToString("00"), emisphere);
 }
Exemple #8
0
 void RefreshPosition(GeoPosition<GeoCoordinate> position)
 {
     _currLatitude = new Degree(position.Location.Latitude);
     _currLongitude = new Degree(position.Location.Longitude);
 }
Exemple #9
0
 private double SunsetJulianDate(Degree longitude, Degree latitude)
 {
     return 2451545.0009
         + (HourAngle(latitude).ToDegree().Value + -longitude.Value) / 360.0
         + JulianCycleSince2000(longitude)
         + 0.0053 * Math.Sin(MeanSunAnomaly.ToRadian().Value)
         - 0.0069 * Math.Sin(2 * EclipticSunLongitude.ToRadian().Value);
 }
Exemple #10
0
        private void OnCheck(object sender, EventArgs e)
        {
            if (_useGps.HasValue && !_useGps.Value)
            {
                if (!TryParseLatLon())
                {
                    return;
                }
                if (_latDeg.HasValue && _latMin.HasValue && _latSec.HasValue)
                {
                    var neg = (short) (pickerLatEmisph.SelectedIndex == 0 ? 1 : -1);
                    _latitude = new Degree((short) (_latDeg.Value*neg), (short) (_latMin.Value*neg),
                                           _latSec.Value*neg);
                }

                if (_lonDeg.HasValue && _lonMin.HasValue && _lonSec.HasValue)
                {
                    var neg = (short) (pickerLonEmisph.SelectedIndex == 0 ? 1 : -1);
                    _longitude = new Degree((short) (_lonDeg.Value*neg), (short) (_lonMin.Value*neg),
                                            _lonSec.Value*neg);
                }
                PhoneApplicationService.Current.State[StateKeys.CurrLatitude] = _latitude;
                PhoneApplicationService.Current.State[StateKeys.CurrLongitude] = _longitude;
            }
            PhoneApplicationService.Current.State[StateKeys.UseGps] = _useGps;
            NavigationService.GoBack();
        }
Exemple #11
0
 private double SolarTransitJulianDate(Degree longitude)
 {
     double meanSunAnomaly = MeanSunAnomaly.ToRadian().Value;
     return ApproximateSolarNoon(longitude) + .0053 * Math.Sin(meanSunAnomaly) - .0069 * Math.Sin(2 * EclipticSunLongitude.ToRadian().Value);
 }
Exemple #12
0
 private double SunriseJulianDate(Degree longitude, Degree latitude)
 {
     double solarTransitJulianDate = SolarTransitJulianDate(longitude);
     return solarTransitJulianDate - (SunsetJulianDate(longitude, latitude) - solarTransitJulianDate);
 }
Exemple #13
0
 private Radian HourAngle(Degree latitude)
 {
     return new Radian(
         Math.Acos(
         (Math.Sin(new Degree(-.83).ToRadian().Value) - Math.Sin(latitude.ToRadian().Value) * Math.Sin(Declination.Value))
         /
         (Math.Cos(latitude.ToRadian().Value) * Math.Cos(Declination.Value))
         )
         );
 }
Exemple #14
0
 private double JulianCycleSince2000(Degree longitude)
 {
     return Math.Floor((DaysFrom2000 - (-longitude.Value / 360.0)) + 0.5);
 }
Exemple #15
0
 public static string GetLatitudeString(Degree latitude)
 {
     string emisphere = latitude.Value > 0 ? "N" : (latitude.Value < 0 ? "S" : "N/S");
     return String.Format("{0}° {1}' {2}\" {3}", latitude.Degrees.ToString("00"), latitude.Minutes.ToString("00"), latitude.Seconds.ToString("00"), emisphere);
 }
Exemple #16
0
 public DateTime? Sunset(Degree longitude, Degree latitude)
 {
     return TimeUtils.JulianDateToUtc(SunsetJulianDate(longitude, latitude));
 }
Exemple #17
0
 public DateTime? SolarTransit(Degree longitude)
 {
     return TimeUtils.JulianDateToUtc(SolarTransitJulianDate(longitude));
 }
Exemple #18
0
 public void SetTime(DateTime utcDateTime)
 {
     _julianDate = TimeUtils.UtcToJulianDate(utcDateTime);
     _axialTilt = null;
 }
Exemple #19
0
 public Radian HourAngle(Radian longitude)
 {
     var hourAngle = GreenwichSiderealTime - (-longitude) - RightAscension;
     if (hourAngle.Value < 0)
     {
         hourAngle = new Degree(TimeSpan.FromHours(24.0)).ToRadian() + hourAngle;
     }
     return hourAngle;
 }