Skip to content

Commit c585a35

Browse files
author
Jim Carr
committed
Calculate -> Binary star orbit data
1 parent 3ed450f commit c585a35

File tree

7 files changed

+154
-1
lines changed

7 files changed

+154
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you're interested in this topic, please buy the book! It provides far more de
5656

5757
### Binary Stars
5858

59-
- [ ] Calculate -> Binary star orbit data
59+
- [x] Calculate -> Binary star orbit data
6060

6161
### The Moon
6262

src/Main.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public static void main(String[] args) {
55
testSun();
66
testPlanet();
77
testComet();
8+
testBinary();
89
}
910

1011
public static void testDateTime() {
@@ -66,4 +67,10 @@ public static void testComet() {
6667
testComet.testPositionOfEllipticalComet();
6768
testComet.testPositionOfParabolicComet();
6869
}
70+
71+
public static void testBinary() {
72+
TestBinary testBinary = new TestBinary();
73+
74+
testBinary.testBinaryStarOrbit();
75+
}
6976
}

src/TestBinary.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import astro.practical.lib.PABinary;
2+
import astro.practical.models.BinaryStarOrbit;
3+
import astro.practical.test.TestLib;
4+
5+
public class TestBinary {
6+
PABinary paBinary;
7+
TestLib testLib;
8+
9+
public TestBinary() {
10+
paBinary = new PABinary();
11+
testLib = new TestLib();
12+
}
13+
14+
public void testBinaryStarOrbit() {
15+
BinaryStarOrbit binaryStarOrbit = paBinary.binaryStarOrbit(1, 1, 1980, "eta-Cor");
16+
17+
testLib.setTestName("Binary Star Orbit")
18+
.Assert(318.5, binaryStarOrbit.positionAngleDeg)
19+
.Assert(0.41, binaryStarOrbit.separationArcsec);
20+
}
21+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package astro.practical.data;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import astro.practical.models.data.BinaryData;
6+
7+
public class BinaryInfo {
8+
List<BinaryData> binaryData;
9+
10+
public BinaryInfo() {
11+
binaryData = new ArrayList<>() {
12+
{
13+
add(new BinaryData("eta-Cor", 41.623, 1934.008, 219.907, 0.2763, 0.907, 59.025, 23.717));
14+
add(new BinaryData("gamma-Vir", 171.37, 1836.433, 252.88, 0.8808, 3.746, 146.05, 31.78));
15+
add(new BinaryData("eta-Cas", 480.0, 1889.6, 268.59, 0.497, 11.9939, 34.76, 278.42));
16+
add(new BinaryData("zeta-Ori", 1508.6, 2070.6, 47.3, 0.07, 2.728, 72.0, 155.5));
17+
add(new BinaryData("alpha-CMa", 50.09, 1894.13, 147.27, 0.5923, 7.5, 136.53, 44.57));
18+
add(new BinaryData("delta-Gem", 1200.0, 1437.0, 57.19, 0.11, 6.9753, 63.28, 18.38));
19+
add(new BinaryData("alpha-Gem", 420.07, 1965.3, 261.43, 0.33, 6.295, 115.94, 40.47));
20+
add(new BinaryData("aplah-CMi", 40.65, 1927.6, 269.8, 0.4, 4.548, 35.7, 284.3));
21+
add(new BinaryData("alpha-Cen", 79.92, 1955.56, 231.56, 0.516, 17.583, 79.24, 204.868));
22+
add(new BinaryData("alpha Sco", 900.0, 1889.0, 0.0, 0.0, 3.21, 86.3, 273.0));
23+
}
24+
};
25+
}
26+
27+
public BinaryData getBinaryInfo(String name) {
28+
BinaryData binaryInfo = binaryData.stream()
29+
.filter(p -> p.Name == name)
30+
.findFirst()
31+
.orElse(new BinaryData("NotFound", 0, 0, 0, 0, 0, 0, 0));
32+
33+
return binaryInfo;
34+
}
35+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package astro.practical.lib;
2+
3+
import astro.practical.data.BinaryInfo;
4+
import astro.practical.models.BinaryStarOrbit;
5+
import astro.practical.models.data.BinaryData;
6+
7+
public class PABinary {
8+
/**
9+
* Calculate orbital data for binary star.
10+
*/
11+
public BinaryStarOrbit binaryStarOrbit(double greenwichDateDay, int greenwichDateMonth, int greenwichDateYear,
12+
String binaryName) {
13+
BinaryInfo binaryInfo = new BinaryInfo();
14+
15+
BinaryData binaryData = binaryInfo.getBinaryInfo(binaryName);
16+
17+
double yYears = greenwichDateYear
18+
+ (PAMacros.civilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear)
19+
- PAMacros.civilDateToJulianDate(0, 1, greenwichDateYear)) / 365.242191
20+
- binaryData.EpochPeri;
21+
double mDeg = 360 * yYears / binaryData.Period;
22+
double mRad = Math.toRadians(mDeg - 360 * Math.floor(mDeg / 360));
23+
double eccentricity = binaryData.Ecc;
24+
double trueAnomalyRad = PAMacros.trueAnomaly(mRad, eccentricity);
25+
double rArcsec = (1 - eccentricity * Math.cos(PAMacros.eccentricAnomaly(mRad, eccentricity))) * binaryData.Axis;
26+
double taPeriRad = trueAnomalyRad + Math.toRadians(binaryData.LongPeri);
27+
28+
double y = Math.sin(taPeriRad) * Math.cos(Math.toRadians(binaryData.Incl));
29+
double x = Math.cos(taPeriRad);
30+
double aDeg = PAMacros.wToDegrees(Math.atan2(y, x));
31+
double thetaDeg1 = aDeg + binaryData.PANode;
32+
double thetaDeg2 = thetaDeg1 - 360 * Math.floor(thetaDeg1 / 360);
33+
double rhoArcsec = rArcsec * Math.cos(taPeriRad) / Math.cos(Math.toRadians(thetaDeg2 - binaryData.PANode));
34+
35+
double positionAngleDeg = PAUtil.round(thetaDeg2, 1);
36+
double separationArcsec = PAUtil.round(rhoArcsec, 2);
37+
38+
return new BinaryStarOrbit(positionAngleDeg, separationArcsec);
39+
}
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package astro.practical.models;
2+
3+
public class BinaryStarOrbit {
4+
public double positionAngleDeg;
5+
public double separationArcsec;
6+
7+
public BinaryStarOrbit(double positionAngleDeg, double separationArcsec) {
8+
this.positionAngleDeg = positionAngleDeg;
9+
this.separationArcsec = separationArcsec;
10+
}
11+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package astro.practical.models.data;
2+
3+
public class BinaryData {
4+
/** Name of binary system. */
5+
public String Name;
6+
7+
/** Period of the orbit. */
8+
public double Period;
9+
10+
/** Epoch of the perihelion. */
11+
public double EpochPeri;
12+
13+
/** Longitude of the perihelion. */
14+
public double LongPeri;
15+
16+
/** Eccentricity of the orbit. */
17+
public double Ecc;
18+
19+
/** Semi-major axis of the orbit. */
20+
public double Axis;
21+
22+
/** Orbital inclination. */
23+
public double Incl;
24+
25+
/** Position angle of the ascending node. */
26+
public double PANode;
27+
28+
public BinaryData(String name, double period, double epochPeri, double longPeri, double ecc, double axis,
29+
double incl, double paNode) {
30+
this.Name = name;
31+
this.Period = period;
32+
this.EpochPeri = epochPeri;
33+
this.LongPeri = longPeri;
34+
this.Ecc = ecc;
35+
this.Axis = axis;
36+
this.Incl = incl;
37+
this.PANode = paNode;
38+
}
39+
}

0 commit comments

Comments
 (0)