Struct oldnav_lib::navdata::coord::SphericalCoordinate [] [src]

pub struct SphericalCoordinate {
    pub r: f64,
    pub theta: f64,
    pub phi: f64,
}

Represents a coordinate in the spherical coordinate system.

The normal range for the variables is as follows:

name range
r 0 -> infinity
theta (0 -> 2PI)
phi (0 -> PI)

See: http://mathworld.wolfram.com/SphericalCoordinates.html for more details.

The design decision to combine Spherical with Geographical coordinates was made beceause many of the algorithms available, and literature deal with the spherical coordinate system, so it is easier to implement it with that. It is fairly low cost to go between the two representations, and this only really occurs twice, once in, and once out to display. Most of the heavy calculations will be while the coordinate is treated as a spherical coordinate.

Examples

It is very common to instantiate from a geographical point and then access those values later in the form of latitude and longitude:


let pos = SphericalCoordinate::from_geographic(324.567, 82.123, 23.452);
println!("{},{}", pos.lat(), pos.lon());

If you are manually setting the r, theta or phi values you need to ensure that your values fall within the range specified, or that you use the rectify_bounds() method to transform the coordinate into the specified range after you set the value

let accuracy = 0.0001;

let mut pos = SphericalCoordinate::new(30.0, 0.0, PI);
println!("{:?}", pos);


// negative theta puts coordinate outside bounds of (0 -> 2PI)
pos.theta = -1.0 * PI;
pos.rectify_bounds_inplace();
println!("{:?}", pos);

// test to see that coordinate is now properly within the bounds
assert!((pos.theta-PI).abs() < accuracy);
assert!((pos.phi-PI).abs() < accuracy);

Fields

r: f64

Radius component

theta: f64

Theta component

phi: f64

Phi component

Methods

impl SphericalCoordinate
[src]

fn new(r: f64, theta: f64, phi: f64) -> SphericalCoordinate

Constructor for SphericalCoordinate

Examples


let pos = SphericalCoordinate::new(10.0, PI, 0.0);
println!("theta: {:?}", pos.theta);

When the values exceed the normal bountaries for the spherical coordinate system, they are wrapped back around to the equivalent angle (rectified) to ensure they stay within the expected values for other calculations:


let accuracy = 0.0001;
let pos = SphericalCoordinate::new(10.0, 3.0*PI, 0.0);

// test to see if values are assigned accurately
assert!((pos.r-10.0).abs() < accuracy);
// theta has been rectified to be within boundary (0 -> 2PI)
assert!((pos.theta-PI).abs() < accuracy);
assert!((pos.phi-0.0).abs() < accuracy);

fn from_geographic(alt: f64, lat: f64, lon: f64) -> SphericalCoordinate

Create a new SphericalCoordinate from geographic coordinate.

alt: metres above the surface as defined by EARTH_MSL_RADIUS

lat: latitude in degrees

lon: longitude in degrees

Examples

fn from_cartesian(v: Vector3<f64>) -> SphericalCoordinate

Create a new SphericalCoordinate from cartesian coordinate.

Scale of vector v needs to be in meters, with reference position being the centre of the sphere.

fn rectify_bounds(&self) -> SphericalCoordinate

Create a clone with values that fall within the normal boundary of Spherical coordinate system.

fn rectify_bounds_inplace(&mut self)

Ensure that this object's values fall within the normal boundary of Spherical coordinate system.

fn approx_eq(&self, other: &SphericalCoordinate, epsilon: f64) -> bool

Check whether this SphericalCoordinate and another are approximately equal

Examples


let pos1 = SphericalCoordinate::new(10.0, PI, 0.0);
let pos2 = SphericalCoordinate::new(10.0, PI, 0.1);
assert!(pos1.approx_eq(&pos2, 0.2));

fn alt(&self) -> f64

get the altitude

fn set_alt(&mut self, alt: f64)

set the altitude above MSL (in metres)

fn lat(&self) -> f64

get the latitude (in degrees)

fn set_lat(&mut self, lat: f64)

set the latitude (in degrees)

fn lon(&self) -> f64

get the longitude (in degrees)

fn set_lon(&mut self, lon: f64)

set the longitude (in degrees)

fn r_cart_uv(&self) -> Vector3<f64>

get the r cartesian unit vector

fn phi_cart_uv(&self) -> Vector3<f64>

get the phi cartesian unit vector

fn theta_cart_uv(&self) -> Vector3<f64>

get the theta cartesian unit vector

fn arc_distance(&self, other: &SphericalCoordinate) -> f64

arc distance between two points along the surface of the sphere. warning: only tested to be accurate to within 5 meters at earth's surface

fn fmt_geographic(&self) -> String

Format the SphericalCoordinate as a Geographical point string (altitude, latitude and longitude).

fn angle_difference_heuristic(&self, other: &SphericalCoordinate) -> f64

A very simple difference in angle heuristic

Trait Implementations

impl Clone for SphericalCoordinate
[src]

fn clone(&self) -> SphericalCoordinate

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Copy for SphericalCoordinate
[src]

impl Debug for SphericalCoordinate
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Display for SphericalCoordinate
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Geohashable<SphericalCoordinate> for SphericalCoordinate
[src]

fn integer_decode(geohash: u64) -> Result<SphericalCoordinateString>

decode this object of type Tfrom an integer geohash

fn integer_encode(&self, precision: u8) -> Result<u64String>

encode this object of type T into an unsigned integer geohash