YASim bugfix: ground effect did not calculate wingspan correctly;
Variable name clarification; Add Wing::getWingArea, separate Wing::getWingSpan and Wing::getBase.
This commit is contained in:
parent
559dcf4e32
commit
d322ded552
5 changed files with 58 additions and 60 deletions
|
@ -471,25 +471,33 @@ void Airplane::addContactPoint(float* pos)
|
||||||
|
|
||||||
float Airplane::compileWing(Wing* w)
|
float Airplane::compileWing(Wing* w)
|
||||||
{
|
{
|
||||||
|
// Make sure it's initialized. The surfaces will pop out with
|
||||||
|
// total drag coefficients equal to their areas, which is what we
|
||||||
|
// want.
|
||||||
|
w->compile();
|
||||||
|
|
||||||
// The tip of the wing is a contact point
|
// The tip of the wing is a contact point
|
||||||
float tip[3];
|
float tip[3];
|
||||||
|
// need compile() before getTip()!
|
||||||
w->getTip(tip);
|
w->getTip(tip);
|
||||||
addContactPoint(tip);
|
addContactPoint(tip);
|
||||||
if(w->isMirrored()) {
|
if(w->isMirrored()) {
|
||||||
tip[1] *= -1;
|
tip[1] *= -1;
|
||||||
addContactPoint(tip);
|
addContactPoint(tip);
|
||||||
|
tip[1] *= -1; //undo mirror
|
||||||
}
|
}
|
||||||
if (_wingsN != 0) {
|
if (_wingsN != 0) {
|
||||||
_wingsN->getNode("tip-x", true)->setFloatValue(tip[0]);
|
_wingsN->getNode("tip-x", true)->setFloatValue(tip[0]);
|
||||||
_wingsN->getNode("tip-y", true)->setFloatValue(tip[1]);
|
_wingsN->getNode("tip-y", true)->setFloatValue(tip[1]);
|
||||||
_wingsN->getNode("tip-z", true)->setFloatValue(tip[2]);
|
_wingsN->getNode("tip-z", true)->setFloatValue(tip[2]);
|
||||||
|
w->getBase(tip);
|
||||||
|
_wingsN->getNode("base-x", true)->setFloatValue(tip[0]);
|
||||||
|
_wingsN->getNode("base-y", true)->setFloatValue(tip[1]);
|
||||||
|
_wingsN->getNode("base-z", true)->setFloatValue(tip[2]);
|
||||||
|
_wingsN->getNode("wingspan", true)->setFloatValue(w->getWingSpan());
|
||||||
|
_wingsN->getNode("wingarea", true)->setFloatValue(w->getWingArea());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure it's initialized. The surfaces will pop out with
|
|
||||||
// total drag coefficients equal to their areas, which is what we
|
|
||||||
// want.
|
|
||||||
w->compile();
|
|
||||||
|
|
||||||
float wgt = 0;
|
float wgt = 0;
|
||||||
float dragSum = 0;
|
float dragSum = 0;
|
||||||
for(int i=0; i<w->numSurfaces(); i++) {
|
for(int i=0; i<w->numSurfaces(); i++) {
|
||||||
|
@ -764,7 +772,9 @@ void Airplane::compile()
|
||||||
if(_wing) {
|
if(_wing) {
|
||||||
float gepos[3];
|
float gepos[3];
|
||||||
float gespan = 0;
|
float gespan = 0;
|
||||||
gespan = _wing->getGroundEffect(gepos);
|
gespan = _wing->getWingSpan();
|
||||||
|
_wing->getBase(gepos);
|
||||||
|
// where does the hard coded factor 0.15 come from?
|
||||||
_model.setGroundEffect(gepos, gespan, 0.15f);
|
_model.setGroundEffect(gepos, gespan, 0.15f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,9 @@ Model::Model()
|
||||||
_hook = 0;
|
_hook = 0;
|
||||||
_launchbar = 0;
|
_launchbar = 0;
|
||||||
|
|
||||||
_groundEffectSpan = 0;
|
_wingSpan = 0;
|
||||||
_groundEffect = 0;
|
_groundEffect = 0;
|
||||||
for(i=0; i<3; i++) _wingCenter[i] = 0;
|
for(i=0; i<3; i++) _geRefPoint[i] = 0;
|
||||||
|
|
||||||
_global_ground[0] = 0; _global_ground[1] = 0; _global_ground[2] = 1;
|
_global_ground[0] = 0; _global_ground[1] = 0; _global_ground[2] = 1;
|
||||||
_global_ground[3] = -100000;
|
_global_ground[3] = -100000;
|
||||||
|
@ -289,8 +289,8 @@ Ground* Model::getGroundCallback(void)
|
||||||
|
|
||||||
void Model::setGroundEffect(float* pos, float span, float mul)
|
void Model::setGroundEffect(float* pos, float span, float mul)
|
||||||
{
|
{
|
||||||
Math::set3(pos, _wingCenter);
|
Math::set3(pos, _geRefPoint);
|
||||||
_groundEffectSpan = span;
|
_wingSpan = span;
|
||||||
_groundEffect = mul;
|
_groundEffect = mul;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,16 +470,19 @@ void Model::calcForces(State* s)
|
||||||
// Account for ground effect by multiplying the vertical force
|
// Account for ground effect by multiplying the vertical force
|
||||||
// component by an amount linear with the fraction of the wingspan
|
// component by an amount linear with the fraction of the wingspan
|
||||||
// above the ground.
|
// above the ground.
|
||||||
if ((_groundEffectSpan != 0) && (_groundEffect != 0 ))
|
if ((_wingSpan != 0) && (_groundEffect != 0 ))
|
||||||
{
|
{
|
||||||
float dist = ground[3] - Math::dot3(ground, _wingCenter);
|
// distance between ground and wing ref. point
|
||||||
if(dist > 0 && dist < _groundEffectSpan) {
|
float dist = ground[3] - Math::dot3(ground, _geRefPoint);
|
||||||
float fz = Math::dot3(faero, ground);
|
float fz = 0;
|
||||||
fz *= (_groundEffectSpan - dist) / _groundEffectSpan;
|
float geForce[3];
|
||||||
fz *= _groundEffect;
|
if(dist > 0 && dist < _wingSpan) {
|
||||||
Math::mul3(fz, ground, faero);
|
fz = Math::dot3(faero, ground);
|
||||||
_body.addForce(faero);
|
fz *= (_wingSpan - dist) / _wingSpan;
|
||||||
}
|
fz *= _groundEffect;
|
||||||
|
Math::mul3(fz, ground, geForce);
|
||||||
|
_body.addForce(geForce);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the velocity and rotation vectors to local coordinates
|
// Convert the velocity and rotation vectors to local coordinates
|
||||||
|
|
|
@ -96,9 +96,9 @@ private:
|
||||||
Launchbar* _launchbar;
|
Launchbar* _launchbar;
|
||||||
Vector _hitches;
|
Vector _hitches;
|
||||||
|
|
||||||
float _groundEffectSpan;
|
float _wingSpan;
|
||||||
float _groundEffect;
|
float _groundEffect;
|
||||||
float _wingCenter[3];
|
float _geRefPoint[3];
|
||||||
|
|
||||||
Ground* _ground_cb;
|
Ground* _ground_cb;
|
||||||
double _global_ground[4];
|
double _global_ground[4];
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include "Math.hpp"
|
|
||||||
#include "Surface.hpp"
|
#include "Surface.hpp"
|
||||||
#include "Wing.hpp"
|
#include "Wing.hpp"
|
||||||
|
|
||||||
|
@ -228,30 +227,6 @@ void Wing::setSlatPos(float val)
|
||||||
((Surface*)_slatSurfs.get(i))->setSlatPos(val);
|
((Surface*)_slatSurfs.get(i))->setSlatPos(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Wing::getGroundEffect(float* posOut)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for(i=0; i<3; i++) posOut[i] = _base[i];
|
|
||||||
float span = _length * Math::cos(_sweep) * Math::cos(_dihedral);
|
|
||||||
span = 2*(span + Math::abs(_base[2]));
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wing::getTip(float* tip)
|
|
||||||
{
|
|
||||||
tip[0] = -Math::tan(_sweep);
|
|
||||||
tip[1] = Math::cos(_dihedral);
|
|
||||||
tip[2] = Math::sin(_dihedral);
|
|
||||||
Math::unit3(tip, tip);
|
|
||||||
Math::mul3(_length, tip, tip);
|
|
||||||
Math::add3(_base, tip, tip);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wing::isMirrored()
|
|
||||||
{
|
|
||||||
return _mirror;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wing::compile()
|
void Wing::compile()
|
||||||
{
|
{
|
||||||
// Have we already been compiled?
|
// Have we already been compiled?
|
||||||
|
@ -306,12 +281,13 @@ void Wing::compile()
|
||||||
Math::unit3(left, left);
|
Math::unit3(left, left);
|
||||||
|
|
||||||
// Calculate coordinates for the root and tip of the wing
|
// Calculate coordinates for the root and tip of the wing
|
||||||
float root[3], tip[3];
|
float root[3];
|
||||||
Math::set3(_base, root);
|
Math::set3(_base, root);
|
||||||
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);
|
||||||
|
_wingspan = Math::abs(2*_tip[1]);
|
||||||
|
|
||||||
// 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
|
||||||
// want motion along the local X axis to be zero AoA (i.e. in the
|
// want motion along the local X axis to be zero AoA (i.e. in the
|
||||||
|
@ -363,7 +339,7 @@ void Wing::compile()
|
||||||
for(j=0; j<nSegs; j++) {
|
for(j=0; j<nSegs; j++) {
|
||||||
float frac = start + (j+0.5f) * (end-start)/nSegs;
|
float frac = start + (j+0.5f) * (end-start)/nSegs;
|
||||||
float pos[3];
|
float pos[3];
|
||||||
interp(root, tip, frac, pos);
|
interp(root, _tip, frac, pos);
|
||||||
|
|
||||||
float chord = _chord * (1 - (1-_taper)*frac);
|
float chord = _chord * (1 - (1-_taper)*frac);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "Vector.hpp"
|
#include "Vector.hpp"
|
||||||
#include "Version.hpp"
|
#include "Version.hpp"
|
||||||
|
#include "Math.hpp"
|
||||||
|
|
||||||
namespace yasim {
|
namespace yasim {
|
||||||
|
|
||||||
|
@ -24,7 +25,13 @@ public:
|
||||||
void setTaper(float taper); // fraction, 0-1
|
void setTaper(float taper); // fraction, 0-1
|
||||||
void setSweep(float sweep); // radians
|
void setSweep(float sweep); // radians
|
||||||
void setDihedral(float dihedral); // radians, positive is "up"
|
void setDihedral(float dihedral); // radians, positive is "up"
|
||||||
|
void getBase(float* base) { Math::set3(_base, base); };
|
||||||
|
float getLength() { return _length; };
|
||||||
|
float getChord() { return _chord; };
|
||||||
|
float getTaper() { return _taper; };
|
||||||
|
float getSweep() { return _sweep; };
|
||||||
|
float getDihedral() { return _dihedral; };
|
||||||
|
|
||||||
void setStall(float aoa);
|
void setStall(float aoa);
|
||||||
void setStallWidth(float angle);
|
void setStallWidth(float angle);
|
||||||
void setStallPeak(float fraction);
|
void setStallPeak(float fraction);
|
||||||
|
@ -48,13 +55,11 @@ public:
|
||||||
|
|
||||||
// Compile the thing into a bunch of Surface objects
|
// Compile the thing into a bunch of Surface objects
|
||||||
void compile();
|
void compile();
|
||||||
|
void getTip(float* tip) { Math::set3(_tip, tip);};
|
||||||
void getTip(float* tip);
|
bool isMirrored() { return _mirror; };
|
||||||
|
// Used for ground effect
|
||||||
bool isMirrored();
|
float getWingSpan() { return _wingspan; };
|
||||||
|
float getWingArea() {return 0.5f*_wingspan*_chord*(1+_taper); };
|
||||||
// Ground effect information
|
|
||||||
float getGroundEffect(float* posOut);
|
|
||||||
|
|
||||||
// Query the list of Surface objects
|
// Query the list of Surface objects
|
||||||
int numSurfaces();
|
int numSurfaces();
|
||||||
|
@ -92,6 +97,10 @@ private:
|
||||||
float _taper;
|
float _taper;
|
||||||
float _sweep;
|
float _sweep;
|
||||||
float _dihedral;
|
float _dihedral;
|
||||||
|
|
||||||
|
// calculated from above
|
||||||
|
float _tip[3];
|
||||||
|
float _wingspan;
|
||||||
|
|
||||||
float _stall;
|
float _stall;
|
||||||
float _stallWidth;
|
float _stallWidth;
|
||||||
|
|
Loading…
Reference in a new issue