Author Topic: A challenge for STx and any other math guys...  (Read 3964 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
A challenge for STx and any other math guys...
« on: December 25, 2020, 02:36:27 am »
Sort this math goobly-gook out into a decent set of QB64 functions for us:

https://farside.ph.utexas.edu/books/Syntaxis/Almagest/node36.html

Now, sort the math here out so that all one needs is something like:

PRINT Spring (2020)

FUNCTION Spring (year)
    ....math magic
END FUNCTION

And the output would be 20, since March 20th would be the first day of Spring.  Once you sort out Spring, all other seasons should, more or less, work off the same math stuff. 

Let's see who wants (and can) tackle this first!   ;D



(Honestly, I think some of you guys might like a lot of this stuff: https://farside.ph.utexas.edu/books/Syntaxis/Almagest/Almagest.html)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: A challenge for STx and any other math guys...
« Reply #1 on: December 25, 2020, 10:43:18 am »
It's a hell of a wheel to reinvent, doing this properly. The thing that makes me mad about celestial calculations is the number of exceptions, specials cases, redefinitions - just yuck. Not to mention pretty much all of the models are wrong except Kepler's. Anything that comes down from Ptolemy or those other wiseguys - is more confusing than helpful.

My approach, honestly, is to look at a working implementation of this stuff, and then borrow that code. I'm sure you found this while searching around:

https://stellafane.org/misc/equinox.html

When I view source on that page, I see some of the cleanest javascript I could ever expect to handle this. It seems like whoever made this probably accounted for lots of things that would take me a month to even realize were necessary.  Somewhere around line 100 is this chunk:

Code: [Select]
//-----Calculate and Display a single event for a single year (Either a Equiniox or Solstice)
// Meeus Astronmical Algorithms Chapter 27
function calcEquiSol( i, year ) {
var k = i - 1;
var str;
var JDE0 = calcInitial( k, year); // Initial estimate of date of event
var T = ( JDE0 - 2451545.0) / 36525;
var W = 35999.373*T - 2.47;
var dL = 1 + 0.0334*COS(W) + 0.0007*COS(2*W);
var S = periodic24( T );
var JDE = JDE0 + ( (0.00001*S) / dL ); // This is the answer in Julian Emphemeris Days
var TDT = fromJDtoUTC( JDE ); // Convert Julian Days to TDT in a Date Object
var UTC = fromTDTtoUTC( TDT ); // Correct TDT to UTC, both as Date Objects
switch ( getTZ() ) {
    case "LCL": str = UTC.toString()    + "\n"; break; //Convert to Local time string
    case "UTC": str = UTC.toUTCString() + "\n"; break; //Convert to UTC time string
    case "DYN": str = TDT.toUTCString() + "\n"; //Convert to Dynamical Time String
    str = str.replace( /UTC/g, "TDT" ); break; // Change UTC to TDT in this output string
    }
writeN( i, str ); // Output date & time of event in Local Time
} // End calcEquiSol

Yeah - big project...

There is another take on this, too - maybe don't bother calculating this stuff outright. Might be best to bite the bullet and import a table, eh?
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: A challenge for STx and any other math guys...
« Reply #2 on: December 25, 2020, 10:45:58 am »
Oh and, I absolutely cannot say where the hell this guy got his information, but a very short calculation is done here:

http://en.chinaculture.org/focus/focus/2011chunfen/2011-03/21/content_408904.htm

... but I don't trust it yet. Too easy.
You're not done when it works, you're done when it's right.

Offline Adrian

  • Newbie
  • Posts: 39
    • View Profile
Re: A challenge for STx and any other math guys...
« Reply #3 on: December 25, 2020, 11:17:27 pm »
Oh and, I absolutely cannot say where the hell this guy got his information, but a very short calculation is done here:

http://en.chinaculture.org/focus/focus/2011chunfen/2011-03/21/content_408904.htm

... but I don't trust it yet. Too easy.

Yup, tried it already. It is too easy and doesnt give correct results.
« Last Edit: December 28, 2020, 11:13:56 pm by Adrian »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: A challenge for STx and any other math guys...
« Reply #4 on: December 26, 2020, 03:40:28 am »
Count me out. I still haven't received my December shipment for my Mayan Calendar of the Month Club. Come to think of it, The last one came in December of 2012.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Adrian

  • Newbie
  • Posts: 39
    • View Profile
Re: A challenge for STx and any other math guys...
« Reply #5 on: December 28, 2020, 08:32:59 pm »
It's a hell of a wheel to reinvent, doing this properly. The thing that makes me mad about celestial calculations is the number of exceptions, specials cases, redefinitions - just yuck. Not to mention pretty much all of the models are wrong except Kepler's. Anything that comes down from Ptolemy or those other wiseguys - is more confusing than helpful.

My approach, honestly, is to look at a working implementation of this stuff, and then borrow that code. I'm sure you found this while searching around:

https://stellafane.org/misc/equinox.html

When I view source on that page, I see some of the cleanest javascript I could ever expect to handle this. It seems like whoever made this probably accounted for lots of things that would take me a month to even realize were necessary.  Somewhere around line 100 is this chunk:

Code: [Select]
//-----Calculate and Display a single event for a single year (Either a Equiniox or Solstice)
// Meeus Astronmical Algorithms Chapter 27
function calcEquiSol( i, year ) {
var k = i - 1;
var str;
var JDE0 = calcInitial( k, year); // Initial estimate of date of event
var T = ( JDE0 - 2451545.0) / 36525;
var W = 35999.373*T - 2.47;
var dL = 1 + 0.0334*COS(W) + 0.0007*COS(2*W);
var S = periodic24( T );
var JDE = JDE0 + ( (0.00001*S) / dL ); // This is the answer in Julian Emphemeris Days
var TDT = fromJDtoUTC( JDE ); // Convert Julian Days to TDT in a Date Object
var UTC = fromTDTtoUTC( TDT ); // Correct TDT to UTC, both as Date Objects
switch ( getTZ() ) {
    case "LCL": str = UTC.toString()    + "\n"; break; //Convert to Local time string
    case "UTC": str = UTC.toUTCString() + "\n"; break; //Convert to UTC time string
    case "DYN": str = TDT.toUTCString() + "\n"; //Convert to Dynamical Time String
    str = str.replace( /UTC/g, "TDT" ); break; // Change UTC to TDT in this output string
    }
writeN( i, str ); // Output date & time of event in Local Time
} // End calcEquiSol

Yeah - big project...

There is another take on this, too - maybe don't bother calculating this stuff outright. Might be best to bite the bullet and import a table, eh?

Looks like the initial estimate of the date (JDE0) is good enough for Steve's purposes.
« Last Edit: December 28, 2020, 10:49:39 pm by Adrian »

Offline Adrian

  • Newbie
  • Posts: 39
    • View Profile
Re: A challenge for STx and any other math guys...
« Reply #6 on: December 28, 2020, 10:47:18 pm »
Code: QB64: [Select]
  1. 'Seasons calculator  (Ref. Meeus Chapter 27)
  2. INPUT "Year "; year 'year between 2000 and 3000
  3. Y = (year - 2000) / 1000
  4. FOR i = 1 TO 4
  5.     SELECT CASE i
  6.         CASE 1: JD = 2451623.80984 + 365242.37404 * Y + 0.05169 * Y ^ 2 - 0.00411 * Y ^ 3 - 0.00057 * Y ^ 4 'Spring
  7.         CASE 2: JD = 2451716.56767 + 365241.62603 * Y + 0.00325 * Y ^ 2 + 0.00888 * Y ^ 3 - 0.00030 * Y ^ 4 'Summer
  8.         CASE 3: JD = 2451810.21715 + 365242.01767 * Y - 0.11575 * Y ^ 2 + 0.00337 * Y ^ 3 + 0.00078 * Y ^ 4 'Autumn
  9.         CASE 4: JD = 2451900.05952 + 365242.74049 * Y - 0.06223 * Y ^ 2 - 0.00823 * Y ^ 3 + 0.00032 * Y ^ 4 'Winter
  10.     END SELECT
  11.     'convert Julian Date (JD) to UTC Date (Ref. Meeus Astronomical Algorithms Chapter 7)
  12.     Z = INT(JD + 0.5) 'Integer JD's
  13.     F = (JD + 0.5) - Z 'Fractional JD's
  14.     IF Z < 2299161 THEN A = Z
  15.     IF Z >= 2299161 THEN
  16.         alpha = INT((Z - 1867216.25) / 36524.25)
  17.         A = Z + 1 + alpha - INT(alpha / 4)
  18.     END IF
  19.     B = A + 1524
  20.     C = INT((B - 122.1) / 365.25)
  21.     D = INT(365.25 * C)
  22.     E = INT((B - D) / 30.6001)
  23.     DT = B - D - INT(30.6001 * E) + F ' Day of Month with decimals for time
  24.     Day = INT(DT) ' Day of Month without decimals for time
  25.     SELECT CASE i
  26.         CASE 1: PRINT "Spring Equinox: March"; Day
  27.         CASE 2: PRINT "Summer Solstice: June"; Day
  28.         CASE 3: PRINT "Autumn Equinox: September"; Day
  29.         CASE 4: PRINT "Winter Solstice: December"; Day
  30.     END SELECT
  31.  

« Last Edit: December 29, 2020, 02:44:12 pm by Adrian »