Post Reply 
Astronomy: Lunar
07-20-2019, 09:10 PM (This post was last modified: 07-20-2019 09:22 PM by StephenG1CMZ.)
Post: #1
Astronomy: Lunar
In celebration of the 50th anniversary of the Apollo 11 Moon Landing, here is a simple Lunar Astronomy program.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
07-20-2019, 09:17 PM (This post was last modified: 07-21-2019 09:54 AM by StephenG1CMZ.)
Post: #2
RE: Astronomy: Lunar
Version 1 illustrates the Moon, the Earth, the Moon's orbit around the Earth, and animates the light-distance of the Moon from the Earth.

Variable XG can be changed to exaggerate the non-spherical/non-circular shape.
Caution: Changing that value will also change the listed radius values.

Code:


 
 LOCAL CRID:="Lunar V1.0 © 2019 StephenG1CMZ";

 //CUSTOMISE
 LOCAL XG:=1;//EXAGERATE XY SCALING,1=NORMAL
  //VISUALLY CHANGE XY SCALING, TO EXAGERRATE NON-CIRCULARITY
  //(NOTE-CIRCULAR ITEMS ARE UNCHANGED,SO IT IS NOT IDEAL FOR ACCOMODATING NONSQUARE PIXELS)
  //NB REPORTING OF POLAR RADIUS ETC MAY ALSO CHANGE, RUN WITH XG=1 FOR STANDARD VALUES
 //END CUSTOM

 //COLOURS
 LOCAL BLUE    :=RGB(0,0,255);
 LOCAL GREEN   :=RGB(0,255,0);
 LOCAL MOONGLOW:=RGB(244,201,201);
 LOCAL RED     :=RGB(255,0,0); 
 LOCAL YELLOWISH :=RGB(255,120,0);

 //SCRN
 LOCAL SW:=320;
 LOCAL LEFTX:=SW/3;
 LOCAL RIGHTX:=2*SW/3;
 LOCAL MIDX:=320/2;
 LOCAL MIDY:=240/2;

 LOCAL MOONX:=LEFTX;
 LOCAL EARTHX:=MIDX;

 LOCAL EARTHRR:={6378.1,6356.8/XG};//KM
 LOCAL EARTHR:=EARTHRR(1);
 LOCAL EARTHEQ:=EARTHRR(1);
 LOCAL MOONRR:={1738.1,1736.0/XG};//KM
 LOCAL MOONR:=MOONRR(1);
 LOCAL MOONEQ:=MOONRR(1);
 LOCAL ORADIUSRR:={0.4055ᴇ6,0.3633ᴇ6/XG};//KM
 LOCAL ORADIUS:=ORADIUSRR(1);
 //LOCAL RADIUS:={};
 LOCAL STATI:=35876;
 LOCAL EARTHDENS:=5514;//KG/m3
 LOCAL MOONDENS:=3344; //KG/m3
 
 LOCAL MAXKM:=400000;
 
 //For radius down half the screen (allowing titles)
 LOCAL PIXELS:=100;//for the main sphere or orbit radius (ie half*MIN(320,240), less border edges)
 LOCAL SCL:=PIXELS/MAXKM;

 LOCAL DT:=1.27;//s //If you wish, *XG to exagerate seconds too
 LOCAL DTPP:=1*DT/PIXELS;//s per pixel
 LOCAL PX;
 LOCAL RR;

 EXPORT GetRoche(RADIUS1,DENS1,DENS2)
 //ROCHE LIMIT DEPENDS ON
 //RADIUS OF PRIMARY
 //RELATIVE DENSITIES OF PRIMARY AND SECONDARY
 //RETURN ROCHE LIMIT RADIUS IN RADIUS1 UNITS
 BEGIN
 
  //MSGBOX({RADIUS1,DENS1,DENS2});
  RR:=RADIUS1*(2*DENS1/DENS2)^(1/3);
  //MSGBOX(RR);
  //RR:=9492;//EXPECTED VALUE:FIX POOR CALC
  RETURN ROUND(RR,0);
 END;

 INITS()
 BEGIN
  RECT_P();
  TEXTOUT_P(CRID,0,0);
 END;

 EXPORT TheMoon()
 BEGIN
  LOCAL SCL:=PIXELS/2000;
  INITS(); 
  
  ARC_P(MOONX,MIDY,ROUND(MOONRR*SCL,0),{YELLOWISH,MOONGLOW});
  //ARC_P(MOONX,MIDY,ROUND(MOONREQ*SCL,0),{RED});

  TEXTOUT_P("Moon",MOONX,210);
  TEXTOUT_P("Radius  "+MOONRR+"km",0,20,0);
  
  WAIT;
 END;

 TheEarthy(SCL)
 BEGIN
  
  INITS(); 
 
  ARC_P(EARTHX,MIDY,ROUND(EARTHRR*SCL,0),{BLUE,BLUE});
  //ARC_P(EARTHX,MIDY,ROUND(EARTHEQ*SCL,0),{GREEN});//COMPARE WITH CIRCULAR
 
  //TEXTOUT_P("Earth",EARTHX,210,0,BLUE);
 
 END;

 EXPORT TheEarth()
 BEGIN
  LOCAL RR;
  LOCAL SCL:=PIXELS/7500;
  TheEarthy(SCL); 
  ARC_P(MOONX,MIDY,ROUND(MOONRR*SCL,0),{YELLOWISH,MOONGLOW});//COMPARE WITH MOON
  TEXTOUT_P("Moon",MOONX-20,MIDY-10); 
  TEXTOUT_P("Radius  "+EARTHRR+"km",0,20,0);
  WAIT;

  RR:=GetRoche(EARTHR,EARTHDENS,MOONDENS);//FIX
  
  SCL:=PIXELS/STATI;

  TheEarthy(SCL);
  //PX:=PIXELS*(STATI/ORADIUS);
  
  ARC_P(EARTHX,MIDY,STATI*SCL,GREEN); //E STATIONARY 
  ARC_P(EARTHX,MIDY,RR*SCL,RED); //E ROCHE
  TEXTOUT_P("Earth  ",0,MIDY,0,BLUE); 
  TEXTOUT_P("Stationary Radius  "+STATI+" km",320/4,40,0,GREEN);
  TEXTOUT_P("Roche Radius       "+RR   +" km",320/4,60,0,RED);
  ARC_P(EARTHX,MIDY,RR*SCL,RED);
  WAIT;
 END;

 EXPORT EM()
 BEGIN
  LOCAL II;
  LOCAL SCL:=PIXELS/MAXKM;
  TheEarth();
  INITS();TheEarthy(SCL);
  PX:=PIXELS*(STATI/ORADIUS);
  //MSGBOX(STATI*SCL);
  WAIT;
  ARC_P(MIDX,MIDY,STATI*SCL,GREEN);
  TEXTOUT_P("Stationary Radius  "+STATI+" km",320/4,20,0,GREEN);
 
  PX:=PIXELS; //RADIUS*SCL;
  ARC_P(MIDX,MIDY,{PX,PX/XG},MOONGLOW);//NEEDS FIXING
 //TO PROPERLY REFERENCE THE TWO ORADIUS VALUES
  TEXTOUT_P("Radius  "+ORADIUSRR+"km",0,40,0,YELLOWISH); 
  WAIT;
  TEXTOUT_P("That's one small step for a man",MIDX-PIXELS+10,MIDY-20,2);
  FOR II FROM PIXELS DOWNTO 2 DO
   LINE_P(II+MIDX,MIDY,PIXELS+MIDX,MIDY,RED); 
   WAIT(DTPP);
  END;
  TEXTOUT_P("One giant leap for mankind",MIDX-PIXELS+10,MIDY+10,2);
  //TEXTOUT_P("Thats one small step for a man, One giant leap for mankind",0,200,2);
  //DRAWMENU("77");
  FREEZE;
  WAIT;
 END;

 EXPORT Legend()
 BEGIN
  INITS();
  RR:=GetRoche(EARTHR,EARTHDENS,MOONDENS);//FIX
  TEXTOUT_P("XG: "+XG,RIGHTX,220);
  TEXTOUT_P("Earth "+STRING(EARTHRR)+"km",0,20,0,BLUE);
  TEXTOUT_P("Stationary Radius  "+STATI+" km",320/4,40,0,GREEN);
  TEXTOUT_P("Roche Radius       "+RR   +" km",320/4,60,0,RED);
  TEXTOUT_P("Moon  "+STRING(MOONRR)+" km",0,120,0);
  TEXTOUT_P("Lunar Orbit "+STRING(ORADIUSRR)+"km",0,140,0);
  TEXTOUT_P("Lunar Orbit "+DT+" s",0,160,0,RED);
  //TEXTOUT_P("{MAX,MIN",0,240);
  FREEZE;
  WAIT;
 END;

EXPORT LUNAR()
BEGIN
 EM();
END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-29-2023, 10:37 AM (This post was last modified: 06-29-2023 10:46 AM by StephenG1CMZ.)
Post: #3
RE: Astronomy: Lunar
I have now written a Python version of this program, in time for the next anniversary:
https://my.numworks.com/python/steveg1cmz
https://my.numworks.com/python/steveg1cmz/al0_1

(The PPL version is more interactive).

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-25-2023, 09:50 PM (This post was last modified: 09-29-2023 07:37 AM by StephenG1CMZ.)
Post: #4
RE: Astronomy: Lunar
I have now written a different version, now implementing Lunar Eclipse calculations based on Jean Meeus algorithms, separate from my earlier graphical program.

https://my.numworks.com/python/steveg1cmz/alunareclipse
https://my.numworks.com/python/steveg1cm...eclipse0_2
(Edit: now v0.2)
If you are wondering how large Numworks source can be, version 0.2 of my program is at the limit for a Numworks module (the last couple of lines which are not necessary, disappear).

Note:if reading the source online on a Chromebook, long lines may be visually truncated (full source shown if you inspect)
The My Numworks source compiles ok.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
10-03-2023, 08:05 AM (This post was last modified: 10-10-2023 09:07 AM by StephenG1CMZ.)
Post: #5
RE: Astronomy: Lunar
I have now extended that to a version that calculates both solar eclipse and lunar eclipse, in time for the eclipses later this month.
https://my.numworks.com/python/steveg1cmz/aeclipse

Update: V0.1 has a bug in my solar eclipse calculation, use V0.2 instead.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
10-09-2023, 09:32 AM (This post was last modified: 10-10-2023 10:21 AM by StephenG1CMZ.)
Post: #6
RE: Astronomy: Lunar
There is a bug in V0.1 of my solar eclipse calculation.
When working out the time of the eclipse I always call "adjustdays (True" Ie adjusting for a Lunar eclipse.
Workaround - change call to "adjustdays(koff" (koff is 0 or False when calculating Solar, Nonzero or True when lunar).
(The mistake is less than 2 minutes for the October 2023 solar eclipse, and luckily is earlier this time, so you won't be late)

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
10-10-2023, 09:05 AM (This post was last modified: 10-10-2023 10:17 AM by StephenG1CMZ.)
Post: #7
RE: Astronomy: Lunar
I have now uploaded V0.2 of aeclipse, which corrects the time of the solar eclipse calculation. Hope it is useful.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)