1 | /**
|
2 | * @copyright 2013 Sonia Keys
|
3 | * @copyright 2016 commenthol
|
4 | * @license MIT
|
5 | * @module binary
|
6 | */
|
7 | /**
|
8 | * Binary: Chapter 57, Binary Stars
|
9 | */
|
10 | import base from './base';
|
11 | var atan = Math.atan,
|
12 | atan2 = Math.atan2,
|
13 | cos = Math.cos,
|
14 | sqrt = Math.sqrt,
|
15 | tan = Math.tan;
|
16 |
|
17 | /**
|
18 | * computes mean anomaly for the given date.
|
19 | *
|
20 | * @param {Number} year - is a decimal year specifying the date
|
21 | * @param {Number} T - is time of periastron, as a decimal year
|
22 | * @param {Number} P - is period of revolution in mean solar years
|
23 | * @returns {Number} mean anomaly in radians.
|
24 | */
|
25 |
|
26 | export function meanAnomaly(year, T, P) {
|
27 | // (year, T, P float64) float64
|
28 | var n = 2 * Math.PI / P;
|
29 | return base.pmod(n * (year - T), 2 * Math.PI);
|
30 | }
|
31 |
|
32 | /**
|
33 | * Position computes apparent position angle and angular distance of
|
34 | * components of a binary star.
|
35 | *
|
36 | * @param {Number} a - is apparent semimajor axis in arc seconds
|
37 | * @param {Number} e - is eccentricity of the true orbit
|
38 | * @param {Number} i - is inclination relative to the line of sight
|
39 | * @param {Number} Ω - is position angle of the ascending node
|
40 | * @param {Number} ω - is longitude of periastron
|
41 | * @param {Number} E - is eccentric anomaly, computed for example with package kepler
|
42 | * and the mean anomaly as returned by function M in this package.
|
43 | * @returns {Number[]} [θ, ρ]
|
44 | * {Number} θ -is the apparent position angle in radians,
|
45 | * {Number} ρ is the angular distance in arc seconds.
|
46 | */
|
47 | export function position(a, e, i, Ω, ω, E) {
|
48 | // (a, e, i, Ω, ω, E float64) (θ, ρ float64)
|
49 | var r = a * (1 - e * cos(E));
|
50 | var ν = 2 * atan(sqrt((1 + e) / (1 - e)) * tan(E / 2));
|
51 |
|
52 | var _base$sincos = base.sincos(ν + ω),
|
53 | sinνω = _base$sincos[0],
|
54 | cosνω = _base$sincos[1];
|
55 |
|
56 | var cosi = cos(i);
|
57 | var num = sinνω * cosi;
|
58 | var θ = atan2(num, cosνω) + Ω;
|
59 | if (θ < 0) {
|
60 | θ += 2 * Math.PI;
|
61 | }
|
62 | var ρ = r * sqrt(num * num + cosνω * cosνω);
|
63 | return [θ, ρ];
|
64 | }
|
65 |
|
66 | /**
|
67 | * ApparentEccentricity returns apparent eccenticity of a binary star
|
68 | * given true orbital elements.
|
69 | *
|
70 | * @param {Number} e - is eccentricity of the true orbit
|
71 | * @param {Number} i - is inclination relative to the line of sight
|
72 | * @param {Number} ω - is longitude of periastron
|
73 | * @returns {Number} apparent eccenticity of a binary star
|
74 | */
|
75 | export function apparentEccentricity(e, i, ω) {
|
76 | // (e, i, ω float64) float64
|
77 | var cosi = cos(i);
|
78 |
|
79 | var _base$sincos2 = base.sincos(ω),
|
80 | sinω = _base$sincos2[0],
|
81 | cosω = _base$sincos2[1];
|
82 |
|
83 | var A = (1 - e * e * cosω * cosω) * cosi * cosi;
|
84 | var B = e * e * sinω * cosω * cosi;
|
85 | var C = 1 - e * e * sinω * sinω;
|
86 | var d = A - C;
|
87 | var sqrtD = sqrt(d * d + 4 * B * B);
|
88 | return sqrt(2 * sqrtD / (A + C + sqrtD));
|
89 | }
|
90 |
|
91 | export default {
|
92 | meanAnomaly: meanAnomaly,
|
93 | position: position,
|
94 | apparentEccentricity: apparentEccentricity
|
95 | }; |
\ | No newline at end of file |