~raph/bezoid

7f05cc107e48722333c8fce70764cc32401f3a9b — Raph Levien 1 year, 6 months ago 91d6c52
Rough calibration

This the first cut of forward mapping of raw params to corresponding
bezier params. It may not be perfect but is probably close enough.
1 files changed, 9 insertions(+), 3 deletions(-)

M src/bezoid.rs
M src/bezoid.rs => src/bezoid.rs +9 -3
@@ 8,6 8,7 @@ pub struct CurveResult {
    pub pts: Vec<Point>,
    pub th0: f64,
    pub th1: f64,
    pub chord: f64,
}

const N: usize = 1000;


@@ 78,18 79,23 @@ pub fn integrate_curve(thetas: &[f64]) -> CurveResult {
        *p = a * *p;
    }
    let th_chord = p.to_vec2().atan2();
    let chord = p.to_vec2().hypot();
    let th0 = th_chord - thetas[0];
    let th1 = thetas[n - 1] - th_chord;
    CurveResult { pts, th0, th1 }
    CurveResult { pts, th0, th1, chord }
}

impl CurveResult {
    pub fn infer_bezier(&self, data: &AppData) -> CubicBez {
        let len0 = (2.0 - data.bias0) / 3.0;
        fn arm_len(bias: f64, chord: f64) -> f64 {
            // This is a bit ad hoc but seems to basically work.
            (2.0 - bias).powf(0.35) / (3.0 * chord.powf(1.4))
        }
        let len0 = arm_len(data.bias0, self.chord);
        let p0 = Point::ORIGIN;
        let p1 = p0 + len0 * Vec2::from_angle(self.th0);
        let p3 = Point::new(1.0, 0.0);
        let len1 = (2.0 - data.bias1) / 3.0;
        let len1 = arm_len(data.bias1, self.chord);
        let p2 = p3 - len1 * Vec2::from_angle(-self.th1);
        CubicBez::new(p0, p1, p2, p3)
    }