Author Topic: getradii and getplanet  (Read 270 times)

0 Members and 1 Guest are viewing this topic.

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
getradii and getplanet
« on: April 16, 2022, 10:12:21 PM »
Hi there - this function (getradii) calculates planetary distances. Depending on the settings within planetdance, it will either return geocentric or heliocentric distances in astronomical units. getplanet() can also be used to get the same data.

The following code is an example of how to use the functions:

real planetData[10][6], planetRads[14];

getradii(0, planetRads);

for (i < 10)
    getplanet(i , 0, planetData);

planetData is an array to hold data for the first 10 planets, with 6 items. Planetary distances are in the last field.

From the AB helpfile:

getplanet()

Syntax: getplanet(int planetnumber, int horoscopenumber, real result[6]);

Action: calculates a planet or body. Some results rely on a horoscope being calculated, for others only sethoroscopetime is needed. The array result will have these values:

0 longitude
1 latitude
2 speed (degree/day)
3 declination
4 rectascension
5 radius (astronomical units)

 More to follow!


Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 614
    • View Profile
Re: getradii and getplanet
« Reply #1 on: April 17, 2022, 07:28:52 AM »
nitpicking..  ;D

Code: [Select]
for (i < 10)
    getplanet(i , 0, planetData[i]);

ps. you can use the word 'code' between brackets like this 'code' bla bla '/code' but replace the ' with brackets []
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
Re: getradii and getplanet
« Reply #2 on: April 17, 2022, 07:44:26 AM »
Hi there - here is the code that finds the min and max distances from the Earth (if geocentric is set) by looking at the radii everyday for 100000 days prior to the current day. The output is attached. The first column is the values for the current day; the second column is minimum distance from the Earth (perigee); the third column is the maximum distance from the Earth over that period (apogee); the final column is the average distance.

Code: [Select]
i = 0; for (i < 100000){
  r = jdNow - i;
  ` calculate(char Index, real julianday, real placelongitude, real placelatitude, char housesystem);
  calculate(1, r, lon, lat, -2);
  getradii(1, planetRads);
  if (i = 0){
     j = 0; for (j < 14){
       minMaxDistances[0][j] = planetRads[j];
       minMaxDistances[1][j] = planetRads[j];}}
  else
      {j = 0; for (j < 14){
        if (planetRads[j] < minMaxDistances[0][j])
           minMaxDistances[0][j] = planetRads[j];
        if (planetRads[j] > minMaxDistances[1][j])
           minMaxDistances[1][j] = planetRads[j];}}}

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 614
    • View Profile
Re: getradii and getplanet
« Reply #3 on: April 17, 2022, 10:48:44 AM »
small improvement. What this does besides shorter code is eliminate the need to have that if (i = 0) condition evaluated 100000 times. A general rule is to have as little as possible code inside a loop.

ps. I modified your post to add code tags, see if you like it.

Code: [Select]
set(minMaxDistances[0], 10000000);
set(minMaxDistances[1], -1);
i = 0; for (i < 100000)
  {
  r = jdNow - i;
  ` calculate(char Index, real julianday, real placelongitude, real placelatitude, char housesystem);
  calculate(1, r, lon, lat, -2);
  getradii(1, planetRads);
  j = 0; for (j < 14)
    {
    if (planetRads[j] < minMaxDistances[0][j])
      minMaxDistances[0][j] = planetRads[j];
    if (planetRads[j] > minMaxDistances[1][j])
      minMaxDistances[1][j] = planetRads[j];
    }
  }
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
Re: getradii and getplanet
« Reply #4 on: April 17, 2022, 07:14:23 PM »
Thanks Jean - that tip is helpful.

Here is the final code. The second part of the code gets the planetary distances from getplanet(), puts the distances into an array with 100001 slots, sorts them from lowest to highest, and then transfers the middle distance (50001) to the array medianDistances. The attached output adds the median distance of the planet from the Earth. Notice that the average value and the median value are not the same. The median value may be a more accurate reflection of the planet's 'average' distance from the Earth as it will take account of the orbits are not circular.

Code: [Select]
real planetData[6], pDistances[100001], planetRads[14], minMaxDistances[2][10], medianDistances[10];
int sortedPDistances[100001];

` for current date - transits
getsystemtime(now);

jdNow = timetojulian(now);
jdDir = jdNow;

` apogee
set(minMaxDistances[0], 2000);
` perigee
set(minMaxDistances[1], -1);

i = 0; for (i < 100001){
  calculate(1, jdNow - i, lon, lat, -2);
  getradii(1, planetRads);
  j = 0; for (j < 10){
    if (planetRads[j] < minMaxDistances[0][j])
       minMaxDistances[0][j] = planetRads[j];
    if (planetRads[j] > minMaxDistances[1][j])
       minMaxDistances[1][j] = planetRads[j];}}
       
i = 0; for (i < 10){
  j = 0; for (j < 100001){
    calculate(1, jdNow - i, lon, lat, -2);
    getplanet(i , 0, planetData);
    pDistances[j] = planetData[5];}
    sort(pDistances, sortedPDistances, 0);
    medianDistances[i] = pDistances[50001];}

This is an example of 'extreme' Astrobasic - calculating 200002 horoscopes to extract this data. Who would have thought you could have an array with 100001 values! It takes a little bit of time, but in reality it's a blink of an eye.

Ed

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 614
    • View Profile
Re: getradii and getplanet
« Reply #5 on: April 17, 2022, 08:19:42 PM »
Some things i don't understand.

Code: [Select]
i = 0; for (i < 10)
  {
  j = 0; for (j < 100001)
    {
    calculate(1, jdNow - i, lon, lat, -2);
    getplanet(i , 0, planetData);
    pDistances[j] = planetData[5];
    }
  sort(pDistances, sortedPDistances, 0);
  medianDistances[i] = pDistances[50001];
  }

you sort values into sortedPDistances but you don't seem to use them.
In stead you are using one particular value out of pDistances[].
Does not make sense to me.
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
Re: getradii and getplanet
« Reply #6 on: April 17, 2022, 09:42:32 PM »
Hi Jean - it's to find the middle value. To find the median (middle) value, all the values need to be sorted from lowest to highest.The idea is that out of the 100001 days, the planet spends 50000 days (50%) at a distance less than the median AU distance, and 50000 (50%) days at a distance greater than the median AU distance. The median distance is the 50001st value in the array.

All the best. Ed

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 614
    • View Profile
Re: getradii and getplanet
« Reply #7 on: April 18, 2022, 07:23:58 AM »
then what are you doing with sortedPDistances[], you never seem to use it.
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
Re: getradii and getplanet
« Reply #8 on: April 18, 2022, 08:45:15 AM »
Hi Jean - I don't know any other way of sorting the values. I assumed that this variable had to be created to get the function to work. I don't need to use the variable as such. Is there another way to sort the values? The median is just the single value in the middle of all the sorted values.

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 614
    • View Profile
Re: getradii and getplanet
« Reply #9 on: April 18, 2022, 10:06:29 AM »
My fault, you're right, you need sortedPDistances even if you don't use it.
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
Re: getradii and getplanet
« Reply #10 on: April 18, 2022, 08:37:49 PM »
Here is the final output - table and graph.

On the graph, the horizontal bars mark the point, in % terms, where the median value in AU lies for each planet. The median value is the distance in astronomical units that lies at the point at which the planet spends 50% of its orbit between perigee and the median value, and 50% of its orbit between the median value and apogee. You will see that the median value in AU is often more than the average value (the midpoint in distance between apogee and perigee). This is because orbits are not circular, the planets do not orbit around the Earth, and the apparent speed of the planet is not regular.

Thanks. Ed

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 614
    • View Profile
Re: getradii and getplanet
« Reply #11 on: April 18, 2022, 08:49:52 PM »
Looks cool, it's part of a module, which one?
I assume you use previously calculated values or do you still use that 1000000 loop, if so, how fast is it?
Greetings from Groningen Netherlands <)))><.`.><(((>

ABer

  • Administrator
  • Hero Member
  • *****
  • Posts: 528
    • View Profile
Re: getradii and getplanet
« Reply #12 on: April 18, 2022, 09:32:25 PM »
Hi Jean - it's going to be in the next update of Cosmobiology. In the end I did a 200000 loop to make the figures as accurate as possible. I tried a 300000 loop, but the figures didn't vary much. 200000 is about 550 years, which captures at least 2 Pluto cycles, so 300000 is redundant data. I won't include the loop each time as it takes a while, but no more than 5 minutes I would say, probably less. The code was used to generate this array:

distanceArray[10][4] = { 0.98302429, 1.01697475, 0.99999952, 1.00408958 }, { 0.00238238, 0.00271865, 0.00255052, 0.00245624 },
       { 0.54908403, 1.45148001, 1.00028202, 1.15369470 }, { 0.26402321, 1.73610976, 1.00006648, 0.88283971 }, { 0.37272573, 2.67622323, 1.52447448, 1.72341608 },
       { 3.94873521, 6.45601472, 5.20237497, 5.82141580 }, { 8.00184101, 11.08963697, 9.54573899, 10.36503582 }, { 17.28781037, 21.09275074, 19.19028056, 20.63641862 },
       { 28.82187177, 31.32439679, 30.07313428, 30.80806348 }, { 28.68066290, 50.27479641, 39.47772965, 34.63600460 }

This is for Sun through Pluto: the first field is the perigee figure, the second apogee, the third is the average ((perigee + apogee) / 2), the final figure is the median value.

Ed