Post Reply 
Horizons: Distance to Horizon
04-11-2019, 09:10 PM (This post was last modified: 04-15-2019 09:25 PM by StephenG1CMZ.)
Post: #3
RE: Horizons: Distance to Horizon
Version 0.2:
Improves cas solve implementation (using h instead of HT)
Improves handling of extreme values
Implements inverse surface area calculations (although these may be approximate and need more checking).
Note: The I at the start of the code is a cut-and-paste error - please delete it.

// If you have previously downloaded this, please delete this I:
// I 
 LOCAL CRID:="Horizons V0.2 © 2019 StephenG1CMZ";
 //This version has simple geometric horizons
 //No refraction
 LOCAL HT;//FOR SOLVE //Global h used
 LOCAL AU2KM:=149597871;//GOOGLE
 LOCAL RADIUS:=6378140;//m //MUST BE >=0
 LOCAL NA:=0;  // NA OR 0 => ONE OF:
  //INPUT=0.5 (INFINITE HEIGHT LIMITING CASE, use UpperLimits for values)

 //DD   Direct Distance       (eye-horizon)
 //HT   Height above Sphere   (<0=NA)
 //SLen Curved Surface Length (paw-horizon)
 //Distances and heights in same units

 EXPORT GetDLen(HT,RADIUS) //Direct distance
 //RETURN D is the straight geometrical eye-hZ dist
 //TIMING 58us


 //Get Height for Surface Area (SAF Fraction of sphere visible, 0..0.5)
   RETURN HT; //MAX(HT,0); 
 //Get Height for Surface Area (SA in units^2)

  IF SurfLen<0 OR SurfLen≥π*RADIUS THEN

 EXPORT GetSurfLenDD(DD,RADIUS) //Surface Length from DD
 //D is the straight geometrical eye-hor dist
 //TIMING 55us



 //Surfacevisible at Height
 //FP Fraction
 //PC Percent
 //SA Surface Area (same units as radius)

 //Derived From:
 //Height and Radius in same units. Ht is above surface 
 //Return.Proportion Surface Visible at Ht (0-0.5,HT≥0)
 //For example:
 //Radius of Earth = 6378 km
 //Distance of Apollo 17 from Earth's surface at 1972-12-07T10:39Z = 29000 km
 //Visible percentage of Earth's surface in 1972 "Blue Marble" photograph = 40.99% (41%)
   RETURN NA;//0 OR 1


 //Hint: See EX 

  PRINT("At Height "+HT+" Radius "+RADIUS);
  PRINT("Geometric visible horizon: "+ROUND(DX,PLACES));
  PRINT("Surface horizon: "+ROUND(GetSurfLenDD(DX,RADIUS),PLACES));
  PRINT("Surface Area: "+ROUND(FP*GetSphereSA(RADIUS/1000),PLACES));

 //Work an example
 //Exhibits program functionality
 //Hint: See Report
  PRINT("Direct Length "+DX);
  PRINT("SurfaceLenDD "+GetSurfLenDD(DX,RADIUS));
  PRINT("SurfaceLenHT "+GetSurfLenHT(HT,RADIUS));
  PRINT("SurfArea "+STRING({100*FP+"%",FP*GetSphereSA(RADIUS)}));
  //PRINT("Verify: HT SD "+GetHeightSL(GetSurfLenHT(HT,RADIUS),RADIUS));
  PRINT("Verify: HT DD "+GetHeightDD(GetDLen     (HT,RADIUS),RADIUS));
  PRINT("Verify: HT SAF"+GetHeightSAF(FP,RADIUS));
  //PRINT("Verify: HT SA "+GetHeightSA(SA,RADIUS));
  PRINT(" ");

 //Upper Limits = Half Sphere = Infinite Height
 //Appply to SurfLen,SurfArea. Not DD and HT

  // a feW examples : most test data elsWhere


  PRINT("Sphere: R "+RADIUS/1000+" km. Circ & Area:");
  PRINT("Upper limits: SurfLen & SurfArea");
  PRINT(STRING(UpperLimits(RADIUS))+" m,m^2");//m
  PRINT(" ");

  //HT≤0 RETURNS 0 

  PRINT("//MAN at 2m (D 5.1km)");

  PRINT("//ISS at 408 km (around 2373 km)");

  PRINT("//Eg APOLLO at 29000 km");
  PRINT("Note the differences in these calculations...");
  PRINT("My inverse surface area may be inaccurate");
  PRINT(" ");

  PRINT("//40.5 AU Voyager PALE BLUE DOT");

  //PRINT("//145 AU Voyager 2019");

  PRINT("//Viewed as Exoplanet from Proxima Centauri");
  //This last verifies, except solve doesnt
  //Test Traps 
  PRINT(GetHeightSAF(0.50,RADIUS));//undef unless trapped

  LOCAL HT:=2;

  //PRINT("TEVAL DStraight "+TEVAL(DX:=HZDistanceD(HT,RADIUS)));// 58 CALC D 
  //PRINT("TEVAL SurfaceD "+TEVAL(HZDistanceSD(DX,RADIUS)));    // 54 S ADD TO ABOVE 
  //PRINT("TEVAL SurfaceH "+TEVAL(HZDistanceSH(HT,RADIUS)));    //109 VS S 
Note: Some of my examples are incorrect - I mangled km and m. In particular, the AU2KM AU2M conversion.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Horizons: Distance to Horizon - StephenG1CMZ - 04-11-2019 09:10 PM

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