Skip to content

Fix gmt_get_smallcircle for equinox#8938

Open
Esteban82 wants to merge 2 commits intomasterfrom
Fix_small_circle_equinox
Open

Fix gmt_get_smallcircle for equinox#8938
Esteban82 wants to merge 2 commits intomasterfrom
Fix_small_circle_equinox

Conversation

@Esteban82
Copy link
Member

This fixes #8936.

The code was written by Claude after some attemps. This is its explanation:


Problem

On the vernal and autumnal equinoxes (~March 20 and ~September 22), all
four solar terminator lines drawn by gmt solar -Tdcna overlap
completely instead of appearing as distinct concentric bands.

Root cause

In gmt_get_smallcircle (src/gmt_map.c), the generating vector X
is computed by finding a starting point xlat along the meridian
through the pole, colat degrees away:

xlat = (plat > 0.0) ? plat - colat : plat + colat;

All four terminator types use colat > 90° (90.833, 96, 102, 108).
On the equinoxes, plat ≈ −0.04° (solar declination near zero), so:

plat + colat = −0.04 + 90.833 = +90.79°  ← invalid latitude
plat + colat = −0.04 + 108    = +107.96° ← invalid latitude

gmt_geo_to_cart receives an out-of-range latitude and produces the
same degenerate vector X for all four terminators regardless of their
different colat values. All four small circles end up identical.

Confirmed with -Vd: the Added extra point coordinates were
byte-for-byte identical for -Td (90.833°) and -Ta (108°) before
the fix.

Fix

When xlat exceeds ±90°, wrap it around the pole by reflecting the
latitude and shifting the longitude by 180°. This places X at the
geometrically equivalent point on the correct side of the pole, at a
valid latitude, preserving the exact angular distance colat from P.

xlon = plon;
if (xlat > 90.0) {
    xlat = 180.0 - xlat;
    xlon += 180.0;
    if (xlon > 180.0) xlon -= 360.0;
} else if (xlat < -90.0) {
    xlat = -180.0 - xlat;
    xlon += 180.0;
    if (xlon > 180.0) xlon -= 360.0;
}

After the fix, -Vd shows four distinct Added extra point coordinates,
one per terminator, confirming each gets a unique generating vector:

Terminator Radius Extra point
-Td 90.833° −180/−89.107 and 180/+89.193
-Tc 96° −180/−83.941 and 180/+84.027
-Tn 102° −180/−77.941 and 180/+78.027
-Ta 108° −180/−71.941 and 180/+72.027

Files changed

  • src/gmt_map.cgmt_get_smallcircle: added pole-wrap guard and
    xlon variable; updated gmt_geo_to_cart call to use xlon instead
    of plon.

@Esteban82 Esteban82 requested review from a team and joa-quim March 20, 2026 17:19
@Esteban82 Esteban82 self-assigned this Mar 20, 2026
src/gmt_map.c Outdated
} else if (xlat < -90.0) {
xlat = -180.0 - xlat;
xlon += 180.0;
if (xlon > 180.0) xlon -= 360.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not correctly indented.

@Esteban82 Esteban82 requested a review from joa-quim March 20, 2026 18:42
@Esteban82
Copy link
Member Author

I revised the code style.

@joa-quim
Copy link
Member

We have test failures

@Esteban82
Copy link
Member Author

Yes, I see that the pssolar_fill.sh and pssolar_fill2.sh are different.

pssolar_fill.sh:

Original:
pssolar_fill_0

New:
pssolar_fill

pssolar_fill2.sh:

Original:
pssolar_fill2_0

New:
pssolar_fill2

@joa-quim
Copy link
Member

Can it be that originals were wrong?

@Esteban82
Copy link
Member Author

Can it be that originals were wrong?

For pssolar_fill.sh, I think so. I am checking for pssolar_fill2.sh.

@joa-quim
Copy link
Member

They are both wrong.

@Esteban82
Copy link
Member Author

This is the image from timeanddate:

image

https://www.timeanddate.com/worldclock/sunearth.html?day=26&month=09&year=2017&hour=12&min=40&sec=0&n=&ntxt=&earth=0

The pssolar_fill2.sh plots the astronomical twilight so it is also wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Terminator lines appear on top of each other on 2026-03-20

2 participants