Point3d

Struct Point3d 

Source
pub struct Point3d {
    pub point: Point,
    pub z: f64,
}
Expand description

A 3D geographic point with x, y (longitude/latitude) and z (altitude/elevation).

This type represents a point in 3D space, typically used for altitude-aware geospatial applications like drone tracking, aviation, or multi-floor buildings.

§Examples

use spatio_types::point::Point3d;
use spatio_types::geo::Point;

// Create a 3D point for a drone at 100 meters altitude
let drone_position = Point3d::new(-74.0060, 40.7128, 100.0);
assert_eq!(drone_position.altitude(), 100.0);

// Calculate 3D distance to another point
let other = Point3d::new(-74.0070, 40.7138, 150.0);
let distance = drone_position.distance_3d(&other);

Fields§

§point: Point

The 2D geographic point (longitude/latitude or x/y)

§z: f64

The altitude/elevation/z-coordinate (in meters typically)

Implementations§

Source§

impl Point3d

Source

pub fn new(x: f64, y: f64, z: f64) -> Self

Create a new 3D point from x, y, and z coordinates.

§Arguments
  • x - Longitude or x-coordinate
  • y - Latitude or y-coordinate
  • z - Altitude/elevation in meters
§Examples
use spatio_types::point::Point3d;

let point = Point3d::new(-74.0060, 40.7128, 100.0);
Source

pub fn from_point_and_altitude(point: Point, z: f64) -> Self

Create a 3D point from a 2D point and altitude.

Source

pub fn x(&self) -> f64

Get the x coordinate (longitude).

Source

pub fn y(&self) -> f64

Get the y coordinate (latitude).

Source

pub fn z(&self) -> f64

Get the z coordinate (altitude/elevation).

Source

pub fn altitude(&self) -> f64

Get the altitude (alias for z()).

Source

pub fn point_2d(&self) -> &Point

Get a reference to the underlying 2D point.

Source

pub fn to_2d(&self) -> Point

Project this 3D point to 2D by discarding the z coordinate.

Source

pub fn distance_3d(&self, other: &Point3d) -> f64

Calculate the 3D Euclidean distance to another 3D point.

This calculates the straight-line distance in 3D space using the Pythagorean theorem.

§Examples
use spatio_types::point::Point3d;

let p1 = Point3d::new(0.0, 0.0, 0.0);
let p2 = Point3d::new(3.0, 4.0, 12.0);
let distance = p1.distance_3d(&p2);
assert_eq!(distance, 13.0); // 3-4-5 triangle extended to 3D
Source

pub fn haversine_distances(&self, other: &Point3d) -> (f64, f64, f64)

Calculate all distance components at once (horizontal, altitude, 3D).

This is more efficient than calling haversine_2d and haversine_3d separately as it calculates the haversine formula only once.

§Returns

Tuple of (horizontal_distance, altitude_difference, distance_3d) in meters.

§Examples
use spatio_types::point::Point3d;

let p1 = Point3d::new(-74.0060, 40.7128, 0.0);
let p2 = Point3d::new(-74.0070, 40.7138, 100.0);
let (h_dist, alt_diff, dist_3d) = p1.haversine_distances(&p2);
Source

pub fn haversine_3d(&self, other: &Point3d) -> f64

Calculate the haversine distance combined with altitude difference.

This uses the haversine formula for the horizontal distance (considering Earth’s curvature) and combines it with the altitude difference using the Pythagorean theorem.

§Returns

Distance in meters.

§Examples
use spatio_types::point::Point3d;

let p1 = Point3d::new(-74.0060, 40.7128, 0.0);    // NYC sea level
let p2 = Point3d::new(-74.0070, 40.7138, 100.0);  // Nearby, 100m up
let distance = p1.haversine_3d(&p2);
Source

pub fn haversine_2d(&self, other: &Point3d) -> f64

Calculate the haversine distance on the 2D plane (ignoring altitude).

§Returns

Distance in meters.

Source

pub fn altitude_difference(&self, other: &Point3d) -> f64

Get the altitude difference to another point.

Trait Implementations§

Source§

impl Clone for Point3d

Source§

fn clone(&self) -> Point3d

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Point3d

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Point3d

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Point3d

Source§

fn eq(&self, other: &Point3d) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Point3d

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Point3d

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,