use std::f64::consts::PI; use chrono::{DateTime,Utc}; use serde::{Deserialize,Serialize}; pub fn earth_rotation_angle(t_u:f64) -> f64 { //returns radians 2.0*PI*(0.7790572732640 + 1.00273781191135448*t_u) % std::f64::consts::TAU } //to be deleted dont think i need it much longer? pub async fn get_celerak_data() -> (Option,Option>) { let mut resp = ureq::get("https://celestrak.org/NORAD/elements/gp.php?GROUP=stations&FORMAT=json").call().unwrap(); //blocking, and thats okey. let element_vec:Vec = resp.body_mut().read_json().unwrap(); let epoch = &element_vec[0].datetime.and_utc(); let iss_constant = sgp4::Constants::from_elements(&element_vec[0]).unwrap(); (Some(iss_constant),Some(*epoch)) } // i should be using the geoid crate but this is good enough for now pub fn polar_loc_transformer(loc: [f64;3]) -> [f32;2] { let theta = -((loc[2]/ (loc[0].powi(2) + loc[1].powi(2) + loc[2].powi(2)).powf(0.5)).acos() - PI/2.0); let phi = loc[1].signum() * (loc[0]/(loc[0].powi(2) + loc[1].powi(2)).powf(0.5)).acos(); [(phi*180.0/PI) as f32, (theta*180.0/PI) as f32] } #[derive(Debug,Clone,PartialEq,Deserialize,Serialize)] pub struct Location { pub latitude: String, pub longitude: String } #[derive(Debug,Clone,Deserialize,Serialize)] pub struct FLocation { pub latitude: f32, pub longitude: f32 } impl From for FLocation { fn from(value: Location) -> Self { FLocation { longitude: value.longitude.parse().unwrap(), latitude: value.latitude.parse().unwrap() } } } #[derive(Debug,Clone,PartialEq,Deserialize,Serialize)] pub struct LocationResponse { pub iss_position: Location, message: String, timestamp: i64 }