From 4584c83d8b49f70d7e80a4669177f4dac634d73f Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Thu, 4 May 2017 14:02:11 +0200 Subject: [PATCH] YASim: split Wing::compile into smaller functions (1). --- src/FDM/YASim/Wing.cpp | 30 ++++++++++++++++++++---------- src/FDM/YASim/Wing.hpp | 4 +++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/FDM/YASim/Wing.cpp b/src/FDM/YASim/Wing.cpp index ee02337f0..dd45fe936 100644 --- a/src/FDM/YASim/Wing.cpp +++ b/src/FDM/YASim/Wing.cpp @@ -111,6 +111,23 @@ void Wing::setSlatPos(float val) ((Surface*)_slatSurfs.get(i))->setSlatPos(val); } +void Wing::calculateSpan() +{ + // wingspan in y-direction (not for vstab) + _wingspan = Math::abs(2*_tip[1]); + _netSpan = Math::abs(2*(_tip[1]-_base[1])); + _aspectRatio = _wingspan / _meanChord; +} + +void Wing::calculateMAC() +{ + // http://www.nasascale.org/p2/wp-content/uploads/mac-calculator.htm + const float commonFactor = _chord*(0.5+_taper)/(3*_chord*(1+_taper)); + _mac = _chord-(2*_chord*(1-_taper)*commonFactor); + _macRootDistance = _netSpan*commonFactor; + _macX = _base[0]-Math::tan(_sweep) * _macRootDistance + _mac/2; +} + void Wing::compile() { // Have we already been compiled? @@ -167,16 +184,9 @@ void Wing::compile() Math::mul3(_length, left, _tip); Math::add3(_base, _tip, _tip); _meanChord = _chord*(_taper+1)*0.5f; - // wingspan in y-direction (not for vstab) - _wingspan = Math::abs(2*_tip[1]); - _aspectRatio = _wingspan / _meanChord; - - _netSpan = Math::abs(2*(_tip[1]-_base[1])); - // http://www.nasascale.org/p2/wp-content/uploads/mac-calculator.htm - const float commonFactor = _chord*(0.5+_taper)/(3*_chord*(1+_taper)); - _mac = _chord-(2*_chord*(1-_taper)*commonFactor); - _macRootDistance = _netSpan*commonFactor; - _macX = _base[0]-Math::tan(_sweep) * _macRootDistance + _mac/2; + + calculateSpan(); + calculateMAC(); // The wing's Y axis will be the "left" vector. The Z axis will // be perpendicular to this and the local (!) X axis, because we diff --git a/src/FDM/YASim/Wing.hpp b/src/FDM/YASim/Wing.hpp index 7df2d811b..debdf43c2 100644 --- a/src/FDM/YASim/Wing.hpp +++ b/src/FDM/YASim/Wing.hpp @@ -97,7 +97,9 @@ private: void interp(const float* v1, const float* v2, const float frac, float* out); Surface* newSurface(float* pos, float* orient, float chord, bool hasFlap0, bool hasFlap1, bool hasSlat, bool hasSpoiler); - + void calculateSpan(); + void calculateMAC(); + struct SurfRec { Surface * surface; float weight; }; Vector _surfs;