Repository navigation
Spherical projections: precision near the poles, the equator and the centres; tmerc scale factor; Putnins P2 - #140
Conversation
|
Pushed 473f539: the spherical |
The forward took y from acos() of a value close to 1, which loses half the digits close to the equator, and gave y = 0 instead of pi * R * k0 for |longitudes| > 90 on the equator; atan2(|sin(phi)|, cos(phi) * cos(lam)) is the same angle without either problem. The inverse latitude is now atan2(|sin(D)|, hypot(g, h)) instead of asin(sqrt((1 - h * h) / (1 + g * g))). (The scale factor applied twice is fixed in master by locationtech#133.) The precision changes are the ones submitted to PROJ as OSGeo/PROJ#4944. Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
The spherical inverses of ortho, gnom, stere, aeqd and laea took the latitude from asin() of a value close to +/-1 near the poles, which loses half the digits (2 to 4 cm at the Moon's radius); atan2() of rh * sin(phi) and rh * hypot(cos(phi) * cos(lam), cos(phi) * sin(lam)) keeps them, and the polar stere uses pi/2 - c. The shortcuts within 1e-10 of the centre now apply at the centre only (they were up to 1e-10 * R off), and laea and aeqd no longer return longitude 0 instead of +/-90 where the cos(lam) term is exactly 0. aeqd forward: sin(c) from hypot() and c from atan2() instead of acos(cos(c)); points with cos(c) within 1e-14 of 1 went to the centre (240 m off at the Moon's radius), as in current PROJ. The same changes were submitted to PROJ as OSGeo/PROJ#4944. Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
The Newton iterations converge only linearly at the poles: Mollweide gave up after 10 iterations and snapped to the pole (254 km off at 89.3 degrees on a sphere of the Moon's radius), Eckert IV stopped 186 m off, and Putnins P2 (with the iteration on the auxiliary angle, as fixed in master by locationtech#133) also converges slowly there. Close to the poles the equations are now solved in terms of the distance of the angle from its polar value, and the inverses use the same relations instead of asin() of a value close to 1. Mollweide gets the 30 iterations of PROJ. The polar handling is the one submitted to PROJ as OSGeo/PROJ#4944. Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
15 points for tmerc, ortho, aeqd, laea, gnom, moll, eck4 and putp2 on a sphere of radius 6371000 m, with expected values from a 50-digit computation; the inverse is checked as a great-circle distance in metres. The test fails before the previous commits. Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
Close to the origin A, G and P of Snyder's (29-1) and (29-2) are all large and the forward subtracted them, which lost all the digits: points within 1e-7 degrees of the origin failed or went up to 5460 km off at the Moon's radius. The same values are now computed from a rearrangement in which no step subtracts two large terms. The shortcuts within 1e-10 of the equator and of the central meridian now apply to exact zeros only (they were off by up to 1e-10 * R), and the inverse longitude avoids the cancellation of sqrt(t) against pi^2 - r close to the origin (14 m). Three van der Grinten points added to ProjectionPrecisionTest. Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
The forward took d from acos(cos(phi) * cos(lam / 2)), which loses half the digits close to the origin (3.8 cm off at the Moon's radius). sin(d) from hypot() and d from atan2() keep them, as in PROJ. Four Aitoff and Winkel Tripel points added to ProjectionPrecisionTest (forward only: Proj4J has no inverse for these). Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
The forward used m after initialize() had divided it by w, so a second call of initialize() divided it again. m / w now has its own field. (Keeping the W and M set with setW() and setM() is fixed in master by locationtech#133.) Test: hammerUsesWAndM, with a 50-digit expected value for W = 0.25, M = 2. Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
cos(z) was computed as sqrt(1 - sin(z)^2), which loses its digits close to 90 degrees from the centre, where the coordinates are very large, and defeated the atan2() of the equatorial and oblique modes. The new test gnomonicInverseFarFromTheCentre checks 6 such points (expected values from 50-digit computations of the inverse of the same double inputs). Found by the proj4rs maintainer in the review of the same change there (3liz/proj4rs#65). Signed-off-by: SpaceOceanCorp <info@spaceoceancorp.com>
473f539 to
453b6f2
Compare
|
Hi there, really appreciate all your work here! While I could see it as an improvement; we'd have to align with OSGeo/PROJ#4944 I see some similar sentiments expressed on the PR boostorg/geometry#1513 Let's wait up until it gets merged in some way! I however I cherry picked and backported some of the fixes from this PR #143 |
|
Thanks for taking these in #143, and understood on staying aligned with PROJ. One note: OSGeo/PROJ#4944 was closed on 12 Nov rather than merged, so it may not land in that form. Fine to leave this open or close it, whichever suits you. Paul S. Mamakos, Space Ocean Corp |
Precision fixes for spherical projections, the same ones submitted to PROJ in OSGeo/PROJ#4944, plus three plain bugs found while measuring (tmerc, Putnins P2, Hammer). Independent of the separate PR with the PROJ string parameter fixes (
+R, polar stereographic, azimuthal defaults); either can be merged first.Measured on a sphere of radius 1737400 m against 50-digit references on the same double inputs (the inverse as a great-circle distance), master vs this branch:
Changes, in six commits plus a test:
ml0is already0.5 * k0for the sphere, and the forward multipliedxby the scale factor again, so with+k=0.999x was 0.1% short (the 121 m above). The forward also tookyfromacos()of a value close to 1 (half the digits lost near the equator) and gavey = 0instead ofpi * R * k0on the equator for |lon| > 90;atan2(|sin(phi)|, cos(phi) * cos(lam))is the same angle without either problem. The inverse latitude usesatan2(|sin(D)|, hypot(g, h)).atan2()instead ofasin()of a value close to +/-1, andpi/2 - cfor polar stere. The shortcuts withinEPS10of the centre now apply at the centre only: ortho took the longitude from the unscaledx, ythere, which put points within 1e-10 radians of the centre at longitude near 180 (the 5450 km above). laea and aeqd no longer return longitude 0 where the longitude is +/-90. The aeqd forward takessin(c)fromhypot()andcfromatan2()instead ofacos(cos(c)), which sent points withcos(c)within 1e-14 of 1 to the centre.out.yinstead of the auxiliary angle, so the angle stayed equal to the latitude and the result was not Putnins P2 (the 5190 km above). Near the poles the Newton iterations converge only linearly: Mollweide gave up after 10 iterations and snapped to the pole, Eckert IV stopped 186 m off. Near the poles the equations are now solved for the distance of the angle from its polar value, and the inverses use the same relations instead ofasin()near 1. Mollweide gets PROJ's 30 iterations.ProjectionPrecisionTest: 15 points (22 with the two later commits) on a sphere of radius 6371000 m with 50-digit expected values; it fails on master and passes here.sqrt(t)againstpi^2 - r. The inverse keeps its shortcut for |y| < 1e-10 (the 1.7e-4 m above), as PROJ does. Three points added to the test.sin(d)fromhypot()anddfromatan2()instead ofacos()of a value close to 1, as in PROJ. Four forward points added to the test.setW()andsetM()had no effect.initialize()replacedwandmby 0.5 and 1 whenever they were positive. They are now kept (new testhammerUsesWAndM).mvn testgives the same results as on master otherwise (all pass; the same 18 knownFAILlines printed by the existing comparison tests).Not changed here, noted: Aitoff, Winkel Tripel and Hammer have no inverse in Proj4J (
hasInverse()is false), andinverseProject()then returns its input unchanged rather than failing; PROJ has inverses for all three. The PROJ string parser does not read+W/+Mfor Hammer.