+dumbbell

This commit is contained in:
Alain Zscheile 2024-01-05 20:46:14 +01:00
parent 0de797d45b
commit b74b9e4c7f
2 changed files with 28 additions and 0 deletions

View file

@ -34,6 +34,29 @@ pub fn circle_sin_chain1(w: f64) -> impl Fn(f64) -> [f64; 2] {
}
}
// source: https://mathworld.wolfram.com/DumbbellCurve.html
pub fn dumbbell(a: f64) -> impl Fn(f64) -> [f64; 2] {
move |t: f64| {
if t <= 0.25 {
let tm4 = t * 4.0;
let t2 = tm4 * tm4;
[a * tm4, a * t2 * (1.0 - t2).sqrt()]
} else if t <= 0.5 {
let tm4 = 1.0 - (t - 0.25) * 4.0;
let t2 = tm4.powi(2);
[a * tm4, -a * t2 * (1.0 - t2).sqrt()]
} else if t <= 0.75 {
let tm4 = (t - 0.5) * 4.0;
let t2 = tm4.powi(2);
[-a * tm4, a * t2 * (1.0 - t2).sqrt()]
} else {
let tm4 = 1.0 - (t - 0.75) * 4.0;
let t2 = tm4.powi(2);
[-a * tm4, -a * t2 * (1.0 - t2).sqrt()]
}
}
}
pub fn ellipse(a: f64, b: f64) -> impl Fn(f64) -> [f64; 2] {
move |t: f64| {
let cdat = circle(t);

View file

@ -12,6 +12,7 @@ pub enum SelectExample {
CassiniAntiAstroid { ca: f64, cc: f64, aa: f64 },
CassiniAstroidTsq { ca: f64, cc: f64, aa: f64 },
Dumbbell { a: f64 },
Ellipse { a: f64, b: f64 },
Lemniskate { a: f64 },
CirclePow { k: f64 },
@ -42,6 +43,9 @@ impl SelectExample {
*cc += l;
*aa += l;
}
Self::Dumbbell { a } => {
*a += l;
}
Self::Ellipse { a, b } => {
*a /= 1.0 + l;
*b *= 1.0 + l;
@ -79,6 +83,7 @@ impl SelectExample {
let x = ex::cassini_astroid(ca, cc, aa);
Box::new(move |t: f64| x(t * t))
}
Self::Dumbbell { a } => Box::new(ex::dumbbell(a)),
Self::Ellipse { a, b } => Box::new(ex::ellipse(a, b)),
Self::Lemniskate { a } => Box::new(move |t: f64| ex::lemniskate(t, a)),
Self::CirclePow { k } => Box::new(ex::circle_pow(k)),