Skip to content

Commit

Permalink
Fix velocity calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee authored and matzipan committed Nov 11, 2023
1 parent 2c333a7 commit 68c8d4c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions crates/lox_core/src/ephemeris/daf_spk/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,19 @@ impl Spk {
if degree_of_polynomial > 2 {
derivative.push(4f64 * polynomial[1]);
for i in 3..degree_of_polynomial {
let x = 2f64 * polynomial[1] * derivative[i - 1]
- derivative[i - 2] * polynomial[i - 1]
let x = 2f64 * polynomial[1] * derivative[i - 1] - derivative[i - 2]
+ polynomial[i - 1]
+ polynomial[i - 1];
let x = 2f64 * x;
let x = x / array.intlen as f64;

derivative.push(x);
}
}

let derivative: Vec<f64> = derivative
.iter()
.map(|d| 2.0 * d / array.intlen as f64)
.collect();

#[allow(clippy::needless_range_loop)]
for i in 0..degree_of_polynomial {
x += sign * record[i].x * derivative[i];
Expand Down Expand Up @@ -230,7 +233,11 @@ mod test {
let spk = parse_daf_spk(&FILE_CONTENTS).expect("Unable to parse DAF/SPK");

assert_eq!(
Ok((-16347507.654236255, -10396015.881953504, -3828362.817319523)), //@TODO validate
Ok((
-46.723420416476635,
-28.050723083678367,
-10.055174230490163,
)),
spk.velocity(-14200747200.0 as Epoch, 0, 1)
);
}
Expand All @@ -242,7 +249,11 @@ mod test {
assert_eq!(
Ok((
(-32703259.291699532, 31370540.51993667, 20159681.594182793),
(-16347507.654236255, -10396015.881953504, -3828362.817319523),
(
-46.723420416476635,
-28.050723083678367,
-10.055174230490163,
),
)),
spk.state(-14200747200.0 as Epoch, 0, 1)
);
Expand Down

0 comments on commit 68c8d4c

Please sign in to comment.