Skip to main content

roche/
vel_transform.rs

1use crate::errors::RocheError;
2
3
4
5pub fn vel_transform(q: f64, transform_type: i32, x: f64, y: f64, vx: f64, vy: f64) -> Result<(f64, f64), RocheError> {
6
7    let mu: f64 = q/(1.0+q);
8    let rad: f64 = (x*x + y*y).sqrt();
9    let vkep: f64 = 1.0/((1.0 + q)*rad).sqrt();
10
11    match transform_type {
12        1 => Ok((vx - y, vy + x - mu)),
13        2 => Ok((-vkep*y/rad, vkep*x/(rad-mu))),
14        3 => Ok((vx, vy)),
15        _ => Err(RocheError::ParameterError(format!("{} is not a valid transform_type.", transform_type))),
16    }
17}