Skip to content

Commit a344487

Browse files
committed
Small amount of refactoring
1 parent c7e17c4 commit a344487

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

src/main/uk/me/g4dpz/satellite/AbstractSatellite.java

+21-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
predict4java: An SDP4 / SGP4 library for satellite orbit predictions
33
44
Copyright (C) 2004-2010 David A. B. Johnson, G4DPZ.
@@ -66,10 +66,10 @@ public abstract class AbstractSatellite implements Satellite, Serializable {
6666

6767
protected static final double PERIGEE_156_KM = 156.0;
6868

69-
/* WGS 84 Earth radius km */
69+
/** WGS 84 Earth radius km. */
7070
protected static final double EARTH_RADIUS = 6.378137E3;
7171

72-
/* Solar radius - km (IAU 76) */
72+
/** Solar radius - km (IAU 76). */
7373
protected static final double SOLAR_RADIUS = 6.96000E5;
7474

7575
private double s4;
@@ -84,7 +84,7 @@ public abstract class AbstractSatellite implements Satellite, Serializable {
8484
private final Vector4 position = new Vector4();
8585
/** Velocity vector of the satellite. Used to store the velocity for later calculations. */
8686
private final Vector4 velocity = new Vector4();
87-
/** Date/time at which the position and velocity were calculated */
87+
/** Date/time at which the position and velocity were calculated. */
8888
private double julUTC;
8989
/** Satellite position. Used to store the SatPos for later calculations. */
9090
private SatPos satPos;
@@ -381,11 +381,9 @@ public synchronized SatPos getPosition(final GroundStationPosition gsPos, final
381381

382382
final Vector4 squintVector = new Vector4();
383383

384-
//
385384
// /** All angles in rads. Distance in km. Velocity in km/S **/
386385
// /* Calculate satellite Azi, Ele, Range and Range-rate */
387386
calculateObs(julUTC, position, velocity, gsPos, squintVector);
388-
//
389387
/* Calculate satellite Lat North, Lon East and Alt. */
390388

391389
calculateLatLonAlt(julUTC, position, satPos);
@@ -432,11 +430,11 @@ private static void calculateUserPosVel(final double time,
432430
final double c = AbstractSatellite.invert(Math.sqrt(1.0 + FLATTENING_FACTOR * (FLATTENING_FACTOR - 2)
433431
* AbstractSatellite.sqr(Math.sin(DEG2RAD * gsPos.getLatitude()))));
434432
final double sq = AbstractSatellite.sqr(1.0 - FLATTENING_FACTOR) * c;
435-
final double achcp = (EARTH_RADIUS_KM * c + (gsPos.getHeightAMSL() / 1000.0))
433+
final double achcp = (EARTH_RADIUS_KM * c + gsPos.getHeightAMSL() / 1000.0)
436434
* Math.cos(DEG2RAD * gsPos.getLatitude());
437435
obsPos.setXYZ(achcp * Math.cos(gsPos.getTheta()),
438436
achcp * Math.sin(gsPos.getTheta()),
439-
(EARTH_RADIUS_KM * sq + (gsPos.getHeightAMSL() / 1000.0))
437+
(EARTH_RADIUS_KM * sq + gsPos.getHeightAMSL() / 1000.0)
440438
* Math.sin(DEG2RAD * gsPos.getLatitude()));
441439
obsVel.setXYZ(-MFACTOR * obsPos.getY(),
442440
MFACTOR * obsPos.getX(),
@@ -522,13 +520,11 @@ private void calculateObs(final double julianUTC,
522520

523521
double elevation = (satPos.getElevation() / Satellite.TWO_PI) * 360.0;
524522

525-
if (elevation > 0.0) {
526-
if (elevation > 90) {
527-
elevation = 180 - elevation;
528-
}
523+
if (elevation > 0.0 && elevation > 90) {
524+
elevation = 180 - elevation;
529525
}
530526

531-
satPos.setAboveHorizon((elevation - gsPos.getHorizonElevations()[sector]) > EPSILON);
527+
satPos.setAboveHorizon(elevation - gsPos.getHorizonElevations()[sector] > EPSILON);
532528
}
533529

534530
/**
@@ -555,8 +551,8 @@ public boolean willBeSeen(final GroundStationPosition qth) {
555551
* (2.0 / 3.0));
556552
final double apogee = sma * (1.0 + tle.getEccn()) - EARTH_RADIUS_KM;
557553

558-
return (Math.acos(EARTH_RADIUS_KM
559-
/ (apogee + EARTH_RADIUS_KM)) + (lin * DEG2RAD)) > Math
554+
return Math.acos(EARTH_RADIUS_KM
555+
/ (apogee + EARTH_RADIUS_KM)) + lin * DEG2RAD > Math
560556
.abs(qth.getLatitude() * DEG2RAD);
561557
}
562558

@@ -605,19 +601,19 @@ protected void setPerigee(final double perigee) {
605601

606602
static class Vector4 extends Object implements Serializable {
607603

608-
/** serialized id. */
604+
/** Serialized id. */
609605
private static final long serialVersionUID = -8804649332186066551L;
610606

611-
/** the w part of the vector. ` */
607+
/** The w part of the vector. ` */
612608
private double w;
613-
/** the x part of the vector. ` */
609+
/** The x part of the vector. ` */
614610
private double x;
615-
/** the y part of the vector. ` */
611+
/** The y part of the vector. ` */
616612
private double y;
617-
/** the z part of the vector. ` */
613+
/** The z part of the vector. ` */
618614
private double z;
619615

620-
/** default constructor. */
616+
/** Default constructor. */
621617
Vector4() {
622618
this.w = 0.0;
623619
this.x = 0.0;
@@ -724,7 +720,7 @@ public Vector4 subtract(final Vector4 vector) {
724720
this.z - vector.z);
725721
}
726722

727-
public static final Vector4 scalarMultiply(final Vector4 vector, final double multiplier) {
723+
public static Vector4 scalarMultiply(final Vector4 vector, final double multiplier) {
728724

729725
return new Vector4(
730726
vector.w * Math.abs(multiplier),
@@ -736,7 +732,7 @@ public static final Vector4 scalarMultiply(final Vector4 vector, final double mu
736732
/**
737733
* Calculates the angle between vectors v1 and v2.
738734
*/
739-
public static final double angle(final Vector4 v1, final Vector4 v2) {
735+
public static double angle(final Vector4 v1, final Vector4 v2) {
740736
AbstractSatellite.magnitude(v1);
741737
AbstractSatellite.magnitude(v2);
742738
return Math.acos(AbstractSatellite.dot(v1, v2) / (v1.w * v2.w));
@@ -745,7 +741,7 @@ public static final double angle(final Vector4 v1, final Vector4 v2) {
745741
/**
746742
* Subtracts vector v2 from v1.
747743
*/
748-
public static final Vector4 subtract(final Vector4 v1, final Vector4 v2) {
744+
public static Vector4 subtract(final Vector4 v1, final Vector4 v2) {
749745

750746
final Vector4 v3 = new Vector4();
751747
v3.x = v1.x - v2.x;
@@ -886,12 +882,7 @@ private boolean isEclipsed() {
886882
final double delta = Vector4.angle(sunVector, earth);
887883
eclipseDepth = sdEarth - sdSun - delta;
888884

889-
if (sdEarth < sdSun) {
890-
return false;
891-
}
892-
else {
893-
return eclipseDepth >= 0;
894-
}
885+
return sdEarth >= sdSun && eclipseDepth >= 0;
895886
}
896887

897888
private Vector4 calculateSunVector() {

0 commit comments

Comments
 (0)