1 stable release

1.0.0 Nov 12, 2021

#40 in #geography

Custom license

16KB
319 lines

Multilateration

This is a multilateration library implemented in Rust, which is loosly based on Java trilateration library.

License

MIT


lib.rs:

githubcrates-iodocs-rs


This is a multilateration library implemented in Rust, which is loosly based on Java trilateration library.


Details

  • It exposes one function that uses a vector of Measurement struct as an input. Output will be the tuple struct called Point which contains the output coordinates as a vector in the first tuple slot

    use multilateration::{multilaterate, Measurement, Point};
    
    fn main() -> Result<()> {
      let measurements = vec![
        Measurement::new(Point(vec![1.0, 1.0, 1.0]), 1.0),
        Measurement::new(Point(vec![3.0, 1.0, 1.0]), 1.0),
        Measurement::new(Point(vec![2.0, 2.0, 1.0]), 1.0),
      ];
    
      let coordinates = multilaterate(measurements).unwrap().0;
      println!("Coordinates are: {:?}", coordinates);
      Ok(())
    }
    
    Coordinates are: [2.0, 1.0000157132198315, 0.9943941804736127]
    

Error conditions

  • Points have different dimensions
  use multilateration::{multilaterate, Measurement, Point};

  fn main() -> Result<()> {
    let measurements = vec![
      Measurement::new(Point(vec![1.0, 1.0]), 1.0),
      Measurement::new(Point(vec![3.0, 1.0, 1.0]), 1.0),
      Measurement::new(Point(vec![2.0, 2.0, 1.0]), 1.0),
    ];

    let result = multilaterate(measurements);
    println!("Result is: {:?}", result);
    Ok(())
  }
Result is: Err(All points must have the same dimensions)
  • Points have no dimensions
  use multilateration::{multilaterate, Measurement, Point};

  fn main() -> Result<()> {
    let measurements = vec![
      Measurement::new(Point(vec![]), 1.0),
      Measurement::new(Point(vec![]), 1.0),
      Measurement::new(Point(vec![]), 1.0),
    ];

    let result = multilaterate(measurements);
    println!("Result is: {:?}", result);
    Ok(())
  }
Result is: Err(Points must contain at least one dimension)

Dependencies

~1MB
~23K SLoC