From b288ca3d9db8bd4835afb74bcf366f27bb205d73 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Sun, 19 Nov 2017 23:33:07 +0100 Subject: [PATCH] YASIM: add struct Chord to Wing.hpp ; add static method calculateMAC to Wing --- src/FDM/YASim/Wing.cpp | 34 +++++++++++++++++++++++----------- src/FDM/YASim/Wing.hpp | 24 +++++++++++++++--------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/FDM/YASim/Wing.cpp b/src/FDM/YASim/Wing.cpp index 30bafe0bf..f83c91c79 100644 --- a/src/FDM/YASim/Wing.cpp +++ b/src/FDM/YASim/Wing.cpp @@ -9,7 +9,7 @@ Wing::Wing(Version *ver, bool mirror, float* base, float chord, float length, float taper, float sweep, float dihedral, float twist) : _version(ver), _mirror(mirror), - _chord(chord), + _rootChordLength(chord), _length(length), _taper(taper), _sweepAngleCenterLine(sweep), @@ -17,7 +17,7 @@ Wing::Wing(Version *ver, bool mirror, float* base, float chord, _twist(twist) { Math::set3(base, _base); - _meanChord = _chord*(_taper+1)*0.5f; + _meanChord = _rootChordLength*(_taper+1)*0.5f; calculateWingCoordinateSystem(); calculateTip(); calculateSpan(); @@ -127,10 +127,22 @@ void Wing::calculateSpan() 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(_sweepAngleCenterLine) * _macRootDistance + _mac/2; + const float commonFactor = _rootChordLength*(0.5+_taper)/(3*_rootChordLength*(1+_taper)); + _mac.length = _rootChordLength-(2*_rootChordLength*(1-_taper)*commonFactor); + _mac.y = _netSpan*commonFactor; + _mac.x = _base[0]-Math::tan(_sweepAngleCenterLine) * _mac.y + _mac.length/2; +} + +Chord Wing::calculateMAC(Chord root, Chord tip) +{ + assert(root.length > 0); + //const float taper = tip.length / root.length; + const float commonFactor = (root.length*0.5+tip.length)/(3*(root.length+tip.length)); + Chord m; + m.length = root.length-(2*(root.length - tip.length)*commonFactor); + m.y = Math::abs(2*(tip.y - root.y))*commonFactor; + m.x = root.x - (root.x - tip.x)*(root.y - m.y)/(root.y - tip.y); + return m; } float Wing::calculateSweepAngleLeadingEdge() @@ -139,7 +151,7 @@ float Wing::calculateSweepAngleLeadingEdge() return 0; } return Math::atan( - (sin(_sweepAngleCenterLine)+(1-_taper)*_chord/(2*_length)) / + (sin(_sweepAngleCenterLine)+(1-_taper)*_rootChordLength/(2*_length)) / cos(_sweepAngleCenterLine) ); } @@ -221,7 +233,7 @@ void Wing::compile() float pos[3]; interp(_base, _tip, frac, pos); - float chord = _chord * (1 - (1-_taper)*frac); + float chord = _rootChordLength * (1 - (1-_taper)*frac); float weight = chord * segWid; float twist = _twist * frac; @@ -354,9 +366,9 @@ void Wing::writeInfoToProptree() _wingN->getNode("wing-area", true)->setFloatValue(_wingspan*_meanChord); _wingN->getNode("aspect-ratio", true)->setFloatValue(_aspectRatio); _wingN->getNode("standard-mean-chord", true)->setFloatValue(_meanChord); - _wingN->getNode("mac", true)->setFloatValue(_mac); - _wingN->getNode("mac-x", true)->setFloatValue(_macX); - _wingN->getNode("mac-y", true)->setFloatValue(_base[1]+_macRootDistance); + _wingN->getNode("mac", true)->setFloatValue(_mac.length); + _wingN->getNode("mac-x", true)->setFloatValue(_mac.x); + _wingN->getNode("mac-y", true)->setFloatValue(_base[1]+_mac.y); float wgt = 0; float dragSum = 0; diff --git a/src/FDM/YASim/Wing.hpp b/src/FDM/YASim/Wing.hpp index 4e64500ca..8b7f10f64 100644 --- a/src/FDM/YASim/Wing.hpp +++ b/src/FDM/YASim/Wing.hpp @@ -19,6 +19,13 @@ struct FlapParams { float aoa {0}; }; +// position and length of a chord line +struct Chord { + float x {0}; + float y {0}; + float length {0}; +}; + enum WingFlaps { WING_FLAP0, WING_FLAP1, @@ -45,7 +52,7 @@ public: // dist. ALONG wing (not span!) float getLength() const { return _length; }; // at base, measured along X axis - float getChord() const { return _chord; }; + float getChord() const { return _rootChordLength; }; // fraction of chord at wing tip, 0..1 float getTaper() const { return _taper; }; // radians @@ -80,9 +87,10 @@ public: float getArea() const { return _wingspan*_meanChord; }; float getAspectRatio() const { return _aspectRatio; }; float getSMC() const { return _meanChord; }; - float getMACLength() const { return _mac; }; // get length of MAC - float getMACx() const { return _macX; }; // get x-coord of MAC leading edge - float getMACy() const { return _base[1]+_macRootDistance; }; // get y-coord of MAC leading edge + Chord getMAC() const { return _mac; }; + float getMACLength() const { return _mac.length; }; // get length of MAC + float getMACx() const { return _mac.x; }; // get x-coord of MAC + float getMACy() const { return _base[1]+_mac.y; }; // get y-coord of MAC int numSurfaces() const { return _surfs.size(); } @@ -110,12 +118,12 @@ private: void calculateTip(); void calculateSpan(); void calculateMAC(); + static Chord calculateMAC(Chord root, Chord tip); float calculateSweepAngleLeadingEdge(); void addSurface(Surface* s, float weight, float twist); void writeInfoToProptree(); - struct SurfRec { Surface * surface; float weight; }; // all surfaces of this wing Vector _surfs; @@ -125,7 +133,7 @@ private: Version * _version; bool _mirror {false}; float _base[3] {0,0,0}; - float _chord {0}; + float _rootChordLength {0}; // length is distance from base to tip, not wing span float _length {0}; float _taper {1}; @@ -138,9 +146,7 @@ private: float _rightOrient[9]; float _tip[3] {0,0,0}; float _meanChord {0}; // std. mean chord - float _mac {0}; // mean aerodynamic chord length - float _macRootDistance {0}; // y-distance of mac from root - float _macX {0}; // x-coordinate of mac (leading edge) + Chord _mac; // mean aerodynamic chord (x,y) leading edge float _netSpan {0}; float _wingspan {0}; float _aspectRatio {1};