Skip to content

Commit

Permalink
Фикс багов библиотки SunCalc:
Browse files Browse the repository at this point in the history
    - Wrong azimuth angle: mourner/suncalc#6
    - Nadir shifted from past to future: mourner/suncalc#125
    - Coefficient is incorrect in solarTransitJ() function: mourner/suncalc#178
  • Loading branch information
zedxxx committed Jan 22, 2025
1 parent f8a7181 commit 09b6aab
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Includes/SunCalc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function getDeclination(const l, b: Double): Double; inline;

function getAzimuth(const H, phi, dec: Double): Double; inline;
begin
Result := ArcTan2(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi));
Result := Pi + ArcTan2(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi));
end;

function getAltitude(const H, phi, dec: Double): Double; inline;
Expand Down Expand Up @@ -280,7 +280,7 @@ function getApproxTransit(const Ht, lw: Double; const n: Double): Double; inline

function getSolarTransitJ(const ds, M, L: Double): Double; inline;
begin
Result := J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L);
Result := J2000 + ds + 0.0053 * sin(M) - 0.0068 * sin(2 * L);
end;

function getHourAngle(const h, phi, d: Double): Double; inline;
Expand Down Expand Up @@ -323,7 +323,7 @@ function GetTimes(const ADate: TDateTime; const ALat, ALon: Double): TSunCalcTim

if not IsNan(Jnoon) then begin
Result[solarNoon].Value := fromJulian(Jnoon);
Result[nadir].Value := fromJulian(Jnoon - 0.5);
Result[nadir].Value := fromJulian(Jnoon + 0.5);
end;

for i := Low(Result) to High(Result) do begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ function TSunCalcDataProviderMoon.GetDayInfo(
end;

AddRow(VRow, _('Up Time'), MinutesToStr(VUptime) );
AddRow(VRow, _('Azimuth'), Format('%.0f°', [RadToDeg(VPos.Azimuth + Pi)]) );
AddRow(VRow, _('Azimuth'), Format('%.0f°', [RadToDeg(VPos.Azimuth)]) );
AddRow(VRow, _('Altitude'), Format('%.1f°', [RadToDeg(VPos.Altitude)]) );
AddRow(VRow, _('Shadow, meters'), ShadowToStr(VPos.Altitude) );
AddRow(VRow, _('Illumination'), Format('%.0f%%', [VIllumination.Fraction * 100]) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ function TSunCalcDataProviderSun.GetDayInfo(
end;

AddRow(VRow, _('Day Length'), MinutesToStr(VUptime) );
AddRow(VRow, _('Azimuth'), Format('%.0f°', [RadToDeg(VPos.Azimuth + Pi)]) );
AddRow(VRow, _('Azimuth'), Format('%.0f°', [RadToDeg(VPos.Azimuth)]) );
AddRow(VRow, _('Altitude'), Format('%.1f°', [RadToDeg(VPos.Altitude)]) );
AddRow(VRow, _('Shadow, meters'), ShadowToStr(VPos.Altitude) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function TSunCalcShapesGenerator.GetPointPosition(
Exit;
end;
VPos := FDataProvider.GetPosition(ADate, FLocation);
VAngle := Pi / 2 + VPos.Azimuth;
VAngle := VPos.Azimuth - Pi / 2;
R := FRadius * Cos(VPos.Altitude);
AAltitude := VPos.Altitude;
Result.X := FCenter.X + R * Cos(VAngle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ procedure TWindowLayerSunCalcDetailsPanel.DrawRow(
if ATime <> 0 then begin
if FIsDetailedView then begin
VPos := FSunCalcDataProvider.GetPosition(ATime, FLocation);
VAzimuth := Format('%.0f°', [RadToDeg(VPos.Azimuth + Pi)]);
VAzimuth := Format('%.0f°', [RadToDeg(VPos.Azimuth)]);
VAltitude := Format('%.1f°', [RadToDeg(VPos.Altitude)]);
end;
VLocalTime := TTimeZoneInfo.UTCToTzLocalTime(ATime, FTzOffset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ procedure TWindowLayerSunCalcTimeInfo.InvalidateLayer;
if FSunCalcConfig.ShowCaptionNearSun then begin
VSunPos := FSunCalcDataProvider.GetPosition(FDateTime, FLocation);

VAzimuth := Format('%.2f°', [RadToDeg(VSunPos.Azimuth + Pi)]);
VAzimuth := Format('%.2f°', [RadToDeg(VSunPos.Azimuth)]);
VAltitude := Format('%.2f°', [RadToDeg(VSunPos.Altitude)]);
VText := Format('%s: %s; %s: %s', [rsAltitude, VAltitude, rsAzimuth, VAzimuth]);

Expand Down

0 comments on commit 09b6aab

Please sign in to comment.