drop old code
This commit is contained in:
parent
feb58afd56
commit
07be8faadc
207
src/main.rs
207
src/main.rs
|
|
@ -1,10 +1,10 @@
|
|||
use std::{f32::consts::PI, time::Duration};
|
||||
|
||||
use flo_draw::{
|
||||
canvas::{Color::Rgba, GraphicsContext, GraphicsPrimitives, Transform2D},
|
||||
create_drawing_window, create_drawing_window_with_events, with_2d_graphics,
|
||||
canvas::{Color::Rgba, GraphicsContext},
|
||||
create_drawing_window_with_events, with_2d_graphics,
|
||||
};
|
||||
use glam::{Affine2, FloatExt, Vec2, vec2};
|
||||
use glam::{FloatExt, Vec2, vec2};
|
||||
|
||||
const fn rad(deg: f32) -> f32 {
|
||||
deg * (PI / 180.0)
|
||||
|
|
@ -15,207 +15,6 @@ const DEDENDUM: f32 = 1.25;
|
|||
const PRESSURE_ANGLE: f32 = rad(20.0);
|
||||
const PITCH: f32 = PI;
|
||||
|
||||
fn draw_rack(gc: &mut impl GraphicsContext) {
|
||||
gc.move_to(-ADDENDUM * PRESSURE_ANGLE.tan(), ADDENDUM);
|
||||
gc.line_to(DEDENDUM * PRESSURE_ANGLE.tan(), -DEDENDUM);
|
||||
gc.line_to(0.5 * PITCH - DEDENDUM * PRESSURE_ANGLE.tan(), -DEDENDUM);
|
||||
gc.line_to(0.5 * PITCH + ADDENDUM * PRESSURE_ANGLE.tan(), ADDENDUM);
|
||||
gc.line_to(PITCH - ADDENDUM * PRESSURE_ANGLE.tan(), ADDENDUM);
|
||||
gc.line_to(PITCH + DEDENDUM * PRESSURE_ANGLE.tan(), -DEDENDUM);
|
||||
gc.stroke();
|
||||
|
||||
gc.stroke_color(Rgba(0.1, 1.0, 0.1, 0.2));
|
||||
|
||||
gc.move_to(-PITCH, 0.0);
|
||||
gc.line_to(PITCH, 0.0);
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
fn cut_involute(gc: &mut impl GraphicsContext, n_teeth: u32) {
|
||||
let tooth_angle = 360.0 / n_teeth as f32;
|
||||
let r = 0.5 * n_teeth as f32;
|
||||
let n = 500;
|
||||
for k in -n..=n {
|
||||
let t = 2.0 * k as f32 / n as f32;
|
||||
gc.push_state();
|
||||
gc.transform(Transform2D::translate(0.0, -r));
|
||||
gc.transform(Transform2D::rotate_degrees(tooth_angle * t));
|
||||
gc.transform(Transform2D::translate(0.0, r));
|
||||
gc.transform(Transform2D::translate(PITCH * t, 0.0));
|
||||
gc.transform(Transform2D::translate(-2.0 * PITCH, 0.0));
|
||||
for _ in -2..2 {
|
||||
gc.move_to(-ADDENDUM * PRESSURE_ANGLE.tan(), ADDENDUM);
|
||||
gc.line_to(DEDENDUM * PRESSURE_ANGLE.tan(), -DEDENDUM);
|
||||
gc.line_to(0.5 * PITCH - DEDENDUM * PRESSURE_ANGLE.tan(), -DEDENDUM);
|
||||
gc.line_to(0.5 * PITCH + ADDENDUM * PRESSURE_ANGLE.tan(), ADDENDUM);
|
||||
gc.line_to(PITCH - ADDENDUM * PRESSURE_ANGLE.tan(), ADDENDUM);
|
||||
gc.line_to(PITCH + DEDENDUM * PRESSURE_ANGLE.tan(), -DEDENDUM);
|
||||
gc.stroke();
|
||||
gc.transform(Transform2D::translate(PITCH, 0.0));
|
||||
}
|
||||
gc.pop_state();
|
||||
}
|
||||
|
||||
gc.stroke_color(Rgba(0.1, 1.0, 0.1, 0.2));
|
||||
|
||||
gc.circle(0.0, -r, r);
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
fn show_involute(gc: &mut impl GraphicsContext, n_teeth: u32) {
|
||||
let tooth_angle = 360.0 / n_teeth as f32;
|
||||
let r = 0.5 * n_teeth as f32;
|
||||
let n = 500;
|
||||
let size = 5.0;
|
||||
for k in -n..=n {
|
||||
let t = 2.0 * k as f32 / n as f32;
|
||||
gc.push_state();
|
||||
gc.transform(Transform2D::translate(0.0, -r));
|
||||
gc.transform(Transform2D::rotate_degrees(tooth_angle * t));
|
||||
gc.transform(Transform2D::translate(0.0, r));
|
||||
gc.transform(Transform2D::translate(PITCH * t, 0.0));
|
||||
|
||||
gc.move_to(-size * PRESSURE_ANGLE.tan(), size);
|
||||
gc.line_to(size * PRESSURE_ANGLE.tan(), -size);
|
||||
gc.stroke();
|
||||
gc.pop_state();
|
||||
}
|
||||
|
||||
gc.stroke_color(Rgba(0.1, 1.0, 0.1, 0.2));
|
||||
|
||||
gc.circle(0.0, -r, r);
|
||||
gc.circle(0.0, -r, r - DEDENDUM);
|
||||
gc.circle(0.0, -r, r + ADDENDUM);
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
fn draw_crown(gc: &mut impl GraphicsContext, n_teeth: u32) {
|
||||
let tooth_angle = rad(360.0 / n_teeth as f32);
|
||||
let r = 0.5 * n_teeth as f32;
|
||||
|
||||
let mut points = Vec::new();
|
||||
let n = 500;
|
||||
for i_point in -n..=n {
|
||||
let t_point = 5.0 * i_point as f32 / n as f32;
|
||||
let x = PITCH * t_point;
|
||||
let angle = f32::atan2(x, r);
|
||||
let tooth = angle / tooth_angle;
|
||||
let vx = PITCH * tooth.fract_gl();
|
||||
|
||||
let tan = PRESSURE_ANGLE.tan();
|
||||
let vy = if vx < DEDENDUM * tan {
|
||||
-vx / tan
|
||||
} else if vx <= 0.5 * PITCH - DEDENDUM * tan {
|
||||
-DEDENDUM
|
||||
} else if vx <= 0.5 * PITCH + ADDENDUM * tan {
|
||||
(vx - 0.5 * PITCH) / tan
|
||||
} else if vx <= PITCH - ADDENDUM * tan {
|
||||
ADDENDUM
|
||||
} else {
|
||||
-(vx - PITCH) / tan
|
||||
};
|
||||
points.push(vec2(x, vy));
|
||||
}
|
||||
gc.move_to(points[0].x, points[0].y);
|
||||
for pt in &points[1..] {
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.stroke();
|
||||
|
||||
gc.stroke_color(Rgba(0.1, 1.0, 0.1, 0.2));
|
||||
|
||||
gc.move_to(-20.0, 0.0);
|
||||
gc.line_to(20.0, 0.0);
|
||||
gc.stroke();
|
||||
|
||||
let n = 4;
|
||||
for k in -n..=n {
|
||||
let angle = tooth_angle * k as f32;
|
||||
let x = r * angle.tan();
|
||||
gc.move_to(x, -1.0);
|
||||
gc.line_to(x, 1.0);
|
||||
gc.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
fn cut_crown(gc: &mut impl GraphicsContext, n_teeth_crown: u32, n_teeth_gear: u32) {
|
||||
let tooth_angle_crown = rad(360.0 / n_teeth_crown as f32);
|
||||
let r_crown = 0.5 * n_teeth_crown as f32;
|
||||
|
||||
let tooth_angle_gear = rad(360.0 / n_teeth_gear as f32);
|
||||
let r_gear = 0.5 * n_teeth_gear as f32;
|
||||
|
||||
let n_subcuts = 200;
|
||||
for i_subcut in -n_subcuts..=n_subcuts {
|
||||
let t_cut = 2.0 * i_subcut as f32 / n_subcuts as f32;
|
||||
|
||||
let rot_gear = t_cut * tooth_angle_gear;
|
||||
let rot_crown = t_cut * tooth_angle_crown;
|
||||
|
||||
let tfm_gear = Affine2::from_translation(vec2(0.0, -r_gear))
|
||||
* Affine2::from_angle_translation(-rot_gear, Vec2::ZERO)
|
||||
* Affine2::from_translation(vec2(0.0, r_gear));
|
||||
|
||||
let mut points = Vec::new();
|
||||
let n_points = 300;
|
||||
for i_point in -n_points..=n_points {
|
||||
let t_point = 2.0 * i_point as f32 / n_points as f32;
|
||||
let x = PITCH * t_point;
|
||||
let angle = f32::atan2(x, r_crown) + rot_crown;
|
||||
let tooth = angle / tooth_angle_crown;
|
||||
let vx = PITCH * tooth.fract_gl();
|
||||
|
||||
let tan = PRESSURE_ANGLE.tan();
|
||||
let vy = if vx < DEDENDUM * tan {
|
||||
-vx / tan
|
||||
} else if vx <= 0.5 * PITCH - DEDENDUM * tan {
|
||||
-DEDENDUM
|
||||
} else if vx <= 0.5 * PITCH + ADDENDUM * tan {
|
||||
(vx - 0.5 * PITCH) / tan
|
||||
} else if vx <= PITCH - ADDENDUM * tan {
|
||||
ADDENDUM
|
||||
} else {
|
||||
-(vx - PITCH) / tan
|
||||
};
|
||||
points.push(tfm_gear.transform_point2(vec2(x, vy)));
|
||||
}
|
||||
gc.move_to(points[0].x, points[0].y);
|
||||
for pt in &points[1..] {
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
gc.stroke_color(Rgba(0.1, 1.0, 0.1, 0.2));
|
||||
|
||||
gc.move_to(-20.0, 0.0);
|
||||
gc.line_to(20.0, 0.0);
|
||||
gc.stroke();
|
||||
|
||||
let n = 4;
|
||||
for k in -n..=n {
|
||||
let angle = tooth_angle_crown * k as f32;
|
||||
let x = r_crown * angle.tan();
|
||||
gc.move_to(x, -1.0);
|
||||
gc.line_to(x, 1.0);
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
gc.circle(0.0, -r_gear, r_gear);
|
||||
gc.circle(0.0, -r_gear, r_gear - DEDENDUM);
|
||||
gc.circle(0.0, -r_gear, r_gear + ADDENDUM);
|
||||
gc.stroke();
|
||||
|
||||
let n = 4;
|
||||
for k in -n..=n {
|
||||
let angle = tooth_angle_gear * k as f32;
|
||||
let (x, y) = angle.sin_cos();
|
||||
gc.move_to(0.0, -r_gear);
|
||||
gc.line_to(x * r_gear, (y - 1.0) * r_gear);
|
||||
gc.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
fn cutter_y_at_x(x: f32) -> f32 {
|
||||
let x = (x / PITCH).fract_gl() * PITCH;
|
||||
let a = DEDENDUM * vec2(PRESSURE_ANGLE.tan(), 1.0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user