From a645be80b58599d9e8a7873867592ad80f2cf7fc Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Wed, 27 Dec 2023 09:48:10 +0800 Subject: [PATCH] Revert to use of cos^2 in LiftDrag plugin In response to https://github.com/gazebosim/gz-sim/pull/2189#issuecomment-1869798904 As suggested by @srmainwaring I also renamed cosSweepAngle -> cos2SweepAngle to prevent further confusion. Signed-off-by: Arjo Chakravarty --- src/systems/lift_drag/LiftDrag.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/systems/lift_drag/LiftDrag.cc b/src/systems/lift_drag/LiftDrag.cc index b16766e6a0..bc2afdfdcc 100644 --- a/src/systems/lift_drag/LiftDrag.cc +++ b/src/systems/lift_drag/LiftDrag.cc @@ -328,7 +328,7 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm) spanwiseI.Dot(velI), minRatio, maxRatio); // get cos from trig identity - double cosSweepAngle = sqrt(1.0 - sinSweepAngle * sinSweepAngle); + double cos2SweepAngle = 1.0 - sinSweepAngle * sinSweepAngle; double sweep = std::asin(sinSweepAngle); // truncate sweep to within +/-90 deg @@ -390,7 +390,7 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm) { cl = (this->cla * this->alphaStall + this->claStall * (alpha - this->alphaStall)) * - cosSweepAngle; + cos2SweepAngle; // make sure cl is still great than 0 cl = std::max(0.0, cl); } @@ -398,12 +398,12 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm) { cl = (-this->cla * this->alphaStall + this->claStall * (alpha + this->alphaStall)) - * cosSweepAngle; + * cos2SweepAngle; // make sure cl is still less than 0 cl = std::min(0.0, cl); } else - cl = this->cla * alpha * cosSweepAngle; + cl = this->cla * alpha * cos2SweepAngle; // modify cl per control joint value if (controlJointPosition && !controlJointPosition->Data().empty()) @@ -421,16 +421,16 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm) { cd = (this->cda * this->alphaStall + this->cdaStall * (alpha - this->alphaStall)) - * cosSweepAngle; + * cos2SweepAngle; } else if (alpha < -this->alphaStall) { cd = (-this->cda * this->alphaStall + this->cdaStall * (alpha + this->alphaStall)) - * cosSweepAngle; + * cos2SweepAngle; } else - cd = (this->cda * alpha) * cosSweepAngle; + cd = (this->cda * alpha) * cos2SweepAngle; // make sure drag is positive cd = std::fabs(cd); @@ -444,7 +444,7 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm) { cm = (this->cma * this->alphaStall + this->cmaStall * (alpha - this->alphaStall)) - * cosSweepAngle; + * cos2SweepAngle; // make sure cm is still great than 0 cm = std::max(0.0, cm); } @@ -452,12 +452,12 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm) { cm = (-this->cma * this->alphaStall + this->cmaStall * (alpha + this->alphaStall)) - * cosSweepAngle; + * cos2SweepAngle; // make sure cm is still less than 0 cm = std::min(0.0, cm); } else - cm = this->cma * alpha * cosSweepAngle; + cm = this->cma * alpha * cos2SweepAngle; // Take into account the effect of control surface deflection angle to cm if (controlJointPosition && !controlJointPosition->Data().empty())