Skip to main content

Position

Struct Position 

Source
pub struct Position {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}
Expand description

3D position vector

Fields§

§x: f64

X coordinate (AU)

§y: f64

Y coordinate (AU)

§z: f64

Z coordinate (AU)

Implementations§

Source§

impl Position

Source

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

Create a new position

Source

pub fn distance(&self) -> f64

Calculate distance from origin

Examples found in repository?
examples/planetary_positions.rs (line 45)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    println!("=== Planetary Positions Example ===\n");
9
10    // Initialize ephemeris
11    let eph = Ephemeris::new("config.toml")?;
12
13    // Define dates to query
14    let dates = vec![
15        (2024, 1, 1, 0, 0, 0.0),
16        (2024, 6, 15, 12, 0, 0.0),
17        (2024, 12, 31, 23, 59, 59.0),
18    ];
19
20    let bodies = vec!["Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter"];
21
22    for (year, month, day, hour, minute, second) in dates {
23        let jd = JulianDate::from_calendar(year, month, day, hour, minute, second)?;
24        println!(
25            "Date: {}-{:02}-{:02} {:02}:{:02}:{:02} (JD: {:.6})",
26            year,
27            month,
28            day,
29            hour,
30            minute,
31            second as i32,
32            jd.as_f64()
33        );
34        println!("{}", "=".repeat(70));
35
36        for body_name in &bodies {
37            match eph.get_position(body_name, jd) {
38                Ok(pos) => {
39                    println!(
40                        "  {:10} | X: {:12.6} | Y: {:12.6} | Z: {:12.6} | Distance: {:10.6} AU",
41                        body_name,
42                        pos.x,
43                        pos.y,
44                        pos.z,
45                        pos.distance()
46                    );
47                }
48                Err(e) => {
49                    println!("  {:10} | Error: {}", body_name, e);
50                }
51            }
52        }
53        println!();
54    }
55
56    Ok(())
57}
More examples
Hide additional examples
examples/basic_usage.rs (line 98)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    println!("=== Rust JPL Ephemeris Reader - Basic Usage Example ===\n");
13
14    // Initialize the ephemeris from config.toml
15    println!("1. Initializing Ephemeris...");
16    let eph = Ephemeris::new("config.toml")?;
17    println!("   ✓ Ephemeris loaded successfully\n");
18
19    // Display metadata
20    println!("2. Ephemeris Metadata:");
21    let metadata = eph.get_metadata();
22    println!(
23        "   - Date Range: {} - {}",
24        metadata.start_year, metadata.end_year
25    );
26    println!(
27        "   - Julian Date Range: {:.2} - {:.2}",
28        metadata.julian_start, metadata.julian_end
29    );
30    println!("   - Interval: {} days", metadata.interval_days);
31    println!(
32        "   - Earth-Moon Mass Ratio: {:.6}",
33        metadata.earth_moon_ratio
34    );
35    println!(
36        "   - Number of Coefficients: {}\n",
37        metadata.number_of_coefficients
38    );
39
40    // List available bodies
41    println!("3. Available Celestial Bodies:");
42    for body in eph.get_bodies() {
43        let status = if body.active { "✓" } else { "✗" };
44        println!(
45            "   {} {} ({})",
46            status,
47            body.name,
48            if body.active { "active" } else { "inactive" }
49        );
50    }
51    println!();
52
53    // Time conversion example
54    println!("4. Time Conversion Example:");
55    let calendar_date = rust_jpl::CalendarDate::new(2024, 1, 15, 12, 0, 0.0);
56    println!(
57        "   Calendar Date: {}-{:02}-{:02} {:02}:{:02}:{:02}",
58        calendar_date.year,
59        calendar_date.month,
60        calendar_date.day,
61        calendar_date.hour,
62        calendar_date.minute,
63        calendar_date.second as i32
64    );
65
66    let jd = calendar_date.to_julian()?;
67    println!("   Julian Date: {:.6}", jd.as_f64());
68
69    let converted_back = jd.to_calendar();
70    println!(
71        "   Converted back: {}-{:02}-{:02} {:02}:{:02}:{:02}\n",
72        converted_back.year,
73        converted_back.month,
74        converted_back.day,
75        converted_back.hour,
76        converted_back.minute,
77        converted_back.second as i32
78    );
79
80    // Get planetary positions
81    println!(
82        "5. Planetary Positions (at Julian Date {:.6}):",
83        jd.as_f64()
84    );
85    let bodies = [
86        "Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn",
87    ];
88
89    for body_name in &bodies {
90        match eph.get_position(body_name, jd) {
91            Ok(pos) => {
92                println!(
93                    "   {}: ({:12.6}, {:12.6}, {:12.6}) AU, Distance: {:.6} AU",
94                    body_name,
95                    pos.x,
96                    pos.y,
97                    pos.z,
98                    pos.distance()
99                );
100            }
101            Err(e) => {
102                println!("   {}: Error - {}", body_name, e);
103            }
104        }
105    }
106
107    println!("\n=== Example Complete ===");
108    Ok(())
109}

Trait Implementations§

Source§

impl Clone for Position

Source§

fn clone(&self) -> Position

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 Position

Source§

impl Debug for Position

Source§

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

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

impl PartialEq for Position

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for Position

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> 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.