Skip to main content

Position3D

Struct Position3D 

Source
pub struct Position3D {
    pub x_m: f64,
    pub y_m: f64,
    pub z_m: f64,
}
Expand description

A Cartesian position in meters.

Coordinates are intentionally reference-frame agnostic. A topology may use local east/north/up coordinates, Earth-centered coordinates, or another consistent frame appropriate to the simulation.

Fields§

§x_m: f64

X coordinate in meters.

§y_m: f64

Y coordinate in meters.

§z_m: f64

Z coordinate in meters.

Implementations§

Source§

impl Position3D

Source

pub const ORIGIN: Self

The origin of a coordinate frame.

Source

pub const fn new(x_m: f64, y_m: f64, z_m: f64) -> Self

Creates a position from coordinates measured in meters.

Examples found in repository?
examples/moving_link.rs (line 17)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let network = NetworkConfig {
10        devices: vec![
11            DeviceConfig {
12                id: "aircraft".into(),
13                kind: DeviceKind::Source {
14                    egress: "radio".into(),
15                },
16                mobility: MobilityModel::Linear {
17                    position_at_epoch: Position3D::new(100_000.0, 0.0, 10_000.0),
18                    velocity_mps: Velocity3D::new(-150.0, 0.0, 0.0),
19                    epoch_ns: 0,
20                },
21                interference: vec![],
22            },
23            DeviceConfig {
24                id: "ground_station".into(),
25                kind: DeviceKind::Sink,
26                mobility: MobilityModel::Static {
27                    position: Position3D::ORIGIN,
28                },
29                interference: vec![],
30            },
31        ],
32        channels: vec![ChannelConfig {
33            id: "radio".into(),
34            endpoints: ["aircraft".into(), "ground_station".into()],
35            bit_rate_bps: 10_000_000,
36            propagation_delay_ns: 50_000,
37            state: ChannelState::Operational,
38            distance: Some(DistanceChannel {
39                propagation_speed_mps: 299_792_458.0,
40                max_range_m: 120_000.0,
41                rate_model: DistanceRateModel::Linear {
42                    full_rate_distance_m: 20_000.0,
43                    minimum_bit_rate_bps: 1_000_000,
44                },
45            }),
46            radio: None,
47        }],
48    };
49
50    let mut simulator = Simulator::new(network)?;
51    simulator.schedule_send(SimTime::ZERO, "aircraft", "ground_station", vec![0; 1_000])?;
52    simulator.schedule_send(
53        SimTime::from_nanos(300_000_000_000),
54        "aircraft",
55        "ground_station",
56        vec![0; 1_000],
57    )?;
58    simulator.schedule_send(
59        SimTime::from_nanos(1_500_000_000_000),
60        "aircraft",
61        "ground_station",
62        vec![0; 1_000],
63    )?;
64
65    simulator.run_with(|event| match event {
66        NetworkEvent::TransmissionStarted {
67            at,
68            distance_mm,
69            effective_bit_rate_bps,
70            ..
71        } => println!(
72            "{at}: distance {:.1} km, rate {:.2} Mbit/s",
73            distance_mm.unwrap_or_default() as f64 / 1_000_000.0,
74            *effective_bit_rate_bps as f64 / 1_000_000.0,
75        ),
76        NetworkEvent::PacketDropped { at, reason, .. } => {
77            println!("{at}: packet dropped: {reason:?}");
78        }
79        _ => {}
80    })?;
81    Ok(())
82}
Source

pub fn distance_to(self, other: Self) -> f64

Returns the Euclidean distance to another position in meters.

Trait Implementations§

Source§

impl Clone for Position3D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Position3D

Source§

impl Debug for Position3D

Source§

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

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

impl Default for Position3D

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Position3D

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 Position3D

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Position3D

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 Position3D

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.