+Spiral1D

This commit is contained in:
Alain Zscheile 2023-12-11 11:30:55 +01:00
parent bb63d86a8c
commit 0a720971ba
2 changed files with 25 additions and 11 deletions

View file

@ -12,7 +12,7 @@ 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]
[-TAU * ttsin, TAU * ttcos]
}
pub fn ellipse(a: f64, b: f64) -> impl Fn(f64) -> [f64; 2] {
@ -50,11 +50,7 @@ pub fn intersect_8pp(t: f64) -> [f64; 2] {
[newx, x8p[1]]
} else if (t < 0.0625) || (t >= 0.9375) {
// /
let tx = sqrt2_16 * if afterh {
t - 1.0
} else {
t
};
let tx = sqrt2_16 * if afterh { t - 1.0 } else { t };
[tx, -tx]
} else {
// \
@ -107,8 +103,8 @@ pub fn cassini_oval(a: f64, c: f64) -> impl Fn(f64) -> [f64; 2] {
let (ttsin, ttcos) = tt2pi.sin_cos();
let denom = c2 + a2 * ttsin * ttsin;
[
(c2 * cahyp * ttcos) / denom,
(cahyp * ttsin * (c4 - a4 * ttsin * ttsin).sqrt()) / denom,
(c2 * cahyp * ttcos) / denom,
(cahyp * ttsin * (c4 - a4 * ttsin * ttsin).sqrt()) / denom,
]
}
}
@ -121,7 +117,10 @@ pub fn cassini_wobbly(a: f64, c: f64, wob: u32) -> impl Fn(f64) -> [f64; 2] {
let ttx2pi = t * wobx;
let (ttxsin, ttxcos) = (ttx2pi).sin_cos();
let cas = cassini(t);
[ttxcos.mul_add(wobinv, cas[0]), ttxsin.mul_add(wobinv, cas[1])]
[
ttxcos.mul_add(wobinv, cas[0]),
ttxsin.mul_add(wobinv, cas[1]),
]
}
}
@ -148,3 +147,12 @@ pub fn spiral(k: u32) -> impl Fn(f64) -> [f64; 2] {
[ttcos * ttxcos, ttcos * ttxsin]
}
}
pub fn spiral_1d(k: u32) -> impl Fn(f64) -> [f64; 2] {
let x2pi = (k as f64) * core::f64::consts::TAU;
move |t: f64| {
let ttcos = (t * core::f64::consts::TAU).cos();
let ttxsin = (t * x2pi).sin();
[ttcos, ttxsin]
}
}

View file

@ -18,6 +18,7 @@ pub enum SelectExample {
Lemniskate { a: f64 },
Spiral { k: u32 },
Spiral1D { k: u32 },
Circle,
Intersect8,
@ -44,7 +45,11 @@ impl SelectExample {
Self::Lemniskate { a } => {
*a += l;
}
Self::Spiral { .. } | Self::Circle | Self::Intersect8 | Self::Intersect8pp => {
Self::Spiral { .. }
| Self::Spiral1D { .. }
| Self::Circle
| Self::Intersect8
| Self::Intersect8pp => {
panic!("offsetting not supported for this example")
}
}
@ -58,10 +63,11 @@ impl SelectExample {
Self::CassiniAstroidTsq { ca, cc, aa } => {
let x = ex::cassini_astroid(ca, cc, aa);
Box::new(move |t: f64| x(t * t))
},
}
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::Spiral1D { k } => Box::new(ex::spiral_1d(k)),
Self::Circle => Box::new(ex::circle),
Self::Intersect8 => Box::new(ex::intersect_eight),
Self::Intersect8pp => Box::new(ex::intersect_8pp),