fix bevel miscutting due to y≠f(x)
the new algorithm is slow for sure but it works fine
This commit is contained in:
parent
160052a23a
commit
1c0dfa51c9
52
src/main.rs
52
src/main.rs
|
|
@ -157,27 +157,16 @@ fn main() {
|
||||||
|
|
||||||
let rack_y_at_x = |x, profile| rack_shape(x - rack_offset * PI, profile);
|
let rack_y_at_x = |x, profile| rack_shape(x - rack_offset * PI, profile);
|
||||||
let inv_cutter_y_at_x = |x| rack_y_at_x(x, &cutter_profile);
|
let inv_cutter_y_at_x = |x| rack_y_at_x(x, &cutter_profile);
|
||||||
let bevel_cutter_y_at_x = |x| {
|
|
||||||
if x < crown_cutter.first().unwrap().x || x > crown_cutter.last().unwrap().x {
|
let bevel_cutter: Vec<_> = crown_cutter
|
||||||
return -cutter_profile.dedendum;
|
.iter()
|
||||||
}
|
.map(|pt| {
|
||||||
let mut i1 = 0;
|
let rel = vec2(r_pitch - pt.y, pt.x);
|
||||||
let mut i2 = crown_cutter.len() - 1;
|
let r = rel.length();
|
||||||
while i2 - i1 > 1 {
|
let phi = rel.to_angle();
|
||||||
let i3 = (i1 + i2) / 2;
|
(r, phi)
|
||||||
if x < crown_cutter[i3].x {
|
})
|
||||||
i2 = i3;
|
.collect();
|
||||||
} else {
|
|
||||||
i1 = i3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let a = crown_cutter[i1];
|
|
||||||
let b = crown_cutter[i2];
|
|
||||||
assert!(a.x <= x);
|
|
||||||
assert!(x <= b.x);
|
|
||||||
let delta = (x - a.x) / (b.x - a.x);
|
|
||||||
a.y + delta * (b.y - a.y)
|
|
||||||
};
|
|
||||||
|
|
||||||
let kr_to_xy = |k, r: f32| {
|
let kr_to_xy = |k, r: f32| {
|
||||||
let u = k as f32 / n_points_per_tooth as f32;
|
let u = k as f32 / n_points_per_tooth as f32;
|
||||||
|
|
@ -198,13 +187,22 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (k, r) in bevel_shape.iter_mut().enumerate() {
|
for (k, r) in bevel_shape.iter_mut().enumerate() {
|
||||||
loop {
|
let u = k as f32 / n_points_per_tooth as f32;
|
||||||
let xy = kr_to_xy(k, *r);
|
let angle =
|
||||||
let cut_y = bevel_cutter_y_at_x(xy.x);
|
2.0 * PI * (((gear_offset + u) / n_teeth as f32 + 0.5).fract_gl() - 0.5);
|
||||||
if cut_y < xy.y {
|
for (&(mut r1, mut phi1), &(mut r2, mut phi2)) in
|
||||||
break;
|
bevel_cutter.iter().zip(&bevel_cutter[1..])
|
||||||
|
{
|
||||||
|
if phi2 < phi1 {
|
||||||
|
(r1, phi1, r2, phi2) = (r2, phi2, r1, phi1);
|
||||||
}
|
}
|
||||||
*r -= 0.01;
|
if angle < phi1 || angle > phi2 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if *r < r1 && *r < r2 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*r = f32::min(r1, r2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user