Hi Community,
I’m trying to find the Visibility of a Star - Canopus using Eclipse Detector.
At certain point while running the code I’m getting NullPointerException. below I share you the piece of code to try and let me know why the error is generated. from the OneAxisEllipsoid class it says that it will return null if → intersection point at altitude zero or null if the line does not intersect the surface. But the Intersection point is computed when the event is detected with eclipse detector.( here it just doesnot makes sense to me). maybe if I’m wrong. Also if you have any other solution to compute the Intersection point and visibility would be much appreciable.
I have cut short the code to focus on only one part. I hope this helps. please let me know if you need more details.
Waiting for your response.
{ // main function
Frame eme = FramesFactory.getEME2000();
OneAxisEllipsoid tangentPLow = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
Constants.WGS84_EARTH_FLATTENING,
FramesFactory.getITRF(IERSConventions.IERS_2010, true));
TLE tle = new TLE("1 39159U 13021A 21117.10971189 -.00000003 00000-0 16958-4 0 9999",
"2 39159 98.4135 167.6604 0003439 213.4832 146.6130 14.22999585414117",TimeScalesFactory.getUTC());
TLEPropagator probav = TLEPropagator.selectExtrapolator(tle);
// Dates for visibility check
AbsoluteDate startDate = new AbsoluteDate(2021, 4, 27, 0, 0, 00.000, TimeScalesFactory.getUTC());
AbsoluteDate endDate = new AbsoluteDate(2021, 4, 28, 0, 0, 00.000, TimeScalesFactory.getUTC());
Stars fStars = new Stars();
PVCoordinatesProvider Capella = fStars.Star("Capella");
// Eclipse detector
EclipseDetector capellalow = new EclipseDetector(Capella, 0, tangentPLow)
.withHandler((SpacecraftState s, EclipseDetector detector, boolean increasing) -> {
if (increasing) {
Vector3D PlanAppPos = Capella.getPVCoordinates(s.getDate(), eme).getPosition();
Vector3D sd = s.getPVCoordinates(eme).getPosition();
GeodeticPoint gp = tangentPLow.transform(sd, eme, s.getDate());
double slt = FastMath.toDegrees(gp.getLatitude());
double sln = FastMath.toDegrees(gp.getLongitude());
Line los = new Line(sd,PlanAppPos, 1e-10);
GeodeticPoint gp1 = tangentPLow.getIntersectionPoint(los, sd, eme, s.getDate());
double tlt = FastMath.toDegrees(gp1.getLatitude()); // The Error Occurs here as the gp1 is null
double tln = FastMath.toDegrees(gp1.getLongitude());
double alt = tanPoints[0];
System.out.format(Locale.US,
"Visibility of Capella Begins at :%s, SLat: %3.3f, SLon: %3.3f, TPLat: %3.3f, TPLon: %3.3f, TAlt: %3.2f %n",
s.getDate(),slt,sln,tlt,tln,alt);
}
return Action.CONTINUE;
});
System.out.print("\n");
probav.addEventDetector(capellalow);
probav.propagate(startDate, endDate);
}
static class Stars{
public PVCoordinatesProvider Star(String star){
// Star Cartesian coordinates taken from https://www.astronexus.com/hyg HYG 3.0 Database.
PVCoordinatesProvider st;
PVCoordinates pv;
Frame frame = FramesFactory.getEME2000();
if(star == "Capella" | star =="capella"){
pv = new PVCoordinates(new Vector3D(1.712633*Constants.IAU_2012_ASTRONOMICAL_UNIT, 8.954439*Constants.IAU_2012_ASTRONOMICAL_UNIT,
9.440007*Constants.IAU_2012_ASTRONOMICAL_UNIT),new Vector3D(1.92E-06, 3.559E-05, -2.54E-06));
AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
st = new CartesianOrbit(pv, frame, date, Constants.WGS84_EARTH_MU);
}else{
st = null;
System.out.println("Please Enter Stars from the catalogue- Polaris, Capella, Canopus, Procyon, Altair. If"
+" you need to add a new star in the statements above use the Hyg DataBase for Star Position Data");
}
return st;
}
}
Here is the error produced:
Exception in thread "main" java.lang.NullPointerException
at org.orekit.tutorials.propagation.PlanetAngPos.lambda$16(PlanetAngPos.java:499)