pub fn maxwell_montes_summit_m() -> f64 {
11_000.0
}
pub fn deep_basin_m() -> f64 {
-2_500.0
}
pub fn venus_elevation(lat_deg: f64, lon_deg: f64) -> f64 {
let lat = lat_deg.to_radians();
let lon = lon_deg.to_radians();
let aphrodite = 3000.0 * (-(lat * lat + (lon - 2.0).powi(2)) / 0.5).exp();
let ishtar = 5000.0 * (-((lat - 1.2).powi(2) + (lon + 1.0).powi(2)) / 0.2).exp();
aphrodite + ishtar
}
pub struct Heightmap {
pub data: Vec<f64>,
pub width: usize,
pub height: usize,
}
impl Heightmap {
pub fn generate(width: usize, height: usize) -> Self {
let mut data = vec![0.0; width * height];
for j in 0..height {
let lat = 90.0 - (j as f64 / height as f64) * 180.0;
for i in 0..width {
let lon = (i as f64 / width as f64) * 360.0 - 180.0;
data[j * width + i] = venus_elevation(lat, lon);
}
}
Self {
data,
width,
height,
}
}
pub fn sample(&self, lat_deg: f64, lon_deg: f64) -> f64 {
let u = ((lon_deg + 180.0) / 360.0).clamp(0.0, 1.0);
let v = ((90.0 - lat_deg) / 180.0).clamp(0.0, 1.0);
let x = u * (self.width - 1) as f64;
let y = v * (self.height - 1) as f64;
let ix = (x as usize).min(self.width - 2);
let iy = (y as usize).min(self.height - 2);
let fx = x - ix as f64;
let fy = y - iy as f64;
let v00 = self.data[iy * self.width + ix];
let v10 = self.data[iy * self.width + ix + 1];
let v01 = self.data[(iy + 1) * self.width + ix];
let v11 = self.data[(iy + 1) * self.width + ix + 1];
v00 * (1.0 - fx) * (1.0 - fy)
+ v10 * fx * (1.0 - fy)
+ v01 * (1.0 - fx) * fy
+ v11 * fx * fy
}
}