+spiral curve

This commit is contained in:
Alain Zscheile 2023-12-07 23:34:47 +01:00
parent d43e036dc0
commit 9089863a81
2 changed files with 14 additions and 1 deletions

View file

@ -139,3 +139,13 @@ pub fn cassini_astroid(ca: f64, cc: f64, aa: f64) -> impl Fn(f64) -> [f64; 2] {
[ap[0] + cs[0], ap[1] + cs[1]]
}
}
pub fn spiral(k: u32) -> impl Fn(f64) -> [f64; 2] {
let x2pi = (k as f64) * core::f64::consts::TAU;
move |t: f64| {
let tstretch = t - 0.5;
let tstretch2 = tstretch * tstretch;
let (ttxsin, ttxcos) = (t * x2pi).sin_cos();
[tstretch2 * ttxcos, tstretch2 * ttxsin]
}
}

View file

@ -17,6 +17,8 @@ pub enum SelectExample {
Lemniskate { a: f64 },
Spiral { k: u32 },
Circle,
Intersect8,
Intersect8pp,
@ -42,7 +44,7 @@ impl SelectExample {
Self::Lemniskate { a } => {
*a += l;
}
Self::Circle | Self::Intersect8 | Self::Intersect8pp => {
Self::Spiral { .. } | Self::Circle | Self::Intersect8 | Self::Intersect8pp => {
panic!("offsetting not supported for this example")
}
}
@ -59,6 +61,7 @@ impl SelectExample {
},
Self::Ellipse { a, b } => Box::new(ex::ellipse(a, b)),
Self::Lemniskate { a } => Box::new(move |t: f64| ex::lemniskate(t, a)),
Self::Spiral { k } => Box::new(ex::spiral(k)),
Self::Circle => Box::new(ex::circle),
Self::Intersect8 => Box::new(ex::intersect_eight),
Self::Intersect8pp => Box::new(ex::intersect_8pp),