1use cadrum::{DQuat, DVec3, Solid};
2use std::f64::consts::TAU;
3
4const M: usize = 48; const N: usize = 24; const RING_R: f64 = 6.0;
15
16fn point(i: usize, j: usize) -> DVec3 {
17 let phi = TAU * (i as f64) / (M as f64);
18 let theta = TAU * (j as f64) / (N as f64);
19 let two_phi = 2.0 * phi;
20 let a = 1.8 + 0.6 * two_phi.sin();
21 let b = 1.0 + 0.4 * two_phi.cos();
22 let psi = two_phi; let z_shift = 1.0 * two_phi.sin();
24 let local_raw = DVec3::X * (a * theta.cos()) + DVec3::Z * (b * theta.sin());
26 let local_twisted = DQuat::from_axis_angle(DVec3::Y, psi) * local_raw;
28 let local_shifted = local_twisted + DVec3::Z * z_shift;
30 let translated = local_shifted + DVec3::X * RING_R;
32 DQuat::from_axis_angle(DVec3::Z, phi) * translated
34}
35
36fn main() {
37 let example_name = std::path::Path::new(file!()).file_stem().unwrap().to_str().unwrap();
38
39 let plasma = Solid::bspline(M, N, true, point).expect("2-period bspline torus should succeed");
40 let objects = [plasma.color("cyan")];
41 let mut f = std::fs::File::create(format!("{example_name}.step")).unwrap();
42 cadrum::write_step(&objects, &mut f).unwrap();
43 let mut f_svg = std::fs::File::create(format!("{example_name}.svg")).unwrap();
44 cadrum::mesh(&objects, 0.1).and_then(|m| m.write_svg(DVec3::new(0.05, 0.05, 1.0), DVec3::Y, false, true, &mut f_svg)).unwrap();
45 println!("wrote {example_name}.step / {example_name}.svg");
46}