1
0
Fork 0

YASim: split Wing::compile into smaller functions (2).

This commit is contained in:
Henning Stahlke 2017-05-04 14:06:52 +02:00
parent 4584c83d8b
commit 614f05bb39
2 changed files with 45 additions and 42 deletions

View file

@ -111,6 +111,43 @@ void Wing::setSlatPos(float val)
((Surface*)_slatSurfs.get(i))->setSlatPos(val); ((Surface*)_slatSurfs.get(i))->setSlatPos(val);
} }
void Wing::calculateWingCoordinateSystem() {
// prepare wing coordinate system, ignoring incidence and twist for now
// (tail incidence is varied by the solver)
// Generating a unit vector pointing out the left wing.
float left[3];
left[0] = -Math::tan(_sweep);
left[1] = Math::cos(_dihedral);
left[2] = Math::sin(_dihedral);
Math::unit3(left, left);
// 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
// want motion along the local X axis to be zero AoA (i.e. in the
// wing's XY plane) by definition. Then the local X coordinate is
// just Y cross Z.
float *x = _orient, *y = _orient+3, *z = _orient+6;
x[0] = 1; x[1] = 0; x[2] = 0;
Math::set3(left, y);
Math::cross3(x, y, z);
Math::unit3(z, z);
Math::cross3(y, z, x);
// Derive the right side orientation matrix from this one.
int i;
for(i=0; i<9; i++) _rightOrient[i] = _orient[i];
// Negate all Y coordinates, this gets us a valid basis, but
// it's left handed! So...
for(i=1; i<9; i+=3) _rightOrient[i] = -_rightOrient[i];
// Change the direction of the Y axis to get back to a
// right-handed system.
for(i=3; i<6; i++) _rightOrient[i] = -_rightOrient[i];
}
void Wing::calculateTip() {
float *y = _orient+3;
Math::mul3(_length, y, _tip);
Math::add3(_base, _tip, _tip);
}
void Wing::calculateSpan() void Wing::calculateSpan()
{ {
// wingspan in y-direction (not for vstab) // wingspan in y-direction (not for vstab)
@ -170,51 +207,13 @@ void Wing::compile()
last = bounds[i]; last = bounds[i];
} }
// prepare wing coordinate system, ignoring incidence and twist for now calculateWingCoordinateSystem();
// (tail incidence is varied by the solver) calculateTip();
// Generating a unit vector pointing out the left wing.
float left[3];
left[0] = -Math::tan(_sweep);
left[1] = Math::cos(_dihedral);
left[2] = Math::sin(_dihedral);
Math::unit3(left, left);
// Calculate coordinates for the root and tip of the wing
Math::mul3(_length, left, _tip);
Math::add3(_base, _tip, _tip);
_meanChord = _chord*(_taper+1)*0.5f; _meanChord = _chord*(_taper+1)*0.5f;
calculateSpan(); calculateSpan();
calculateMAC(); 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
// want motion along the local X axis to be zero AoA (i.e. in the
// wing's XY plane) by definition. Then the local X coordinate is
// just Y cross Z.
float orient[9], rightOrient[9];
float *x = orient, *y = orient+3, *z = orient+6;
x[0] = 1; x[1] = 0; x[2] = 0;
Math::set3(left, y);
Math::cross3(x, y, z);
Math::unit3(z, z);
Math::cross3(y, z, x);
if(_mirror) {
// Derive the right side orientation matrix from this one.
int i;
for(i=0; i<9; i++) rightOrient[i] = orient[i];
// Negate all Y coordinates, this gets us a valid basis, but
// it's left handed! So...
for(i=1; i<9; i+=3) rightOrient[i] = -rightOrient[i];
// Change the direction of the Y axis to get back to a
// right-handed system.
for(i=3; i<6; i++) rightOrient[i] = -rightOrient[i];
}
// Calculate a "nominal" segment length equal to an average chord, // Calculate a "nominal" segment length equal to an average chord,
// normalized to lie within 0-1 over the length of the wing. // normalized to lie within 0-1 over the length of the wing.
float segLen = _meanChord / _length; float segLen = _meanChord / _length;
@ -247,7 +246,7 @@ void Wing::compile()
float chord = _chord * (1 - (1-_taper)*frac); float chord = _chord * (1 - (1-_taper)*frac);
Surface *s = newSurface(pos, orient, chord, Surface *s = newSurface(pos, _orient, chord,
hasFlap0, hasFlap1, hasSlat, hasSpoiler); hasFlap0, hasFlap1, hasSlat, hasSpoiler);
SurfRec *sr = new SurfRec(); SurfRec *sr = new SurfRec();
@ -259,7 +258,7 @@ void Wing::compile()
if(_mirror) { if(_mirror) {
pos[1] = -pos[1]; pos[1] = -pos[1];
s = newSurface(pos, rightOrient, chord, s = newSurface(pos, _rightOrient, chord,
hasFlap0, hasFlap1, hasSlat, hasSpoiler); hasFlap0, hasFlap1, hasSlat, hasSpoiler);
sr = new SurfRec(); sr = new SurfRec();
sr->surface = s; sr->surface = s;

View file

@ -97,6 +97,8 @@ private:
void interp(const float* v1, const float* v2, const float frac, float* out); void interp(const float* v1, const float* v2, const float frac, float* out);
Surface* newSurface(float* pos, float* orient, float chord, Surface* newSurface(float* pos, float* orient, float chord,
bool hasFlap0, bool hasFlap1, bool hasSlat, bool hasSpoiler); bool hasFlap0, bool hasFlap1, bool hasSlat, bool hasSpoiler);
void calculateWingCoordinateSystem();
void calculateTip();
void calculateSpan(); void calculateSpan();
void calculateMAC(); void calculateMAC();
@ -118,6 +120,8 @@ private:
float _dihedral {0}; float _dihedral {0};
// calculated from above // calculated from above
float _orient[9];
float _rightOrient[9];
float _tip[3] {0,0,0}; float _tip[3] {0,0,0};
float _meanChord {0}; // std. mean chord float _meanChord {0}; // std. mean chord
float _mac {0}; // mean aerodynamic chord length float _mac {0}; // mean aerodynamic chord length