diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f342bb1f3..1de8480bb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,10 @@ Changelog method that returns their raw ITRF coordinates. `#354 `_ +* Fixed the sign of the velocity vector when two vectors are directly + geometrically subtracted. + `#355 `_ + 1.18 — 2020 March 26 -------------------- diff --git a/skyfield/positionlib.py b/skyfield/positionlib.py index 8a2d66957..963b0a037 100644 --- a/skyfield/positionlib.py +++ b/skyfield/positionlib.py @@ -99,7 +99,7 @@ def __sub__(self, body): if self.velocity is None or body.velocity is None: v = None else: - v = body.velocity.au_per_d - self.velocity.au_per_d + v = self.velocity.au_per_d - body.velocity.au_per_d return ICRF(p, v, self.t) def __getitem__(self, i): diff --git a/skyfield/tests/test_positions.py b/skyfield/tests/test_positions.py index eb4af8cc8..28eebb10d 100644 --- a/skyfield/tests/test_positions.py +++ b/skyfield/tests/test_positions.py @@ -5,6 +5,13 @@ from skyfield.positionlib import ICRF from skyfield.starlib import Star +def test_subtraction(): + p0 = ICRF((10,20,30), (40,50,60)) + p1 = ICRF((1,2,3), (4,5,6)) + p = p0 - p1 + assert tuple(p.position.au) == (9, 18, 27) + assert tuple(p.velocity.au_per_d) == (36, 45, 54) + def test_J2000_ecliptic_coordinates_with_and_without_a_time_array(): p0 = ICRF((1,0,0)) p1 = ICRF((0,1,0))