//--------------------------------------------------------------------------------- // Torque Slip Angle to Lateral Force Example //--------------------------------------------------------------------------------- #include "TA/Common/Maths.h" #include "TA/Common/Geometry.h" //--------------------------------------------------------------------------------- // An implementation of TA::CarTemplate::FnSlipAngleToLateralForce //--------------------------------------------------------------------------------- float TAC_CALL SlipAngleToLateralForce( float fSlipAngle, float fLongitudalSlipRatio, const SurfaceAttribute& surfaceAttribute) { const float fInitialGradient = 14.0f; const float fEndGradient = -0.1f; const float fEndOffset = 2.0f; const float fSegmentEndA = 0.08f; const float fSegmentEndB = 0.27f; const float fSegmentEndAOut = fInitialGradient * fSegmentEndA; const float fSegmentEndBOut = fEndGradient * fSegmentEndB + fEndOffset; const float fInvSegBLength = 1.0f / (fSegmentEndB - fSegmentEndA); const float fCubicGradA = fInitialGradient * (fSegmentEndB - fSegmentEndA); const float fCubicGradB = fEndGradient * (fSegmentEndB - fSegmentEndA); float fSign = TA::Sign(fSlipAngle); fSlipAngle *= fSign; float fResult; if (fSlipAngle < fSegmentEndA) { // As the slip angle increases from zero // the lateral force increases linearly. fResult = fSign * fInitialGradient * fSlipAngle; } else if (fSlipAngle < fSegmentEndB) { // As the slip angle approaches its optimal level // the increase lateral force slows so a stop // then begins to fall away. // This meens that if the steering wheel // is turned too far at high speed, // the car will understeer. fResult = fSign * TA::Geometry::CubicInterpolate( fSegmentEndAOut, fSegmentEndBOut, fCubicGradA, fCubicGradB, (fSlipAngle - fSegmentEndA) * fInvSegBLength); } else { // As slip angle moves well past its optimal level // lateral force linearily decreases to zero. float fValue = fEndGradient * fSlipAngle + fEndOffset; if (fValue < 0.0f) fValue = 0.0f; fResult = fSign * fValue; } // The amount of turning grip can be easily increased // and degceased by multipliing here with out altering // the position of the peak with respect to fSlipAngles. fResult *= 2.5f; // Reduce lateral force based on how much longitudal force has already been applied. // For hand brake turns and the like. fResult /= (TA::Fabs(fLongitudalSlipRatio) * 8.5f + 1.0f); return fResult; }