YASim Wing: add _aspectRatio and _meanChord.
(an some indent)
This commit is contained in:
parent
a87442c6f3
commit
cb7d2a1bc5
4 changed files with 56 additions and 43 deletions
src/FDM/YASim
|
@ -440,7 +440,7 @@ int Airplane::getSolutionIterations()
|
||||||
return _solutionIterations;
|
return _solutionIterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Airplane::setupState(float aoa, float speed, float gla, State* s)
|
void Airplane::setupState(const float aoa, const float speed, const float gla, State* s)
|
||||||
{
|
{
|
||||||
float cosAoA = Math::cos(aoa);
|
float cosAoA = Math::cos(aoa);
|
||||||
float sinAoA = Math::sin(aoa);
|
float sinAoA = Math::sin(aoa);
|
||||||
|
@ -494,8 +494,10 @@ float Airplane::compileWing(Wing* w)
|
||||||
_wingsN->getNode("base-x", true)->setFloatValue(tip[0]);
|
_wingsN->getNode("base-x", true)->setFloatValue(tip[0]);
|
||||||
_wingsN->getNode("base-y", true)->setFloatValue(tip[1]);
|
_wingsN->getNode("base-y", true)->setFloatValue(tip[1]);
|
||||||
_wingsN->getNode("base-z", true)->setFloatValue(tip[2]);
|
_wingsN->getNode("base-z", true)->setFloatValue(tip[2]);
|
||||||
_wingsN->getNode("wingspan", true)->setFloatValue(w->getWingSpan());
|
_wingsN->getNode("wing-span", true)->setFloatValue(w->getSpan());
|
||||||
_wingsN->getNode("wingarea", true)->setFloatValue(w->getWingArea());
|
_wingsN->getNode("wing-area", true)->setFloatValue(w->getArea());
|
||||||
|
_wingsN->getNode("aspect-ratio", true)->setFloatValue(w->getAspectRatio());
|
||||||
|
_wingsN->getNode("mean-chord", true)->setFloatValue(w->getMAC());
|
||||||
}
|
}
|
||||||
|
|
||||||
float wgt = 0;
|
float wgt = 0;
|
||||||
|
@ -772,8 +774,8 @@ void Airplane::compile()
|
||||||
if(_wing) {
|
if(_wing) {
|
||||||
float gepos[3];
|
float gepos[3];
|
||||||
float gespan = 0;
|
float gespan = 0;
|
||||||
gespan = _wing->getWingSpan();
|
gespan = _wing->getSpan();
|
||||||
_wing->getBase(gepos);
|
_wing->getBase(gepos);
|
||||||
// where does the hard coded factor 0.15 come from?
|
// where does the hard coded factor 0.15 come from?
|
||||||
_model.setGroundEffect(gepos, gespan, 0.15f);
|
_model.setGroundEffect(gepos, gespan, 0.15f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
float getApproachElevator() { return _approachElevator.val; }
|
float getApproachElevator() { return _approachElevator.val; }
|
||||||
const char* getFailureMsg();
|
const char* getFailureMsg();
|
||||||
|
|
||||||
static void setupState(float aoa, float speed, float gla, State* s); // utility
|
static void setupState(const float aoa, const float speed, const float gla, yasim::State* s); // utility
|
||||||
void loadApproachControls();
|
void loadApproachControls();
|
||||||
void loadCruiseControls();
|
void loadCruiseControls();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "Wing.hpp"
|
#include "Wing.hpp"
|
||||||
|
|
||||||
namespace yasim {
|
namespace yasim {
|
||||||
|
static const float RAD2DEG = 57.2957795131;
|
||||||
|
|
||||||
Wing::Wing( Version * version ) :
|
Wing::Wing( Version * version ) :
|
||||||
_version(version)
|
_version(version)
|
||||||
|
@ -38,6 +39,9 @@ Wing::Wing( Version * version ) :
|
||||||
_slatEnd = 0;
|
_slatEnd = 0;
|
||||||
_slatAoA = 0;
|
_slatAoA = 0;
|
||||||
_slatDrag = 0;
|
_slatDrag = 0;
|
||||||
|
_meanChord = 0;
|
||||||
|
_wingspan = 0;
|
||||||
|
_aspectRatio = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wing::~Wing()
|
Wing::~Wing()
|
||||||
|
@ -172,8 +176,8 @@ void Wing::setFlap0Pos(float lval, float rval)
|
||||||
rval = Math::clamp(rval, -1, 1);
|
rval = Math::clamp(rval, -1, 1);
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<_flap0Surfs.size(); i++) {
|
for(i=0; i<_flap0Surfs.size(); i++) {
|
||||||
((Surface*)_flap0Surfs.get(i))->setFlapPos(lval);
|
((Surface*)_flap0Surfs.get(i))->setFlapPos(lval);
|
||||||
if(_mirror) ((Surface*)_flap0Surfs.get(++i))->setFlapPos(rval);
|
if(_mirror) ((Surface*)_flap0Surfs.get(++i))->setFlapPos(rval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +187,6 @@ void Wing::setFlap0Effectiveness(float lval)
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<_flap0Surfs.size(); i++) {
|
for(i=0; i<_flap0Surfs.size(); i++) {
|
||||||
((Surface*)_flap0Surfs.get(i))->setFlapEffectiveness(lval);
|
((Surface*)_flap0Surfs.get(i))->setFlapEffectiveness(lval);
|
||||||
// if(_mirror) ((Surface*)_flap0Surfs.get(++i))->setFlapEffectiveness(rval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +196,8 @@ void Wing::setFlap1Pos(float lval, float rval)
|
||||||
rval = Math::clamp(rval, -1, 1);
|
rval = Math::clamp(rval, -1, 1);
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<_flap1Surfs.size(); i++) {
|
for(i=0; i<_flap1Surfs.size(); i++) {
|
||||||
((Surface*)_flap1Surfs.get(i))->setFlapPos(lval);
|
((Surface*)_flap1Surfs.get(i))->setFlapPos(lval);
|
||||||
if(_mirror) ((Surface*)_flap1Surfs.get(++i))->setFlapPos(rval);
|
if(_mirror) ((Surface*)_flap1Surfs.get(++i))->setFlapPos(rval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +207,6 @@ void Wing::setFlap1Effectiveness(float lval)
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<_flap1Surfs.size(); i++) {
|
for(i=0; i<_flap1Surfs.size(); i++) {
|
||||||
((Surface*)_flap1Surfs.get(i))->setFlapEffectiveness(lval);
|
((Surface*)_flap1Surfs.get(i))->setFlapEffectiveness(lval);
|
||||||
// if(_mirror) ((Surface*)_flap1Surfs.get(++i))->setFlap(rval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,8 +216,8 @@ void Wing::setSpoilerPos(float lval, float rval)
|
||||||
rval = Math::clamp(rval, 0, 1);
|
rval = Math::clamp(rval, 0, 1);
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<_spoilerSurfs.size(); i++) {
|
for(i=0; i<_spoilerSurfs.size(); i++) {
|
||||||
((Surface*)_spoilerSurfs.get(i))->setSpoilerPos(lval);
|
((Surface*)_spoilerSurfs.get(i))->setSpoilerPos(lval);
|
||||||
if(_mirror) ((Surface*)_spoilerSurfs.get(++i))->setSpoilerPos(rval);
|
if(_mirror) ((Surface*)_spoilerSurfs.get(++i))->setSpoilerPos(rval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +226,7 @@ void Wing::setSlatPos(float val)
|
||||||
val = Math::clamp(val, 0, 1);
|
val = Math::clamp(val, 0, 1);
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<_slatSurfs.size(); i++)
|
for(i=0; i<_slatSurfs.size(); i++)
|
||||||
((Surface*)_slatSurfs.get(i))->setSlatPos(val);
|
((Surface*)_slatSurfs.get(i))->setSlatPos(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wing::compile()
|
void Wing::compile()
|
||||||
|
@ -247,17 +249,17 @@ void Wing::compile()
|
||||||
// Sort in increasing order
|
// Sort in increasing order
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<10; i++) {
|
for(i=0; i<10; i++) {
|
||||||
int minIdx = i;
|
int minIdx = i;
|
||||||
float minVal = bounds[i];
|
float minVal = bounds[i];
|
||||||
int j;
|
int j;
|
||||||
for(j=i+1; j<10; j++) {
|
for(j=i+1; j<10; j++) {
|
||||||
if(bounds[j] < minVal) {
|
if(bounds[j] < minVal) {
|
||||||
minIdx = j;
|
minIdx = j;
|
||||||
minVal = bounds[j];
|
minVal = bounds[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float tmp = bounds[i];
|
float tmp = bounds[i];
|
||||||
bounds[i] = minVal; bounds[minIdx] = tmp;
|
bounds[i] = minVal; bounds[minIdx] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uniqify
|
// Uniqify
|
||||||
|
@ -269,9 +271,6 @@ void Wing::compile()
|
||||||
last = bounds[i];
|
last = bounds[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate a "nominal" segment length equal to an average chord,
|
|
||||||
// normalized to lie within 0-1 over the length of the wing.
|
|
||||||
float segLen = _chord * (0.5f*(_taper+1)) / _length;
|
|
||||||
|
|
||||||
// Generating a unit vector pointing out the left wing.
|
// Generating a unit vector pointing out the left wing.
|
||||||
float left[3];
|
float left[3];
|
||||||
|
@ -286,7 +285,10 @@ void Wing::compile()
|
||||||
Math::set3(left, _tip);
|
Math::set3(left, _tip);
|
||||||
Math::mul3(_length, _tip, _tip);
|
Math::mul3(_length, _tip, _tip);
|
||||||
Math::add3(root, _tip, _tip);
|
Math::add3(root, _tip, _tip);
|
||||||
|
_meanChord = _chord*(_taper+1)*0.5f;
|
||||||
|
// wingspan in y-direction (not for vstab)
|
||||||
_wingspan = Math::abs(2*_tip[1]);
|
_wingspan = Math::abs(2*_tip[1]);
|
||||||
|
_aspectRatio = _wingspan / _meanChord;
|
||||||
|
|
||||||
// The wing's Y axis will be the "left" vector. The Z axis will
|
// 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
|
// be perpendicular to this and the local (!) X axis, because we
|
||||||
|
@ -302,19 +304,23 @@ void Wing::compile()
|
||||||
Math::cross3(y, z, x);
|
Math::cross3(y, z, x);
|
||||||
|
|
||||||
if(_mirror) {
|
if(_mirror) {
|
||||||
// Derive the right side orientation matrix from this one.
|
// Derive the right side orientation matrix from this one.
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<9; i++) rightOrient[i] = orient[i];
|
for(i=0; i<9; i++) rightOrient[i] = orient[i];
|
||||||
|
|
||||||
// Negate all Y coordinates, this gets us a valid basis, but
|
// Negate all Y coordinates, this gets us a valid basis, but
|
||||||
// it's left handed! So...
|
// it's left handed! So...
|
||||||
for(i=1; i<9; i+=3) rightOrient[i] = -rightOrient[i];
|
for(i=1; i<9; i+=3) rightOrient[i] = -rightOrient[i];
|
||||||
|
|
||||||
// Change the direction of the Y axis to get back to a
|
// Change the direction of the Y axis to get back to a
|
||||||
// right-handed system.
|
// right-handed system.
|
||||||
for(i=3; i<6; i++) rightOrient[i] = -rightOrient[i];
|
for(i=3; i<6; i++) rightOrient[i] = -rightOrient[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate a "nominal" segment length equal to an average chord,
|
||||||
|
// normalized to lie within 0-1 over the length of the wing.
|
||||||
|
float segLen = _meanChord / _length;
|
||||||
|
|
||||||
// Now go through each boundary and make segments
|
// Now go through each boundary and make segments
|
||||||
for(i=0; i<(nbounds-1); i++) {
|
for(i=0; i<(nbounds-1); i++) {
|
||||||
float start = bounds[i];
|
float start = bounds[i];
|
||||||
|
@ -354,7 +360,7 @@ void Wing::compile()
|
||||||
_surfs.add(sr);
|
_surfs.add(sr);
|
||||||
|
|
||||||
if(_mirror) {
|
if(_mirror) {
|
||||||
pos[1] = -pos[1];
|
pos[1] = -pos[1];
|
||||||
s = newSurface(pos, rightOrient, chord,
|
s = newSurface(pos, rightOrient, chord,
|
||||||
flap0, flap1, slat, spoiler);
|
flap0, flap1, slat, spoiler);
|
||||||
sr = new SurfRec();
|
sr = new SurfRec();
|
||||||
|
|
|
@ -57,9 +57,12 @@ public:
|
||||||
void compile();
|
void compile();
|
||||||
void getTip(float* tip) { Math::set3(_tip, tip);};
|
void getTip(float* tip) { Math::set3(_tip, tip);};
|
||||||
bool isMirrored() { return _mirror; };
|
bool isMirrored() { return _mirror; };
|
||||||
// Used for ground effect
|
|
||||||
float getWingSpan() { return _wingspan; };
|
// valid only after Wing::compile() was called
|
||||||
float getWingArea() {return 0.5f*_wingspan*_chord*(1+_taper); };
|
float getSpan() { return _wingspan; };
|
||||||
|
float getArea() { return _wingspan*_meanChord; };
|
||||||
|
float getAspectRatio() { return _aspectRatio; };
|
||||||
|
float getMAC() { return _meanChord; };
|
||||||
|
|
||||||
// Query the list of Surface objects
|
// Query the list of Surface objects
|
||||||
int numSurfaces();
|
int numSurfaces();
|
||||||
|
@ -100,7 +103,9 @@ private:
|
||||||
|
|
||||||
// calculated from above
|
// calculated from above
|
||||||
float _tip[3];
|
float _tip[3];
|
||||||
|
float _meanChord;
|
||||||
float _wingspan;
|
float _wingspan;
|
||||||
|
float _aspectRatio;
|
||||||
|
|
||||||
float _stall;
|
float _stall;
|
||||||
float _stallWidth;
|
float _stallWidth;
|
||||||
|
|
Loading…
Add table
Reference in a new issue