public async Task SetDate(Date date, CrdsGeographical geoLocation) { await Task.Run(() => { double jd0 = date.ToJulianEphemerisDay(); daysInMonth = Date.DaysInMonth(date.Year, date.Month); var eL = new PointF[5]; var eB = new PointF[5]; var eR = new PointF[5]; var jL = new PointF[5]; var jB = new PointF[5]; var jR = new PointF[5]; var earth = new CrdsHeliocentrical[5]; var jupiter = new CrdsHeliocentrical[5]; // calculate heliocentrical positions of Earth and Jupiter for 5 instants // and find least squares approximation model of planets position // to quick calculation of Galilean moons postions. for (int i = 0; i < 5; i++) { double jd = jd0 + (i / 4.0) * daysInMonth; earth[i] = PlanetPositions.GetPlanetCoordinates(3, jd); jupiter[i] = PlanetPositions.GetPlanetCoordinates(5, jd); } double[] earthL = earth.Select(x => x.L).ToArray(); double[] earthB = earth.Select(x => x.B).ToArray(); double[] earthR = earth.Select(x => x.R).ToArray(); double[] jupiterL = jupiter.Select(x => x.L).ToArray(); double[] jupiterB = jupiter.Select(x => x.B).ToArray(); double[] jupiterR = jupiter.Select(x => x.R).ToArray(); // it's important to align longitudes (avoid 0 degrees crossing) // before applying least squares method earthL = Angle.Align(earthL); jupiterL = Angle.Align(jupiterL); for (int i = 0; i < 5; i++) { eL[i] = new PointF(i, (float)earthL[i]); eB[i] = new PointF(i, (float)earthB[i]); eR[i] = new PointF(i, (float)earthR[i]); jL[i] = new PointF(i, (float)jupiterL[i]); jB[i] = new PointF(i, (float)jupiterB[i]); jR[i] = new PointF(i, (float)jupiterR[i]); } Begin = jd0; End = jd0 + daysInMonth; GeoLocation = geoLocation; this.eL = LeastSquares.FindCoeffs(eL, 3); this.eB = LeastSquares.FindCoeffs(eB, 3); this.eR = LeastSquares.FindCoeffs(eR, 3); this.jL = LeastSquares.FindCoeffs(jL, 3); this.jB = LeastSquares.FindCoeffs(jB, 3); this.jR = LeastSquares.FindCoeffs(jR, 3); }); }