Post Reply 
Horizons: Distance to Horizon
04-09-2019, 06:00 PM (This post was last modified: 04-10-2019 08:48 AM by StephenG1CMZ.)
Post: #2
RE: Horizons: Distance to Horizon
Version 0.1 implements simple geometric solutions for spheres, taking no account of refraction.

It includes functions for distance to horizon at a given height, and inverse functions.

It also demonstrates some unexpected cas solve behaviour:
The annotated example Print, if included, often seems OK on the 1st run (returning undef), but on later runs all solves return undef, suggestive of an initialisation issue. Earlier versions of the program sometimes generated a large real instead of undef on the 1st run (and on one occasion a large negative, despite the ">=0").
Update: Changing HT to h in the cas solve seems to fix the 2nd run undef problem.

 LOCAL CRID:="Horizons V0.1 © 2019 StephenG1CMZ";
 //This version has simple geometric horizons
 //No refraction
 LOCAL AU2KM:=149597871;//GOOGLE
 LOCAL RADIUS:=6378140;//m //MUST BE >=0

 //DD   Direct Distance       (eye-horizon)
 //HT   Height above Sphere   (<0=NA)
 //SLen Curved Surface Length (paw-horizon)
 //Distances and heights in same units
 //Return Sphere CAV
  RETURN {SpC,SpA,SpV}; 


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

  RETURN CAS("solve((HT*(2*RADIUS+HT))-DD^2=0,HT,HT≥0)");


 //Get Height for Surface Area (SA in units EG m^2,NOT %)//correction saf as a fraction

 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
  RETURN 100*GetSurfAreaHtFP(HT,RADIUS);

 //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/1000)}));//km
  //PRINT("Verify: HT SD "+GetHeightSD(GetSurfLenHT(HT,RADIUS),RADIUS));
  PRINT("Verify: HT DD "+GetHeightDD(GetDLen     (HT,RADIUS),RADIUS));
  PRINT("Verify: HT SAF"+GetHeightSAF(FP,RADIUS));
  PRINT(" ");

  // a feW examples : most test data elsWhere


  PRINT("Sphere: R "+RADIUS/1000+" km. C:A:V:");
  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("//40.5 AU Voyager PALE BLUE DOT");

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

  PRINT("//as Exoplanet of Proxima Centauri");
  //This last verifies, except solve doesnt
  //2ND RUN ALL solve RETURN undef
  //PRINT(GetHeightSAF(0.50,RADIUS));//sometimes undef

  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 

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-09-2019 06:00 PM

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