Skip to content

Commit dcaa67e

Browse files
author
Ivan Dobrianov
committed
saturnmoons, jupitermoons - add Z-coord output
Add the `Z`-coordinate to the computed positions of the moons, so that transits, eclipses, occultations, and shadow transits can be more easily computed. At this moment we do not know of any published "official" Z-values to check against, so we use whatever values would satisfy the test at the moment and hard-code them into the test files.
1 parent 6374bf5 commit dcaa67e

5 files changed

Lines changed: 44 additions & 24 deletions

File tree

src/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const COblJ2000 = 0.917482062
5858
* `dist` is distance in to earth in AU. √(x² + y² + z²)
5959
* Result in seconds of time.
6060
* @param {Number} dist - distance in to earth in AU
61-
* @returns {Number} time for light to travel a given distance in seconds
61+
* @returns {Number} time for light to travel a given distance in days
6262
*/
6363
export function lightTime (dist) {
6464
// Formula given as (33.3) p. 224.

src/jupitermoons.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ export const callisto = 3
2222
const k = [17295, 21819, 27558, 36548]
2323

2424
/**
25-
* XY used for returning coordinates of moons.
25+
* XYZ used for returning coordinates of moons.
2626
* @param {number} x - in units of Jupiter radii
2727
* @param {number} y - in units of Jupiter radii
28+
* @param {number} z - in units of Jupiter radii
2829
*/
29-
function XY (x, y) {
30+
function XYZ (x, y, z) {
3031
this.x = x
3132
this.y = y
33+
this.z = z
3234
}
3335

3436
/**
@@ -37,7 +39,7 @@ function XY (x, y) {
3739
* Returned coordinates are in units of Jupiter radii.
3840
*
3941
* @param {Number} jde - Julian ephemeris day
40-
* @return {Array} x, y - coordinates of the 4 Satellites of jupiter
42+
* @return {Array} x, y, z - coordinates of the 4 Satellites of jupiter
4143
*/
4244
export function positions (jde) {
4345
const d = jde - base.J2000
@@ -83,9 +85,10 @@ export function positions (jde) {
8385
const r3 = 14.9883 - 0.0216 * cG
8486
const r4 = 26.3627 - 0.1939 * cH
8587
const sDE = Math.sin(DE)
88+
const cDE = Math.cos(DE)
8689
const xy = function (u, r) {
8790
const [su, cu] = base.sincos(u)
88-
return new XY(r * su, -r * cu * sDE)
91+
return new XYZ(r * su, -r * cu * sDE, -r * cu * cDE)
8992
}
9093
return [xy(u1 + c1, r1), xy(u2 + c2, r2), xy(u3 + c3, r3), xy(u4 + c4, r4)]
9194
}
@@ -101,7 +104,7 @@ export function positions (jde) {
101104
* @param {Planet} earth - VSOP87 Planet earth
102105
* @param {Planet} jupiter - VSOP87 Planet jupiter
103106
* @param {Array} [pos] - reference to array of positions (same as return value)
104-
* @return {Array} x, y - coordinates of the 4 Satellites of jupiter
107+
* @return {Array} x, y, z - coordinates of the 4 Satellites of jupiter
105108
*/
106109
export function e5 (jde, earth, jupiter, pos) {
107110
pos = pos || new Array(4)
@@ -481,7 +484,7 @@ export function e5 (jde, earth, jupiter, pos) {
481484
x += Math.abs(z) / k[i] * Math.sqrt(1 - d * d)
482485
// perspective effect
483486
const W = Δ / (Δ + z / 2095)
484-
pos[i] = new XY(x * W, y * W)
487+
pos[i] = new XYZ(x * W, y * W, z)
485488
}
486489
return pos
487490
}

src/saturnmoons.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ export const hyperion = 6
2525
export const iapetus = 7
2626

2727
/**
28-
* XY holds coordinates returned from positions().
28+
* XYZ holds coordinates returned from positions().
2929
*/
30-
function XY (x, y) {
30+
function XYZ (x, y, z) {
3131
this.x = x
3232
this.y = y
33+
this.z = z
3334
}
3435

3536
const d = Math.PI / 180
@@ -44,7 +45,7 @@ const d = Math.PI / 180
4445
* @param {number} jde - Julian ephemeris day
4546
* @param {Planet} earth - VSOP87 planet Earth // eslint-disable-line no-unused-vars
4647
* @param {Planet} saturn - VSOP87 planet Saturn // eslint-disable-line no-unused-vars
47-
* @return {XY[]} Array of Moon Positions in `XY`
48+
* @return {XYZ[]} Array of Moon Positions in `XYZ`
4849
* Use `M.mimas ... M.iapetus` to resolve to Moon and its position at `jde`
4950
*/
5051
export function positions (jde, earth, saturn) {
@@ -138,7 +139,7 @@ export function positions (jde, earth, saturn) {
138139
const d = X[j] / s4[j].r
139140
X[j] += Math.abs(Z[j]) / k[j] * Math.sqrt(1 - d * d)
140141
const W = Δ / (Δ + Z[j] / 2475)
141-
pos[j - 1] = new XY(X[j] * W, Y[j] * W)
142+
pos[j - 1] = new XYZ(X[j] * W, Y[j] * W, Z[j])
142143
}
143144
return pos
144145
}

test/jupitermoons.test.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ describe('#jupitermoons', function () {
1818
assert.strictEqual(float(pos[2].y).toFixed(2), +0.65)
1919
assert.strictEqual(float(pos[3].y).toFixed(2), +1.10)
2020

21+
assert.strictEqual(float(pos[0].z).toFixed(2), -4.82)
22+
assert.strictEqual(float(pos[1].z).toFixed(2), -5.74)
23+
assert.strictEqual(float(pos[2].z).toFixed(2), -14.94)
24+
assert.strictEqual(float(pos[3].z).toFixed(2), -25.22)
25+
2126
// Output:
2227
// X -3.44 +7.44 +1.24 +7.08
2328
// Y +0.21 +0.25 +0.65 +1.10
@@ -38,11 +43,13 @@ describe('#jupitermoons', function () {
3843

3944
assert.deepStrictEqual(xyToFixed(pos3[2]), {
4045
x: -0.0016,
41-
y: -0.8424
46+
y: -0.8424,
47+
z: -14.9444
4248
})
4349
assert.deepStrictEqual(xyToFixed(pos4[3]), {
4450
x: +0.0555,
45-
y: +1.4811
51+
y: +1.4811,
52+
z: +26.2743
4653
})
4754

4855
// Output:
@@ -67,6 +74,11 @@ describe('#jupitermoons', function () {
6774
assert.strictEqual(float(pos[2].y).toFixed(4), +0.5900)
6875
assert.strictEqual(float(pos[3].y).toFixed(4), +1.0290)
6976

77+
assert.strictEqual(float(pos[0].z).toFixed(4), -4.8189)
78+
assert.strictEqual(float(pos[1].z).toFixed(4), -5.7472)
79+
assert.strictEqual(float(pos[2].z).toFixed(4), -14.9406)
80+
assert.strictEqual(float(pos[3].z).toFixed(4), -25.2244)
81+
7082
// Output:
7183
// X -3.4503 +7.4418 +1.2010 +7.0720
7284
// Y +0.2137 +0.2752 +0.5900 +1.0290
@@ -90,11 +102,13 @@ describe('#jupitermoons', function () {
90102

91103
assert.deepStrictEqual(xyToFixed(pos3[2]), {
92104
x: +0.0032,
93-
y: -0.8042
105+
y: -0.8042,
106+
z: -14.9433
94107
})
95108
assert.deepStrictEqual(xyToFixed(pos4[3]), {
96109
x: +0.0002,
97-
y: +1.3990
110+
y: +1.3990,
111+
z: +26.2732
98112
})
99113

100114
// Output:
@@ -108,6 +122,7 @@ function xyToFixed (xy, n) {
108122
n = n || 4
109123
return {
110124
x: float(xy.x).toFixed(n),
111-
y: float(xy.y).toFixed(n)
125+
y: float(xy.y).toFixed(n),
126+
z: float(xy.z).toFixed(n)
112127
}
113128
}

test/saturnmoons.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('#saturnmoons', function () {
99
function comp (res, exp) {
1010
assert.strictEqual(float(res.x).toFixed(3), exp.x)
1111
assert.strictEqual(float(res.y).toFixed(3), exp.y)
12+
assert.strictEqual(float(res.z).toFixed(3), exp.z)
1213
}
1314

1415
describe('positions()', function () {
@@ -17,14 +18,14 @@ describe('#saturnmoons', function () {
1718
const saturn = new planetposition.Planet(data.vsop87Bsaturn)
1819
const pos = saturnmoons.positions(2451439.50074, earth, saturn)
1920
const exp = [
20-
{ x: +3.102, y: -0.204 },
21-
{ x: +3.823, y: +0.318 },
22-
{ x: +4.027, y: -1.061 },
23-
{ x: -5.365, y: -1.148 },
24-
{ x: -0.972, y: -3.136 },
25-
{ x: +14.568, y: +4.738 },
26-
{ x: -18.001, y: -5.328 },
27-
{ x: -48.760, y: +4.137 }
21+
{ x: +3.102, y: -0.204, z: +0.295 },
22+
{ x: +3.823, y: +0.318, z: -0.833 },
23+
{ x: +4.027, y: -1.061, z: +2.545 },
24+
{ x: -5.365, y: -1.148, z: +3.004 },
25+
{ x: -0.972, y: -3.136, z: +8.080 },
26+
{ x: +14.568, y: +4.738, z: -12.755 },
27+
{ x: -18.001, y: -5.328, z: +15.121 },
28+
{ x: -48.760, y: +4.137, z: +32.738 }
2829
]
2930

3031
pos.forEach(function (p, i) {

0 commit comments

Comments
 (0)