dumbbell: add y pressure
This commit is contained in:
parent
d1dd84cdfa
commit
996daaadd8
11
src/ex.rs
11
src/ex.rs
|
@ -35,24 +35,25 @@ 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] {
|
||||
pub fn dumbbell(a: f64, p: f64) -> impl Fn(f64) -> [f64; 2] {
|
||||
let adp = a / p;
|
||||
move |t: f64| {
|
||||
if t <= 0.25 {
|
||||
let tm4 = t * 4.0;
|
||||
let t2 = tm4 * tm4;
|
||||
[a * tm4, a * t2 * (1.0 - t2).sqrt()]
|
||||
[a * tm4, adp * 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()]
|
||||
[a * tm4, -adp * 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()]
|
||||
[-a * tm4, -adp * 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()]
|
||||
[-a * tm4, adp * t2 * (1.0 - t2).sqrt()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ pub enum SelectExample {
|
|||
CassiniAntiAstroid { ca: f64, cc: f64, aa: f64 },
|
||||
CassiniAstroidTsq { ca: f64, cc: f64, aa: f64 },
|
||||
|
||||
Dumbbell { a: f64 },
|
||||
Dumbbell { a: f64, p: f64 },
|
||||
Ellipse { a: f64, b: f64 },
|
||||
Lemniskate { a: f64 },
|
||||
CirclePow { k: f64 },
|
||||
|
@ -43,7 +43,7 @@ impl SelectExample {
|
|||
*cc += l;
|
||||
*aa += l;
|
||||
}
|
||||
Self::Dumbbell { a } => {
|
||||
Self::Dumbbell { a, .. } => {
|
||||
*a += l;
|
||||
}
|
||||
Self::Ellipse { a, b } => {
|
||||
|
@ -83,7 +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::Dumbbell { a, p } => Box::new(ex::dumbbell(a, p)),
|
||||
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)),
|
||||
|
|
Loading…
Reference in a new issue