Skip to content

Commit 0309762

Browse files
committed
Fixed #347 - Relaxed convergence criteria for inverse_terra functions.
Asking the latitude and longitude directly beneath the Sun causes inverse_terra not to converge, because the convergence increment `W` never got below 1.48e-8, but the convergence limit was 1.0e-8. I increased the limit to 2.0e-8 in all programming language versions. I'm hoping that is a big enough tolerance for all cases now, but I will do more testing to see if further fixes are required for even more distant bodies than the Sun.
1 parent 1c6a11c commit 0309762

File tree

20 files changed

+35
-19
lines changed

20 files changed

+35
-19
lines changed

Diff for: demo/browser/astronomy.browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ function inverse_terra(ovec, st) {
19511951
const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2;
19521952
denom = Math.sqrt(radicand);
19531953
const W = (factor * sin * cos) / denom - z * cos + p * sin;
1954-
if (Math.abs(W) < 1.0e-8)
1954+
if (Math.abs(W) < 2.0e-8)
19551955
break; // The error is now negligible
19561956
// Error is still too large. Find the next estimate.
19571957
// Calculate D = the derivative of W with respect to lat.

Diff for: demo/nodejs/astronomy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ function inverse_terra(ovec, st) {
19501950
const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2;
19511951
denom = Math.sqrt(radicand);
19521952
const W = (factor * sin * cos) / denom - z * cos + p * sin;
1953-
if (Math.abs(W) < 1.0e-8)
1953+
if (Math.abs(W) < 2.0e-8)
19541954
break; // The error is now negligible
19551955
// Error is still too large. Find the next estimate.
19561956
// Calculate D = the derivative of W with respect to lat.

Diff for: demo/nodejs/calendar/astronomy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ function inverse_terra(ovec: ArrayVector, st: number): Observer {
21212121
const radicand = cos2 + EARTH_FLATTENING_SQUARED*sin2;
21222122
denom = Math.sqrt(radicand);
21232123
const W = (factor*sin*cos)/denom - z*cos + p*sin;
2124-
if (Math.abs(W) < 1.0e-8)
2124+
if (Math.abs(W) < 2.0e-8)
21252125
break; // The error is now negligible
21262126
// Error is still too large. Find the next estimate.
21272127
// Calculate D = the derivative of W with respect to lat.

Diff for: demo/python/astronomy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ def _inverse_terra(ovec: List[float], st: float) -> Observer:
14491449
radicand = cos2 + _EARTH_FLATTENING_SQUARED*sin2
14501450
denom = math.sqrt(radicand)
14511451
W = (factor*sin*cos)/denom - z*cos + p*sin
1452-
if abs(W) < 1.0e-8:
1452+
if abs(W) < 2.0e-8:
14531453
# The error is now negligible
14541454
break
14551455
# Error is still too large. Find the next estimate.

Diff for: generate/template/astronomy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ static astro_observer_t inverse_terra(const double ovec[3], double st)
18591859
radicand = c2 + F*s2;
18601860
denom = sqrt(radicand);
18611861
W = (factor*s*c)/denom - z*c + p*s;
1862-
if (fabs(W) < 1.0e-8)
1862+
if (fabs(W) < 2.0e-8)
18631863
break; /* The error is now negligible. */
18641864
/* Error is still too large. Find the next estimate. */
18651865
/* Calculate D = the derivative of W with respect to lat. */

Diff for: generate/template/astronomy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4176,7 +4176,7 @@ private static Observer inverse_terra(AstroVector ovec)
41764176
double radicand = c2 + F*s2;
41774177
denom = Math.Sqrt(radicand);
41784178
double W = (factor*s*c)/denom - z*c + p*s;
4179-
if (Math.Abs(W) < 1.0e-8)
4179+
if (Math.Abs(W) < 2.0e-8)
41804180
break; // The error is now negligible.
41814181
// Error is still too large. Find the next estimate.
41824182
// Calculate D = the derivative of W with respect to lat.

Diff for: generate/template/astronomy.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4384,7 +4384,7 @@ private fun inverseTerra(ovec: Vector): Observer {
43844384
val radicand = c2 + F*s2
43854385
denom = sqrt(radicand)
43864386
val W = ((factor * s * c) / denom) - (z * c) + (p * s)
4387-
if (W.absoluteValue < 1.0e-8)
4387+
if (W.absoluteValue < 2.0e-8)
43884388
break // The error is now negligible.
43894389
// Error is still too large. Find the next estimate.
43904390
// Calculate D = the derivative of W with respect to lat.

Diff for: generate/template/astronomy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ def _inverse_terra(ovec: List[float], st: float) -> Observer:
14491449
radicand = cos2 + _EARTH_FLATTENING_SQUARED*sin2
14501450
denom = math.sqrt(radicand)
14511451
W = (factor*sin*cos)/denom - z*cos + p*sin
1452-
if abs(W) < 1.0e-8:
1452+
if abs(W) < 2.0e-8:
14531453
# The error is now negligible
14541454
break
14551455
# Error is still too large. Find the next estimate.

Diff for: generate/template/astronomy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ function inverse_terra(ovec: ArrayVector, st: number): Observer {
13881388
const radicand = cos2 + EARTH_FLATTENING_SQUARED*sin2;
13891389
denom = Math.sqrt(radicand);
13901390
const W = (factor*sin*cos)/denom - z*cos + p*sin;
1391-
if (Math.abs(W) < 1.0e-8)
1391+
if (Math.abs(W) < 2.0e-8)
13921392
break; // The error is now negligible
13931393
// Error is still too large. Find the next estimate.
13941394
// Calculate D = the derivative of W with respect to lat.

Diff for: generate/test.js

+16
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,21 @@ function TwilightTest() {
28472847
}
28482848

28492849

2850+
function VectorObserverIssue347() {
2851+
// https://github.com/cosinekitty/astronomy/issues/347
2852+
const body = Astronomy.Body.Sun
2853+
for (let ts = 1717780096000; ts <= 1717780096200; ts++) {
2854+
var date = new Date(ts);
2855+
var vect = Astronomy.GeoVector(body, date, true)
2856+
//console.log('ts, date, vector', ts, date.valueOf(), vect)
2857+
var point = Astronomy.VectorObserver(vect)
2858+
//console.log('point', point)
2859+
//console.log('*')
2860+
}
2861+
return Pass('VectorObserverIssue347');
2862+
}
2863+
2864+
28502865
function Libration(filename) {
28512866
const lines = ReadLines(filename);
28522867
let max_diff_elon = 0.0;
@@ -3665,6 +3680,7 @@ const UnitTests = {
36653680
topostate: TopoStateTest,
36663681
transit: Transit,
36673682
twilight: TwilightTest,
3683+
vecobs: VectorObserverIssue347,
36683684
};
36693685

36703686

Diff for: source/c/astronomy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ static astro_observer_t inverse_terra(const double ovec[3], double st)
18651865
radicand = c2 + F*s2;
18661866
denom = sqrt(radicand);
18671867
W = (factor*s*c)/denom - z*c + p*s;
1868-
if (fabs(W) < 1.0e-8)
1868+
if (fabs(W) < 2.0e-8)
18691869
break; /* The error is now negligible. */
18701870
/* Error is still too large. Find the next estimate. */
18711871
/* Calculate D = the derivative of W with respect to lat. */

Diff for: source/csharp/astronomy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5310,7 +5310,7 @@ private static Observer inverse_terra(AstroVector ovec)
53105310
double radicand = c2 + F*s2;
53115311
denom = Math.Sqrt(radicand);
53125312
double W = (factor*s*c)/denom - z*c + p*s;
5313-
if (Math.Abs(W) < 1.0e-8)
5313+
if (Math.Abs(W) < 2.0e-8)
53145314
break; // The error is now negligible.
53155315
// Error is still too large. Find the next estimate.
53165316
// Calculate D = the derivative of W with respect to lat.

Diff for: source/js/astronomy.browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ function inverse_terra(ovec, st) {
19511951
const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2;
19521952
denom = Math.sqrt(radicand);
19531953
const W = (factor * sin * cos) / denom - z * cos + p * sin;
1954-
if (Math.abs(W) < 1.0e-8)
1954+
if (Math.abs(W) < 2.0e-8)
19551955
break; // The error is now negligible
19561956
// Error is still too large. Find the next estimate.
19571957
// Calculate D = the derivative of W with respect to lat.

Diff for: source/js/astronomy.browser.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: source/js/astronomy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ function inverse_terra(ovec, st) {
19501950
const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2;
19511951
denom = Math.sqrt(radicand);
19521952
const W = (factor * sin * cos) / denom - z * cos + p * sin;
1953-
if (Math.abs(W) < 1.0e-8)
1953+
if (Math.abs(W) < 2.0e-8)
19541954
break; // The error is now negligible
19551955
// Error is still too large. Find the next estimate.
19561956
// Calculate D = the derivative of W with respect to lat.

Diff for: source/js/astronomy.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: source/js/astronomy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ function inverse_terra(ovec: ArrayVector, st: number): Observer {
21212121
const radicand = cos2 + EARTH_FLATTENING_SQUARED*sin2;
21222122
denom = Math.sqrt(radicand);
21232123
const W = (factor*sin*cos)/denom - z*cos + p*sin;
2124-
if (Math.abs(W) < 1.0e-8)
2124+
if (Math.abs(W) < 2.0e-8)
21252125
break; // The error is now negligible
21262126
// Error is still too large. Find the next estimate.
21272127
// Calculate D = the derivative of W with respect to lat.

Diff for: source/js/esm/astronomy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ function inverse_terra(ovec, st) {
19331933
const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2;
19341934
denom = Math.sqrt(radicand);
19351935
const W = (factor * sin * cos) / denom - z * cos + p * sin;
1936-
if (Math.abs(W) < 1.0e-8)
1936+
if (Math.abs(W) < 2.0e-8)
19371937
break; // The error is now negligible
19381938
// Error is still too large. Find the next estimate.
19391939
// Calculate D = the derivative of W with respect to lat.

Diff for: source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4384,7 +4384,7 @@ private fun inverseTerra(ovec: Vector): Observer {
43844384
val radicand = c2 + F*s2
43854385
denom = sqrt(radicand)
43864386
val W = ((factor * s * c) / denom) - (z * c) + (p * s)
4387-
if (W.absoluteValue < 1.0e-8)
4387+
if (W.absoluteValue < 2.0e-8)
43884388
break // The error is now negligible.
43894389
// Error is still too large. Find the next estimate.
43904390
// Calculate D = the derivative of W with respect to lat.

Diff for: source/python/astronomy/astronomy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ def _inverse_terra(ovec: List[float], st: float) -> Observer:
14491449
radicand = cos2 + _EARTH_FLATTENING_SQUARED*sin2
14501450
denom = math.sqrt(radicand)
14511451
W = (factor*sin*cos)/denom - z*cos + p*sin
1452-
if abs(W) < 1.0e-8:
1452+
if abs(W) < 2.0e-8:
14531453
# The error is now negligible
14541454
break
14551455
# Error is still too large. Find the next estimate.

0 commit comments

Comments
 (0)