clean star pos
This commit is contained in:
parent
0f5f353fd4
commit
c0725dcceb
79
src/main.rs
79
src/main.rs
|
@ -6,6 +6,7 @@ use bevy::math::*;
|
|||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::f64::consts::PI;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct StarData {
|
||||
|
@ -49,16 +50,32 @@ fn setup(
|
|||
|
||||
let stars = get_stars().unwrap();
|
||||
|
||||
let star_size = 0.02;
|
||||
let sky_radius = 2.0;
|
||||
|
||||
for star in stars {
|
||||
info!("{:?}", star);
|
||||
|
||||
let star_pos = star_position(star) * sky_radius;
|
||||
info!("{:?}", star_pos);
|
||||
|
||||
// commands.spawn((
|
||||
// PbrBundle {//Plane3d::default().mesh().size(1., 1.)
|
||||
// mesh: meshes.add(Cuboid::new(star_size, star_size, star_size)),
|
||||
// material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
|
||||
// transform: Transform::from_xyz(star_pos.x, star_pos.y, star_pos.z),
|
||||
// ..default()
|
||||
// },
|
||||
// Star,
|
||||
// ));
|
||||
|
||||
}
|
||||
|
||||
|
||||
let star_size = 0.02;
|
||||
commands.spawn((
|
||||
PbrBundle {//Plane3d::default().mesh().size(1., 1.)
|
||||
mesh: meshes.add(Cuboid::new(star_size, star_size, star_size)),
|
||||
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb(1.0, 0.0, 0.0)),
|
||||
transform: Transform::from_xyz(1.0, 0.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
|
@ -90,23 +107,45 @@ fn get_stars() -> std::io::Result<Vec<StarData>> {
|
|||
Ok(stars)
|
||||
}
|
||||
|
||||
// fn star_position_to_spherical(ra_hours: f32, dec_deg: f32, dec_min: f32, dec_sec: f32) -> Vec3 {
|
||||
// // Convert declination to decimal degrees
|
||||
// let dec_decimal = declination_to_decimal(dec_deg, dec_min, dec_sec);
|
||||
//
|
||||
// // Convert Right Ascension from hours to degrees
|
||||
// let ra_degrees = right_ascension_to_degrees(ra_hours);
|
||||
//
|
||||
// // Convert to spherical coordinates
|
||||
// let theta = ra_degrees.to_radians(); // RA as theta (azimuthal angle)
|
||||
// let phi = (90.0 - dec_decimal).to_radians(); // Declination to phi (polar angle)
|
||||
//
|
||||
// // Assuming a unit sphere, the radius (r) is 1. Calculate Cartesian coordinates.
|
||||
// let x = phi.sin() * theta.cos();
|
||||
// let y = phi.sin() * theta.sin();
|
||||
// let z = phi.cos();
|
||||
//
|
||||
// Vec3::new(x, y, z)
|
||||
// }
|
||||
fn star_position(star_data: StarData) -> Vec3 {
|
||||
// Convert declination to decimal degrees
|
||||
let text_ra = star_data.ra;
|
||||
let text_dec = star_data.dec;
|
||||
|
||||
let ra_seconds: f64 = 3600.0 * text_ra[0..2].parse::<f64>().unwrap()
|
||||
+ 60.0 * text_ra[4..6].parse::<f64>().unwrap()
|
||||
+ text_ra[8..12].parse::<f64>().unwrap();
|
||||
|
||||
info!(text_dec);
|
||||
// Parse Dec
|
||||
let formated_dec = text_dec
|
||||
.replace("°", " ")
|
||||
.replace("′", " ")
|
||||
.replace("″", " ");
|
||||
let dec_parts: Vec<&str> = formated_dec.split_whitespace().collect();
|
||||
|
||||
let dec_deg: f64 = dec_parts[0].parse::<f64>().unwrap()
|
||||
+ dec_parts[1].parse::<f64>().unwrap() / 60.0
|
||||
+ dec_parts[2].parse::<f64>().unwrap() / 3600.0;
|
||||
|
||||
let dec_sign : f64 = if text_dec.starts_with('-') {
|
||||
-1.0
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
|
||||
return celestial_to_cartesian(ra_seconds/3600.0, dec_sign * dec_deg)
|
||||
}
|
||||
|
||||
fn celestial_to_cartesian(rah: f64, ded: f64) -> Vec3 {
|
||||
let y_rot = 2.0 * PI * rah / 24.0;
|
||||
let x_rot = 2.0 * PI * ded / 360.0;
|
||||
|
||||
let x : f32 = (y_rot.sin() * x_rot.cos()) as f32;
|
||||
let y : f32 = x_rot.sin() as f32;
|
||||
let z : f32 = (y_rot.cos() * x_rot.cos()) as f32;
|
||||
|
||||
Vec3::new(x, y, z)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue