-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathplot3d.rs
42 lines (34 loc) · 1.07 KB
/
plot3d.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::DrawResult;
use plotters::prelude::*;
use plotters_canvas::CanvasBackend;
use web_sys::HtmlCanvasElement;
pub fn draw(canvas: HtmlCanvasElement, pitch: f64, yaw: f64) -> DrawResult<()> {
let area = CanvasBackend::with_canvas_object(canvas)
.unwrap()
.into_drawing_area();
area.fill(&WHITE)?;
let x_axis = (-3.0..3.0).step(0.1);
let z_axis = (-3.0..3.0).step(0.1);
let mut chart =
ChartBuilder::on(&area).build_cartesian_3d(x_axis.clone(), -3.0..3.0, z_axis.clone())?;
chart.with_projection(|mut pb| {
pb.yaw = yaw;
pb.pitch = pitch;
pb.scale = 0.7;
pb.into_matrix()
});
chart.configure_axes().draw()?;
chart.draw_series(
SurfaceSeries::xoz(x_axis.values(), z_axis.values(), |x:f64, z:f64| {
(x * x + z * z).cos()
})
.style(&BLUE.mix(0.2)),
)?;
chart.draw_series(LineSeries::new(
(-100..100)
.map(|y| y as f64 / 40.0)
.map(|y| ((y * 10.0).sin(), y, (y * 10.0).cos())),
&BLACK,
))?;
Ok(())
}