deep_causality/types/context_node_types/space/ned_space/mod.rs
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6mod adjustable;
7mod coordinate;
8mod display;
9mod getters;
10mod identifiable;
11mod metric;
12mod spatial;
13
14/// A local tangent-plane spatial context using the North-East-Down (NED) reference frame.
15///
16/// `NedSpace` represents a point in a locally linearized coordinate system centered at a reference
17/// geodetic location (typically defined by a GPS fix). It is commonly used in aerospace,
18/// robotics, and real-time navigation systems to express motion and sensor positions
19/// relative to a local Earth-aligned frame.
20///
21/// This frame uses the following axis definitions:
22/// - **North (+N)**: tangential to the Earth's surface, pointing toward the North Pole
23/// - **East (+E)**: tangential to the Earth's surface, perpendicular to North, pointing eastward
24/// - **Down (+D)**: aligned with gravity, pointing toward the Earth's center (positive downward)
25///
26/// This results in a **right-handed coordinate system** with the origin at a defined reference point,
27/// and the frame fixed to the Earth — making it suitable for integrating IMUs, magnetometers, and
28/// other aircraft-attached sensors.
29///
30/// # Fields
31/// - `id`: Unique numeric identifier for this NED spatial context (e.g., sensor ID)
32/// - `north`: Position in meters along the northward axis
33/// - `east`: Position in meters along the eastward axis
34/// - `down`: Position in meters along the downward (gravity-aligned) axis
35///
36/// # Coordinate Index Mapping
37/// When used with the `Coordinate` trait, the following index mapping applies:
38/// - `0 => north`
39/// - `1 => east`
40/// - `2 => down`
41///
42/// # Common Applications
43/// - Aircraft position estimation relative to a flight segment origin
44/// - Magnetometer placement in local frame for MagNav systems
45/// - Inertial Navigation System (INS) drift correction
46/// - Real-time sensor fusion in autonomous drones or ground vehicles
47///
48/// # Example
49/// ```
50/// use deep_causality::*;
51///
52/// let n1 = NedSpace::new(1, 0.0, 0.0, 0.0); // Reference origin
53/// let n2 = NedSpace::new(2, 100.0, 50.0, 10.0); // 100m North, 50m East, 10m below origin
54///
55/// println!("{}", n2);
56///
57/// assert_eq!(n2.dimension(), 3);
58/// assert_eq!(n1.distance(&n2), (100.0_f64.powi(2) + 50.0_f64.powi(2) + 10.0_f64.powi(2)).sqrt());
59/// ```
60///
61/// # Notes
62/// - The "down" axis is **positive in the direction of gravity**. This is a key difference
63/// from ENU (East-North-Up) or typical 3D Cartesian conventions.
64/// - This struct assumes **flat-Earth approximation** — for global modeling, use `GeoSpace` or `EcefSpace`.
65#[derive(Debug, Clone, PartialEq)]
66pub struct NedSpace {
67 /// Unique numeric ID for this local NED context
68 id: u64,
69 /// Distance north from the reference point (in meters)
70 north: f64,
71 /// Distance east from the reference point (in meters)
72 east: f64,
73 /// Vertical distance down from the reference point (in meters, positive = downward)
74 down: f64,
75}
76
77impl NedSpace {
78 pub fn new(id: u64, north: f64, east: f64, down: f64) -> Self {
79 Self {
80 id,
81 north,
82 east,
83 down,
84 }
85 }
86}