+SingularPetalRose

This commit is contained in:
Alain Zscheile 2024-01-05 02:01:19 +01:00
parent 8a06df925f
commit fe4d63bfd1
2 changed files with 25 additions and 11 deletions

View file

@ -1,15 +1,15 @@
/// explicit parametrizations of some curves
/// (t is a parameter in [0,1] with f(0) = f(1) periodic)
use core::f64::consts::TAU;
pub fn circle(t: f64) -> [f64; 2] {
// t * τ
let tt2pi = t * core::f64::consts::TAU;
let tt2pi = t * TAU;
let (ttsin, ttcos) = tt2pi.sin_cos();
[ttcos, ttsin]
}
pub fn circle_deriv(t: f64) -> [f64; 2] {
use core::f64::consts::TAU;
let tt2pi = t * TAU;
let (ttsin, ttcos) = tt2pi.sin_cos();
[-TAU * ttsin, TAU * ttcos]
@ -93,7 +93,7 @@ pub fn square(t: f64) -> [f64; 2] {
}
pub fn wobbly(t: f64, wob: u32) -> [f64; 2] {
let tt2pi = t * core::f64::consts::TAU;
let tt2pi = t * TAU;
let (ttsin, ttcos) = tt2pi.sin_cos();
let (ttxsin, ttxcos) = (tt2pi * (wob as f64)).sin_cos();
let wobinv = 1.0 / (wob as f64);
@ -101,7 +101,7 @@ pub fn wobbly(t: f64, wob: u32) -> [f64; 2] {
}
pub fn lemniskate(t: f64, a: f64) -> [f64; 2] {
let tt2pi = t * core::f64::consts::TAU;
let tt2pi = t * TAU;
let (ttsin, ttcos) = tt2pi.sin_cos();
[a * ttcos, a * ttcos * ttsin]
}
@ -113,7 +113,7 @@ pub fn cassini_oval(a: f64, c: f64) -> impl Fn(f64) -> [f64; 2] {
let a4 = a2 * a2;
let cahyp = c.hypot(a);
move |t: f64| {
let tt2pi = t * core::f64::consts::TAU;
let tt2pi = t * TAU;
let (ttsin, ttcos) = tt2pi.sin_cos();
let denom = c2 + a2 * ttsin * ttsin;
[
@ -125,7 +125,7 @@ pub fn cassini_oval(a: f64, c: f64) -> impl Fn(f64) -> [f64; 2] {
pub fn cassini_wobbly(a: f64, c: f64, wob: u32) -> impl Fn(f64) -> [f64; 2] {
let cassini = cassini_oval(a, c);
let wobx = (wob as f64) * core::f64::consts::TAU;
let wobx = (wob as f64) * TAU;
let wobinv = 1.0 / (wob as f64);
move |t: f64| {
let ttx2pi = t * wobx;
@ -139,7 +139,7 @@ pub fn cassini_wobbly(a: f64, c: f64, wob: u32) -> impl Fn(f64) -> [f64; 2] {
}
pub fn astroid_pedal(t: f64, a: f64) -> [f64; 2] {
let tt2pi = t * core::f64::consts::TAU;
let tt2pi = t * TAU;
let (ttsin, ttcos) = tt2pi.sin_cos();
[a * ttcos * ttsin * ttsin, a * ttcos * ttcos * ttsin]
}
@ -163,9 +163,9 @@ pub fn cassini_anti_astroid(ca: f64, cc: f64, aa: f64) -> impl Fn(f64) -> [f64;
}
pub fn spiral(k: u32) -> impl Fn(f64) -> [f64; 2] {
let x2pi = (k as f64) * core::f64::consts::TAU;
let x2pi = (k as f64) * TAU;
move |t: f64| {
let ttcos = (t * core::f64::consts::TAU).cos();
let ttcos = (t * TAU).cos();
let (ttxsin, ttxcos) = (t * x2pi).sin_cos();
[ttcos * ttxcos, ttcos * ttxsin]
}
@ -173,10 +173,21 @@ pub fn spiral(k: u32) -> impl Fn(f64) -> [f64; 2] {
pub fn spiral_1d(k: u32) -> impl Fn(f64) -> [f64; 2] {
let k = k as f64;
let x2pi = k * core::f64::consts::TAU;
let x2pi = k * TAU;
move |t: f64| {
let ttcos = k * (t * core::f64::consts::TAU).cos();
let ttcos = k * (t * TAU).cos();
let ttxsin = (t * x2pi).sin();
[ttcos, ttxsin]
}
}
// see also: https://commons.wikimedia.org/wiki/File:3_Petal_rose.svg
pub fn singular_petal_rose(k: u32) -> impl Fn(f64) -> [f64; 2] {
let k = k as f64;
let x2pi = k * TAU;
move |t: f64| {
let (txs, txc) = (t * x2pi).sin_cos();
let (ts, tc) = (t * TAU).sin_cos();
[txs + tc, ts + txc]
}
}

View file

@ -20,6 +20,7 @@ pub enum SelectExample {
Spiral { k: u32 },
Spiral1D { k: u32 },
SingularPetalRose { k: u32 },
Circle,
Square,
@ -51,6 +52,7 @@ impl SelectExample {
}
Self::Spiral { .. }
| Self::Spiral1D { .. }
| Self::SingularPetalRose { .. }
| Self::Circle
| Self::Square
| Self::Intersect8
@ -76,6 +78,7 @@ impl SelectExample {
Self::Lemniskate { a } => Box::new(move |t: f64| ex::lemniskate(t, a)),
Self::Spiral { k } => Box::new(ex::spiral(k)),
Self::Spiral1D { k } => Box::new(ex::spiral_1d(k)),
Self::SingularPetalRose { k } => Box::new(ex::singular_petal_rose(k)),
Self::Circle => Box::new(ex::circle),
Self::Square => Box::new(ex::square),
Self::Intersect8 => Box::new(ex::intersect_eight),