diff --git a/demo/browser/astronomy.browser.js b/demo/browser/astronomy.browser.js index d77e3f47..b9ac051e 100644 --- a/demo/browser/astronomy.browser.js +++ b/demo/browser/astronomy.browser.js @@ -1951,7 +1951,7 @@ function inverse_terra(ovec, st) { const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2; denom = Math.sqrt(radicand); const W = (factor * sin * cos) / denom - z * cos + p * sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/demo/nodejs/astronomy.js b/demo/nodejs/astronomy.js index 5d784b6e..94dd87ad 100644 --- a/demo/nodejs/astronomy.js +++ b/demo/nodejs/astronomy.js @@ -1950,7 +1950,7 @@ function inverse_terra(ovec, st) { const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2; denom = Math.sqrt(radicand); const W = (factor * sin * cos) / denom - z * cos + p * sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/demo/nodejs/calendar/astronomy.ts b/demo/nodejs/calendar/astronomy.ts index 1c5abaa5..52c0970d 100644 --- a/demo/nodejs/calendar/astronomy.ts +++ b/demo/nodejs/calendar/astronomy.ts @@ -2121,7 +2121,7 @@ function inverse_terra(ovec: ArrayVector, st: number): Observer { const radicand = cos2 + EARTH_FLATTENING_SQUARED*sin2; denom = Math.sqrt(radicand); const W = (factor*sin*cos)/denom - z*cos + p*sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/demo/python/astronomy.py b/demo/python/astronomy.py index 12b70845..d20ae486 100644 --- a/demo/python/astronomy.py +++ b/demo/python/astronomy.py @@ -1449,7 +1449,7 @@ def _inverse_terra(ovec: List[float], st: float) -> Observer: radicand = cos2 + _EARTH_FLATTENING_SQUARED*sin2 denom = math.sqrt(radicand) W = (factor*sin*cos)/denom - z*cos + p*sin - if abs(W) < 1.0e-8: + if abs(W) < 2.0e-8: # The error is now negligible break # Error is still too large. Find the next estimate. diff --git a/generate/template/astronomy.c b/generate/template/astronomy.c index 26d8ce5e..0fe7bc3e 100644 --- a/generate/template/astronomy.c +++ b/generate/template/astronomy.c @@ -1859,7 +1859,7 @@ static astro_observer_t inverse_terra(const double ovec[3], double st) radicand = c2 + F*s2; denom = sqrt(radicand); W = (factor*s*c)/denom - z*c + p*s; - if (fabs(W) < 1.0e-8) + if (fabs(W) < 2.0e-8) break; /* The error is now negligible. */ /* Error is still too large. Find the next estimate. */ /* Calculate D = the derivative of W with respect to lat. */ diff --git a/generate/template/astronomy.cs b/generate/template/astronomy.cs index 8bc9279b..667fc395 100644 --- a/generate/template/astronomy.cs +++ b/generate/template/astronomy.cs @@ -4176,7 +4176,7 @@ namespace CosineKitty double radicand = c2 + F*s2; denom = Math.Sqrt(radicand); double W = (factor*s*c)/denom - z*c + p*s; - if (Math.Abs(W) < 1.0e-8) + if (Math.Abs(W) < 2.0e-8) break; // The error is now negligible. // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/generate/template/astronomy.kt b/generate/template/astronomy.kt index c7f6bf6b..fbebfc66 100644 --- a/generate/template/astronomy.kt +++ b/generate/template/astronomy.kt @@ -4384,7 +4384,7 @@ private fun inverseTerra(ovec: Vector): Observer { val radicand = c2 + F*s2 denom = sqrt(radicand) val W = ((factor * s * c) / denom) - (z * c) + (p * s) - if (W.absoluteValue < 1.0e-8) + if (W.absoluteValue < 2.0e-8) break // The error is now negligible. // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 657a33ef..eccf13be 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -1449,7 +1449,7 @@ def _inverse_terra(ovec: List[float], st: float) -> Observer: radicand = cos2 + _EARTH_FLATTENING_SQUARED*sin2 denom = math.sqrt(radicand) W = (factor*sin*cos)/denom - z*cos + p*sin - if abs(W) < 1.0e-8: + if abs(W) < 2.0e-8: # The error is now negligible break # Error is still too large. Find the next estimate. diff --git a/generate/template/astronomy.ts b/generate/template/astronomy.ts index 068aadda..2ce04931 100644 --- a/generate/template/astronomy.ts +++ b/generate/template/astronomy.ts @@ -1388,7 +1388,7 @@ function inverse_terra(ovec: ArrayVector, st: number): Observer { const radicand = cos2 + EARTH_FLATTENING_SQUARED*sin2; denom = Math.sqrt(radicand); const W = (factor*sin*cos)/denom - z*cos + p*sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/generate/test.js b/generate/test.js index 8455fa46..2d18f345 100644 --- a/generate/test.js +++ b/generate/test.js @@ -2847,6 +2847,21 @@ function TwilightTest() { } +function VectorObserverIssue347() { + // https://github.com/cosinekitty/astronomy/issues/347 + const body = Astronomy.Body.Sun + for (let ts = 1717780096000; ts <= 1717780096200; ts++) { + var date = new Date(ts); + var vect = Astronomy.GeoVector(body, date, true) + //console.log('ts, date, vector', ts, date.valueOf(), vect) + var point = Astronomy.VectorObserver(vect) + //console.log('point', point) + //console.log('*') + } + return Pass('VectorObserverIssue347'); +} + + function Libration(filename) { const lines = ReadLines(filename); let max_diff_elon = 0.0; @@ -3665,6 +3680,7 @@ const UnitTests = { topostate: TopoStateTest, transit: Transit, twilight: TwilightTest, + vecobs: VectorObserverIssue347, }; diff --git a/source/c/astronomy.c b/source/c/astronomy.c index 62f95d04..291534a8 100644 --- a/source/c/astronomy.c +++ b/source/c/astronomy.c @@ -1865,7 +1865,7 @@ static astro_observer_t inverse_terra(const double ovec[3], double st) radicand = c2 + F*s2; denom = sqrt(radicand); W = (factor*s*c)/denom - z*c + p*s; - if (fabs(W) < 1.0e-8) + if (fabs(W) < 2.0e-8) break; /* The error is now negligible. */ /* Error is still too large. Find the next estimate. */ /* Calculate D = the derivative of W with respect to lat. */ diff --git a/source/csharp/astronomy.cs b/source/csharp/astronomy.cs index 8b5876f4..b886cf28 100644 --- a/source/csharp/astronomy.cs +++ b/source/csharp/astronomy.cs @@ -5310,7 +5310,7 @@ namespace CosineKitty double radicand = c2 + F*s2; denom = Math.Sqrt(radicand); double W = (factor*s*c)/denom - z*c + p*s; - if (Math.Abs(W) < 1.0e-8) + if (Math.Abs(W) < 2.0e-8) break; // The error is now negligible. // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/source/js/astronomy.browser.js b/source/js/astronomy.browser.js index d77e3f47..b9ac051e 100644 --- a/source/js/astronomy.browser.js +++ b/source/js/astronomy.browser.js @@ -1951,7 +1951,7 @@ function inverse_terra(ovec, st) { const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2; denom = Math.sqrt(radicand); const W = (factor * sin * cos) / denom - z * cos + p * sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/source/js/astronomy.browser.min.js b/source/js/astronomy.browser.min.js index 70fde9cd..e86dcdfa 100644 --- a/source/js/astronomy.browser.min.js +++ b/source/js/astronomy.browser.min.js @@ -176,7 +176,7 @@ k));l=Math.asin(-Math.sin(t)*Math.cos(h)*Math.sin(l)-Math.sin(h)*Math.cos(l));t= d;this.vy=f;this.vz=g;this.t=h};e.StateVector=I;var Ba=function(a,b,c){this.lat=w(a);this.lon=w(b);this.dist=w(c)};e.Spherical=Ba;var gb=function(a,b,c,d){this.ra=w(a);this.dec=w(b);this.dist=w(c);this.vec=d};e.EquatorialCoordinates=gb;var J=function(a){this.rot=a};e.RotationMatrix=J;e.MakeRotation=function(a){if(!qd(a))throw"Argument must be a [3][3] array of numbers";return new J(a)};var ec=function(a,b,c,d){this.azimuth=w(a);this.altitude=w(b);this.ra=w(c);this.dec=w(d)};e.HorizontalCoordinates= ec;var gc=function(a,b,c){this.vec=a;this.elat=w(b);this.elon=w(c)};e.EclipticCoordinates=gc;e.Horizon=hb;var zb=function(a,b,c){this.latitude=a;this.longitude=b;this.height=c;za(this)};e.Observer=zb;e.SunPosition=fc;e.Equator=Pa;e.ObserverVector=function(a,b,c){a=v(a);var d=ca(a);b=xb(b,d).pos;c||(b=fb(b,a,F.Into2000));return yb(b,a)};e.ObserverState=function(a,b,c){a=v(a);var d=ca(a);b=xb(b,d);b=new I(b.pos[0],b.pos[1],b.pos[2],b.vel[0],b.vel[1],b.vel[2],a);return c?b:(c=F.Into2000,c===F.Into2000? (d=Na(a,c),b=Ea(d,b),a=Ma(a,c),a=Ea(a,b)):(d=Ma(a,c),b=Ea(d,b),a=Na(a,c),a=Ea(a,b)),a)};e.VectorObserver=function(a,b){var c=ca(a.t),d=[a.x,a.y,a.z];b||(d=wa(d,a.t,F.From2000),d=xa(d,a.t,F.From2000));b=d[0]*e.KM_PER_AU;var f=d[1]*e.KM_PER_AU;d=d[2]*e.KM_PER_AU;a=Math.hypot(b,f);if(1E-6>a){c=0;var g=0=c;)c+=360;for(;180Math.abs(q))break;g-=q/(-42.69778487239616*((k-n)/h-n*k*-.006694397995865464/(-42.69778487239616*p))+d*f+a*b)}g*=e.RAD2DEG;h=6378.1366/h;d=Math.abs(f)>Math.abs(b)?d/f-.9933056020041345*h:a/b-h}return new zb(g,c,1E3*d)};e.ObserverGravity=function(a,b){a=Math.sin(a*e.DEG2RAD);a*=a;return 9.7803253359*(1+.00193185265241*a)/Math.sqrt(1-.00669437999013*a)*(1-(3.15704E-7-2.10269E-9* +b=Math.cos(g);f=Math.sin(g);var k=b*b,n=f*f,p=k+.9933056020041345*n;h=Math.sqrt(p);var q=-42.69778487239616*f*b/h-d*b+a*f;if(2E-8>Math.abs(q))break;g-=q/(-42.69778487239616*((k-n)/h-n*k*-.006694397995865464/(-42.69778487239616*p))+d*f+a*b)}g*=e.RAD2DEG;h=6378.1366/h;d=Math.abs(f)>Math.abs(b)?d/f-.9933056020041345*h:a/b-h}return new zb(g,c,1E3*d)};e.ObserverGravity=function(a,b){a=Math.sin(a*e.DEG2RAD);a*=a;return 9.7803253359*(1+.00193185265241*a)/Math.sqrt(1-.00669437999013*a)*(1-(3.15704E-7-2.10269E-9* a)*b+7.37452E-14*b*b)};e.Ecliptic=Qa;e.GeoMoon=Y;e.EclipticGeoMoon=ib;e.GeoMoonState=Ra;e.GeoEmbState=Bb;var na=[[-73E4,[-26.118207232108,-14.376168177825,3.384402515299],[.0016339372163656,-.0027861699588508,-.0013585880229445]],[-700800,[41.974905202127,-.448502952929,-12.770351505989],[7.3458569351457E-4,.0022785014891658,4.8619778602049E-4]],[-671600,[14.706930780744,44.269110540027,9.353698474772],[-.00210001479998,2.2295915939915E-4,7.0143443551414E-4]],[-642400,[-29.441003929957,-6.43016153057, 6.858481011305],[8.4495803960544E-4,-.0030783914758711,-.0012106305981192]],[-613200,[39.444396946234,-6.557989760571,-13.913760296463],[.0011480029005873,.0022400006880665,3.5168075922288E-4]],[-584E3,[20.2303809507,43.266966657189,7.382966091923],[-.0019754081700585,5.3457141292226E-4,7.5929169129793E-4]],[-554800,[-30.65832536462,2.093818874552,9.880531138071],[6.1010603013347E-5,-.0031326500935382,-9.9346125151067E-4]],[-525600,[35.737703251673,-12.587706024764,-14.677847247563],[.0015802939375649, .0021347678412429,1.9074436384343E-4]],[-496400,[25.466295188546,41.367478338417,5.216476873382],[-.0018054401046468,8.328308359951E-4,8.0260156912107E-4]],[-467200,[-29.847174904071,10.636426313081,12.297904180106],[-6.3257063052907E-4,-.0029969577578221,-7.4476074151596E-4]],[-438E3,[30.774692107687,-18.236637015304,-14.945535879896],[.0020113162005465,.0019353827024189,-2.0937793168297E-6]],[-408800,[30.243153324028,38.656267888503,2.938501750218],[-.0016052508674468,.0011183495337525,8.3333973416824E-4]], diff --git a/source/js/astronomy.js b/source/js/astronomy.js index 5d784b6e..94dd87ad 100644 --- a/source/js/astronomy.js +++ b/source/js/astronomy.js @@ -1950,7 +1950,7 @@ function inverse_terra(ovec, st) { const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2; denom = Math.sqrt(radicand); const W = (factor * sin * cos) / denom - z * cos + p * sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/source/js/astronomy.min.js b/source/js/astronomy.min.js index d3a1a1b0..52b23383 100644 --- a/source/js/astronomy.min.js +++ b/source/js/astronomy.min.js @@ -128,7 +128,7 @@ function precession_rot(a,b){a=a.tt/36525;var c=84381.406,d=((((3.337E-7*a-4.67E k,p=-h*e-g*l*d,r=-h*g*c+l*d*e*c-a*l*k;h=-h*g*a+l*d*e*a+c*l*k;g*=k;l=-k*e*c-a*d;a=-k*e*a+d*c;if(b===PrecessDirection.Into2000)return new RotationMatrix([[f,m,n],[p,r,h],[g,l,a]]);if(b===PrecessDirection.From2000)return new RotationMatrix([[f,p,g],[m,r,l],[n,h,a]]);throw"Invalid precess direction";}function era(a){a=(.779057273264+.00273781191135448*a.ut+a.ut%1)%1*360;0>a&&(a+=360);return a}var sidereal_time_cache; function sidereal_time(a){if(!sidereal_time_cache||sidereal_time_cache.tt!==a.tt){var b=a.tt/36525,c=15*e_tilt(a).ee,d=era(a);b=((c+.014506+((((-3.68E-8*b-2.9956E-5)*b-4.4E-7)*b+1.3915817)*b+4612.156534)*b)/3600+d)%360/15;0>b&&(b+=24);sidereal_time_cache={tt:a.tt,st:b}}return sidereal_time_cache.st}function SiderealTime(a){a=MakeTime(a);return sidereal_time(a)}exports.SiderealTime=SiderealTime; function inverse_terra(a,b){var c=a[0]*exports.KM_PER_AU,d=a[1]*exports.KM_PER_AU;a=a[2]*exports.KM_PER_AU;var e=Math.hypot(c,d);if(1E-6>e){b=0;var f=0=b;)b+=360;for(;180Math.abs(p))break;f-=p/(h*((l-m)/g-m*l*(EARTH_FLATTENING_SQUARED-1)/(h*n))+a*d+e*c)}f*=exports.RAD2DEG;g=EARTH_EQUATORIAL_RADIUS_KM/g;a=Math.abs(d)>Math.abs(c)?a/d-EARTH_FLATTENING_SQUARED*g:e/c-g}return new Observer(f,b,1E3*a)} +Math.sqrt(n);var p=h*d*c/g-a*c+e*d;if(2E-8>Math.abs(p))break;f-=p/(h*((l-m)/g-m*l*(EARTH_FLATTENING_SQUARED-1)/(h*n))+a*d+e*c)}f*=exports.RAD2DEG;g=EARTH_EQUATORIAL_RADIUS_KM/g;a=Math.abs(d)>Math.abs(c)?a/d-EARTH_FLATTENING_SQUARED*g:e/c-g}return new Observer(f,b,1E3*a)} function terra(a,b){var c=a.latitude*exports.DEG2RAD,d=Math.sin(c);c=Math.cos(c);var e=1/Math.hypot(c,EARTH_FLATTENING*d),f=a.height/1E3,g=EARTH_EQUATORIAL_RADIUS_KM*e+f;b=(15*b+a.longitude)*exports.DEG2RAD;a=Math.sin(b);b=Math.cos(b);return{pos:[g*c*b/exports.KM_PER_AU,g*c*a/exports.KM_PER_AU,(EARTH_EQUATORIAL_RADIUS_KM*EARTH_FLATTENING_SQUARED*e+f)*d/exports.KM_PER_AU],vel:[-ANGVEL*g*c*a*86400/exports.KM_PER_AU,ANGVEL*g*c*b*86400/exports.KM_PER_AU,0]}} function nutation(a,b,c){b=nutation_rot(b,c);return rotate(b,a)}function nutation_posvel(a,b,c){b=nutation_rot(b,c);return RotateState(b,a)} function nutation_rot(a,b){a=e_tilt(a);var c=a.mobl*exports.DEG2RAD,d=a.tobl*exports.DEG2RAD,e=a.dpsi*ASEC2RAD;a=Math.cos(c);c=Math.sin(c);var f=Math.cos(d),g=Math.sin(d);d=Math.cos(e);var k=Math.sin(e);e=-k*a;var h=-k*c,l=k*f,m=d*a*f+c*g,n=d*c*f-a*g;k*=g;var p=d*a*g-c*f;a=d*c*g+a*f;if(b===PrecessDirection.From2000)return new RotationMatrix([[d,l,k],[e,m,p],[h,n,a]]);if(b===PrecessDirection.Into2000)return new RotationMatrix([[d,e,h],[l,m,n],[k,p,a]]);throw"Invalid precess direction";} diff --git a/source/js/astronomy.ts b/source/js/astronomy.ts index 1c5abaa5..52c0970d 100644 --- a/source/js/astronomy.ts +++ b/source/js/astronomy.ts @@ -2121,7 +2121,7 @@ function inverse_terra(ovec: ArrayVector, st: number): Observer { const radicand = cos2 + EARTH_FLATTENING_SQUARED*sin2; denom = Math.sqrt(radicand); const W = (factor*sin*cos)/denom - z*cos + p*sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/source/js/esm/astronomy.js b/source/js/esm/astronomy.js index 96cdb9cd..d095213c 100644 --- a/source/js/esm/astronomy.js +++ b/source/js/esm/astronomy.js @@ -1933,7 +1933,7 @@ function inverse_terra(ovec, st) { const radicand = cos2 + EARTH_FLATTENING_SQUARED * sin2; denom = Math.sqrt(radicand); const W = (factor * sin * cos) / denom - z * cos + p * sin; - if (Math.abs(W) < 1.0e-8) + if (Math.abs(W) < 2.0e-8) break; // The error is now negligible // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt b/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt index 2e545f39..a78fd16a 100644 --- a/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt +++ b/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt @@ -4384,7 +4384,7 @@ private fun inverseTerra(ovec: Vector): Observer { val radicand = c2 + F*s2 denom = sqrt(radicand) val W = ((factor * s * c) / denom) - (z * c) + (p * s) - if (W.absoluteValue < 1.0e-8) + if (W.absoluteValue < 2.0e-8) break // The error is now negligible. // Error is still too large. Find the next estimate. // Calculate D = the derivative of W with respect to lat. diff --git a/source/python/astronomy/astronomy.py b/source/python/astronomy/astronomy.py index 12b70845..d20ae486 100644 --- a/source/python/astronomy/astronomy.py +++ b/source/python/astronomy/astronomy.py @@ -1449,7 +1449,7 @@ def _inverse_terra(ovec: List[float], st: float) -> Observer: radicand = cos2 + _EARTH_FLATTENING_SQUARED*sin2 denom = math.sqrt(radicand) W = (factor*sin*cos)/denom - z*cos + p*sin - if abs(W) < 1.0e-8: + if abs(W) < 2.0e-8: # The error is now negligible break # Error is still too large. Find the next estimate.