switched to airfoil struct
This commit is contained in:
parent
7adb8181a1
commit
4de0171bd3
2 changed files with 47 additions and 15 deletions
|
@ -16,10 +16,11 @@ fn main() {
|
|||
scad_file.set_detail(50);
|
||||
|
||||
// cambered airfoil, used in the wing
|
||||
let wing_airfoil: Airfoil = selig::parse(include_str!("../ag24.dat"));
|
||||
let wing_airfoil: Airfoil = Airfoil::parse(include_str!("../ag24.dat"));
|
||||
println!("perim {}, name {}", wing_airfoil.get_name(), wing_airfoil.perimiter());
|
||||
|
||||
// symetric airfoil, used in the control surfaces
|
||||
let control_airfoil: Airfoil = selig::parse(include_str!("../edgevertical.dat"));
|
||||
let control_airfoil: Airfoil = Airfoil::parse(include_str!("../edgevertical.dat"));
|
||||
|
||||
let mut wing_transform = scad!(Translate(vec3(0.0,0.0,0.0)));
|
||||
|
||||
|
@ -86,7 +87,7 @@ fn main() {
|
|||
|
||||
/// returns a extruded airfoil with the given dimensions
|
||||
fn strut(airfoil: &Airfoil, chord: f32, width: f32) -> ScadObject {
|
||||
let aerofoil = scad::PolygonParameters::new(airfoil.clone());
|
||||
let aerofoil = scad::PolygonParameters::new(airfoil.get_points().clone());
|
||||
let shape = scad!(Polygon(aerofoil));
|
||||
|
||||
let extrude = LinExtrudeParams {
|
||||
|
|
39
src/selig.rs
39
src/selig.rs
|
@ -2,16 +2,47 @@ use nalgebra::Vector2;
|
|||
|
||||
pub type Point = Vector2<f32>;
|
||||
|
||||
pub type Airfoil = Vec<Point>;
|
||||
pub struct Airfoil {
|
||||
name: String,
|
||||
data: Vec<Point>,
|
||||
}
|
||||
|
||||
pub fn parse(file: &str) -> Airfoil {
|
||||
impl Airfoil {
|
||||
pub fn parse(file: &str) -> Airfoil {
|
||||
let mut points = Vec::new();
|
||||
|
||||
for line in file.lines().skip(1) {
|
||||
let mut lines = file.lines();
|
||||
let name = lines.next().expect("selig .dat is empty").to_string();
|
||||
|
||||
for line in lines {
|
||||
let mut numbers =line.split(" ").filter(|n| !n.trim().is_empty());
|
||||
let x = numbers.next().unwrap().parse().unwrap();
|
||||
let y = numbers.next().unwrap().parse().unwrap();
|
||||
points.push(Point::new(x,y))
|
||||
}
|
||||
points
|
||||
Airfoil {
|
||||
name,
|
||||
data: points
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_points(&self) -> &Vec<Point> {
|
||||
&self.data
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn perimiter(&self) -> f32 {
|
||||
let mut last_point: Option<Point> = None;
|
||||
let mut distance: f32 = 0.0;
|
||||
for point in self.get_points() {
|
||||
if let Some(last) = last_point {
|
||||
distance += (last - point).magnitude();
|
||||
}
|
||||
last_point = Some(point.clone());
|
||||
}
|
||||
distance
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue