plotters
plotters copied to clipboard
Looks like rendering issue with surface plot
Discussed in https://github.com/orgs/plotters-rs/discussions/299
Originally posted by DaMilyutin October 30, 2021 Hi,
I'm playting with sixtyfps. I've changed plotter example https://github.com/sixtyfpsui/sixtyfps/tree/master/examples/plotter to plot gauss surface and have plotting depending on az and el (i.e. pitch and yaw).
On some particular values of el and az happens something like this

And this one is ok

Code for plotting
fn pdf(x: f64, y: f64) -> f64 {
const SDX: f64 = 0.1;
const SDY: f64 = 0.05;
const A: f64 = 5.0;
let x = x as f64 / 10.0;
let y = y as f64 / 10.0;
A * (-x * x / 2.0 / SDX / SDX - y * y / 2.0 / SDY / SDY).exp()
}
fn render_plot(el: f32, az: f32) -> sixtyfps::Image {
let mut pixel_buffer = SharedPixelBuffer::new(640, 480);
let size = (pixel_buffer.width() as u32, pixel_buffer.height() as u32);
let backend = BitMapBackend::with_buffer(pixel_buffer.make_mut_bytes(), size);
// Plotters requires TrueType fonts from the file system to draw axis text - we skip that for
// WASM for now.
#[cfg(target_arch = "wasm32")]
let backend = wasm_backend::BackendWithoutText { backend };
let root = backend.into_drawing_area();
root.fill(&WHITE).expect("error filling drawing area");
let mut chart = ChartBuilder::on(&root)
.build_cartesian_3d(-3.0..3.0, 0.0..6.0, -3.0..3.0)
.expect("error building coordinate system");
chart.with_projection(|mut p| {
p.pitch = 0.017453292 * el as f64;
p.yaw = 0.017453292 * az as f64;
p.scale = 0.7;
p.into_matrix() // build the projection matrix
});
chart.configure_axes().draw().expect("error drawing");
let scale = 10. as f64;
let ind = (3. * scale) as i64;
chart
.draw_series(
SurfaceSeries::xoz(
(-ind..=ind).map(|x| x as f64 / scale),
(-ind..=ind).map(|x| x as f64 / scale),
pdf,
)
.style_func(&|&v| {
(&HSLColor(240.0 / 360.0 - 240.0 / 360.0 * v / 5.0, 1.0, 0.7)).into()
}),
)
.expect("error drawing series");
root.present().expect("error presenting");
drop(chart);
drop(root);
sixtyfps::Image::from_rgb8(pixel_buffer)
}
With this and angle you probably reproduce these effects.
I'm not sure if all is done right on my side. So give me advise if you see any misses.
Feel free to request any additional data or code.