1
Fork 0
This commit is contained in:
Andy Killorin 2023-11-04 06:32:37 -05:00
parent 109e76e201
commit d221f8640b
Signed by: ank
GPG key ID: B6241CA3B552BCA4
2 changed files with 17 additions and 15 deletions

View file

@ -3,7 +3,7 @@ use std::sync::Mutex;
use nalgebra::Vector3; use nalgebra::Vector3;
use scad::*; use scad::*;
use constants::*; use constants::*;
use selig::Airfoil; use selig::SeligFile;
use selig::Point; use selig::Point;
use std::ops::Range; use std::ops::Range;
mod constants; mod constants;
@ -18,7 +18,7 @@ fn main() {
scad_file.set_detail(50); scad_file.set_detail(50);
// cambered airfoil, used in the wing // cambered airfoil, used in the wing
let wing_airfoil: Airfoil = Airfoil::parse(include_str!("../ag24.dat")); let wing_airfoil: SeligFile = SeligFile::parse(include_str!("../ag24.dat"));
println!("name {}, perim {}", wing_airfoil.get_name(), wing_airfoil.perimiter()); println!("name {}, perim {}", wing_airfoil.get_name(), wing_airfoil.perimiter());
println!("desc {}", wing_airfoil.get_description().clone().unwrap_or("no desc".to_string())); println!("desc {}", wing_airfoil.get_description().clone().unwrap_or("no desc".to_string()));
//println!("span {:?}", points_in_range(wing_airfoil.get_points()[0..80], 0.0..1.0)); //println!("span {:?}", points_in_range(wing_airfoil.get_points()[0..80], 0.0..1.0));
@ -30,7 +30,7 @@ fn main() {
register_part(scad!(Polygon(points))); register_part(scad!(Polygon(points)));
// symetric airfoil, used in the control surfaces // symetric airfoil, used in the control surfaces
let control_airfoil: Airfoil = Airfoil::parse(include_str!("../edgevertical.dat")); let control_airfoil: SeligFile = SeligFile::parse(include_str!("../edgevertical.dat"));
let mut wing_transform = scad!(Translate(vec3(0.0,0.0,0.0))); let mut wing_transform = scad!(Translate(vec3(0.0,0.0,0.0)));
@ -123,7 +123,7 @@ enum SparType {
} }
/// returns a extruded airfoil with the given dimensions /// returns a extruded airfoil with the given dimensions
fn strut(airfoil: &Airfoil, chord: f32, width: f32, spar: &SparType) -> ScadObject { fn strut(airfoil: &SeligFile, chord: f32, width: f32, spar: &SparType) -> ScadObject {
let aerofoil = scad::PolygonParameters::new(airfoil.get_points().clone()); let aerofoil = scad::PolygonParameters::new(airfoil.get_points().clone());
let shape = scad!(Polygon(aerofoil)); let shape = scad!(Polygon(aerofoil));
@ -165,7 +165,7 @@ fn extrude_strut(shape: ScadObject, strut_hole: ScadObject, width: f32, chord: f
rotated rotated
} }
fn topspar_negative(airfoil: &Airfoil, chord: f32, range: Range<f32>) -> ScadObject { fn topspar_negative(airfoil: &SeligFile, chord: f32, range: Range<f32>) -> ScadObject {
let points = airfoil.get_points(); let points = airfoil.get_points();
let points = &points[0.. points.len() / 2]; let points = &points[0.. points.len() / 2];
let perimeter = span_length(points); let perimeter = span_length(points);
@ -217,7 +217,7 @@ fn lerp(a: f32, b:f32, x:f32) -> f32 {
a*(1.0-x) + b*x a*(1.0-x) + b*x
} }
fn wing(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32, spar: SparType) -> ScadObject { fn wing(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, taper: f32, spar: SparType) -> ScadObject {
let mut wing = scad!(Translate(vec3(0.0,0.0,0.0))); let mut wing = scad!(Translate(vec3(0.0,0.0,0.0)));
// struts // struts
@ -239,7 +239,7 @@ fn wing(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32,
wing wing
} }
fn topwing_spar(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32) -> ScadObject { fn topwing_spar(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, taper: f32) -> ScadObject {
let mut wing = scad!(Hull); let mut wing = scad!(Hull);
let mut last_segment : Option<ScadObject> = None; let mut last_segment : Option<ScadObject> = None;
@ -298,13 +298,11 @@ pub fn points_in_range(input: &Vec<Point>, range: Range<f32>) -> Vec<Point> {
match (range.contains(&distance), range.contains(&(distance+span))) { match (range.contains(&distance), range.contains(&(distance+span))) {
(true, true) => { // fully within span (true, true) => { // fully within span
points.push(point.clone()); points.push(point.clone());
println!("in {span}");
}, },
(false, true) => { // entering span (false, true) => { // entering span
let undershoot = distance - range.start; let undershoot = distance - range.start;
let part_out = (span - undershoot) / span; let part_out = (span - undershoot) / span;
points.push(last.lerp(&point, part_out)); points.push(last.lerp(&point, part_out));
println!("enter");
}, },
(true, false) => { // exiting span (true, false) => { // exiting span
let overshoot = range.end - distance; let overshoot = range.end - distance;

View file

@ -3,15 +3,16 @@ use std::ops::Range;
use nalgebra::Vector2; use nalgebra::Vector2;
pub type Point = Vector2<f32>; pub type Point = Vector2<f32>;
pub type Airfoil = Vec<Point>;
pub struct Airfoil { pub struct SeligFile {
name: String, name: String,
description: Option<String>, description: Option<String>,
data: Vec<Point>, data: Airfoil,
} }
impl Airfoil { impl SeligFile {
pub fn parse(file: &str) -> Airfoil { pub fn parse(file: &str) -> SeligFile {
let mut points = Vec::new(); let mut points = Vec::new();
let mut lines = file.lines(); let mut lines = file.lines();
@ -25,14 +26,14 @@ impl Airfoil {
let y = numbers.next().unwrap().parse().unwrap(); let y = numbers.next().unwrap().parse().unwrap();
points.push(Point::new(x,y)) points.push(Point::new(x,y))
} }
Airfoil { SeligFile {
name, name,
description, description,
data: points data: points
} }
} }
pub fn get_points(&self) -> &Vec<Point> { pub fn get_points(&self) -> &Airfoil {
&self.data &self.data
} }
@ -44,6 +45,9 @@ impl Airfoil {
&self.description &self.description
} }
}
impl Airfoil {
pub fn perimiter(&self) -> f32 { pub fn perimiter(&self) -> f32 {
self.span_length(&self.get_points()[..]) self.span_length(&self.get_points()[..])
} }