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);
|
scad_file.set_detail(50);
|
||||||
|
|
||||||
// cambered airfoil, used in the wing
|
// 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
|
// 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)));
|
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
|
/// returns a extruded airfoil with the given dimensions
|
||||||
fn strut(airfoil: &Airfoil, chord: f32, width: f32) -> ScadObject {
|
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 shape = scad!(Polygon(aerofoil));
|
||||||
|
|
||||||
let extrude = LinExtrudeParams {
|
let extrude = LinExtrudeParams {
|
||||||
|
|
55
src/selig.rs
55
src/selig.rs
|
@ -2,16 +2,47 @@ use nalgebra::Vector2;
|
||||||
|
|
||||||
pub type Point = Vector2<f32>;
|
pub type Point = Vector2<f32>;
|
||||||
|
|
||||||
pub type Airfoil = Vec<Point>;
|
pub struct Airfoil {
|
||||||
|
name: String,
|
||||||
pub fn parse(file: &str) -> Airfoil {
|
data: Vec<Point>,
|
||||||
let mut points = Vec::new();
|
}
|
||||||
|
|
||||||
for line in file.lines().skip(1) {
|
impl Airfoil {
|
||||||
let mut numbers =line.split(" ").filter(|n| !n.trim().is_empty());
|
pub fn parse(file: &str) -> Airfoil {
|
||||||
let x = numbers.next().unwrap().parse().unwrap();
|
let mut points = Vec::new();
|
||||||
let y = numbers.next().unwrap().parse().unwrap();
|
|
||||||
points.push(Point::new(x,y))
|
let mut lines = file.lines();
|
||||||
}
|
let name = lines.next().expect("selig .dat is empty").to_string();
|
||||||
points
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
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