diff --git a/src/constants.rs b/src/constants.rs index b882bae..f5aa7dd 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -2,12 +2,12 @@ /// the native unit is mm const IN2MM: f32 = 25.4; -pub const CHORD: f32 = 5.0 * IN2MM; +pub const CHORD: f32 = 7.0 * IN2MM; pub const WING_TAPER: f32 = 0.6; pub const WINGSPAN: f32 = 45.0 * IN2MM; pub const LENGTH: f32 = 30.0*IN2MM; /// strut count in the main wing -pub const STRUTS: usize = 20; +pub const STRUTS: usize = 12; pub const CARDBOARD_WIDTH: f32 = 2.4; /// length of each side of the triangular spar pub const SPAR_SIDE_WIDTH: f32 = 0.75 * IN2MM; @@ -19,6 +19,8 @@ pub const RUDDER_CHORD: f32 = 3.0 *IN2MM; pub const RUDDER_TAPER: f32 = 0.7; pub const RUDDER_STRUTS: usize = 3; pub const ELEVATOR_HEIGHT: f32 = 8.0 *IN2MM; -pub const ELEVATOR_CHORD: f32 = 3.0 *IN2MM; +pub const ELEVATOR_CHORD: f32 = 5.0 *IN2MM; pub const ELEVATOR_TAPER: f32 = 0.7; -pub const ELEVATOR_STRUTS: usize = 3; +pub const ELEVATOR_STRUTS: usize = 4; +pub const STOCK_HEIGHT: f32 = 25.0 *IN2MM; +pub const STOCK_WIDTH: f32 = 36.0 *IN2MM; diff --git a/src/main.rs b/src/main.rs index ff47d31..f820261 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,13 +37,16 @@ fn main() { // struts for port in [true,false] { let mut wing = wing(&wing_airfoil, STRUTS/2, WINGSPAN/2.0, CHORD, CHORD * WING_TAPER, SparType::Top); + let top_spar = topwing_spar(&wing_airfoil, STRUTS/2, WINGSPAN/2.0, CHORD, CHORD * WING_TAPER); wing = scad!(Translate(vec3(0.0, FUSELAGE_GAP,0.0)); wing); + wing.add_child(top_spar); if port { wing = scad!(Mirror(vec3(0.0, 1.0, 0.0)); wing); } wing_transform.add_child(wing); } + // spars // "fuselage" @@ -116,6 +119,10 @@ fn strut(airfoil: &Airfoil, chord: f32, width: f32, spar: &SparType) -> ScadObje } }; + extrude_strut(shape, strut_hole, width, chord) +} + +fn extrude_strut(shape: ScadObject, strut_hole: ScadObject, width: f32, chord: f32) -> ScadObject { let mut strut_shape = scad!(Difference); strut_shape.add_child(shape); strut_shape.add_child(strut_hole); @@ -210,6 +217,52 @@ fn wing(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32, wing } +fn topwing_spar(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32) -> ScadObject { + let mut wing = scad!(Translate(vec3(0.0,0.0,0.0))); + + let mut last_segment : Option = None; + let mut pre_vis = scad!(Union); + + // struts + for strut_idx in 0..struts + 1 { + + let gap = length/struts as f32; + + let chord = lerp(chord, taper, strut_idx as f32 / struts as f32); + + let spacing = strut_idx as f32 * gap; + + let shape = topspar_negative(&aerofoil, chord, 0.1..0.6); + let extruded = extrude_strut(shape.clone(), scad!(Union), CARDBOARD_WIDTH, chord); + + let mut transform = scad!(Translate(vec3(0.0, spacing ,0.0))); + transform.add_child(extruded); + + + // in betweens + if let Some(last) = last_segment { + let mut hull = scad!(Hull); + hull.add_child(last); + hull.add_child(shape.clone()); + + let unit: Vector3 = Vector3::new(1.0, 1.0, 1.0); + hull = scad!(Scale(unit * chord); hull); + + hull = scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)); hull); + + transform.add_child(hull); + } + + pre_vis.add_child(transform); + + last_segment = Some(shape); + } + + wing.add_child(pre_vis); + + wing +} + pub fn points_in_range(input: &Vec, range: Range) -> Vec { let mut last_point: Option = None; let mut distance: f32 = 0.0;