pub struct Position {
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
3D position vector
Fields§
§x: f64X coordinate (AU)
y: f64Y coordinate (AU)
z: f64Z coordinate (AU)
Implementations§
Source§impl Position
impl Position
Sourcepub fn distance(&self) -> f64
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
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§
impl Copy for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more