//Retreives an "apparent" diameter from a DragCube private float GetApparentDiameter(DragCube cube) { float area = 0; for (int i = 0; i < 6; i++) { area += cube.Area[i] * cube.Drag[i] * PhysicsGlobals.DragCurveValue((Vector3.Dot(Vector3.up, DragCubeList.GetFaceDirection((DragCube.DragFace)i)) + 1f) * 0.5f, 0); } return((float)(Math.Max(Math.Round(Math.Sqrt((area * PhysicsGlobals.DragCubeMultiplier * PhysicsGlobals.DragMultiplier) / Math.PI) * 2d, 1, MidpointRounding.AwayFromZero), 0.1))); }
//Retreives an "apparent" diameter from a DragCube private static float GetApparentDiameter(DragCube cube) { float area = 0; for (int i = 0; i < 6; i++) { // TODO 1.2: according to API docs this method should have only 2 arguments but it has 3 area += cube.Area[i] * cube.Drag[i] * PhysicsGlobals.DragCurveValue(PhysicsGlobals.SurfaceCurves, (Vector3.Dot(Vector3.up, DragCubeList.GetFaceDirection((DragCube.DragFace)i)) + 1) * 0.5f, 0); } return((float)Math.Max(Math.Round(Math.Sqrt((area * 0.1f * PhysicsGlobals.DragMultiplier) / Math.PI) * 2, 1, MidpointRounding.AwayFromZero), 0.1)); }
public DragCubeList.CubeData AddSurfaceDragDirection(Vector3 direction, float machNumber) { part.DragCubes.SetDrag(direction, machNumber); //var liftCurves = GetPrivate<PhysicsGlobals.LiftingSurfaceCurve>("liftCurves", part.DragCubes); var liftCurves = part.DragCubes.BodyLiftCurve; float num = 0; DragCubeList.CubeData result = default(DragCubeList.CubeData); result.dragVector = direction; for (int i = 0; i < 6; i++) { Vector3 faceDirection = DragCubeList.GetFaceDirection((DragCube.DragFace)i); float num2 = Vector3.Dot(direction, faceDirection); float dotNormalized = (num2 + 1) * 0.5f; float num3 = PhysicsGlobals.DragCurveValue(PhysicsGlobals.SurfaceCurves, dotNormalized, machNumber); float num4 = this.areaOccluded [i] * num3; float num5 = this.weightedDrag [i]; float num6 = num5; if (num6 < 1) { num6 = PhysicsGlobals.DragCurveCd.Evaluate(num6); } result.area += num4; result.areaDrag += num4 * num6; result.crossSectionalArea += this.areaOccluded [i] * Mathf.Clamp01(num2); if (num5 < 0.01) { num5 = 1; } if (num5 < 1) { num5 = 1 / num5; } result.exposedArea += num4 / PhysicsGlobals.DragCurveMultiplier.Evaluate(machNumber) * num5; if (num2 > 0) { num += num2; double num7 = (double)liftCurves.liftCurve.Evaluate(num2); if (!double.IsNaN(num7)) { result.liftForce += -faceDirection * (num2 * this.areaOccluded [i] * this.weightedDrag [i] * (float)num7); } result.depth += num2 * this.weightedDepth [i]; result.dragCoeff += num2 * num6; } } float num8 = 1 / num; result.depth *= num8; result.dragCoeff *= num8; return(result); }
double drag(double s, double h, double v) { if (h > Body.atmosphereDepth) { return(0); } var atm = Body.AtmoParamsAtAltitude(h); var v2 = v * v; var dP = atm.Rho * v2 / 2; var mach = v / atm.Mach1; var d = Cd * PhysicsGlobals.DragCurveValue(PhysicsGlobals.SurfaceCurves, C.DragCurveK, (float)mach) * PhysicsGlobals.DragCurvePseudoReynolds.Evaluate((float)(atm.Rho * Math.Abs(v))); return(dP * d * s); }
public void Update() { Altitude = pos.magnitude - Body.Radius; Atmosphere = Body.atmosphere && Altitude < Body.atmosphereDepth; rel_pos = Body.BodyFrame.WorldToLocal(TrajectoryCalculator.BodyRotationAtdT(Body, Path.UT0 - UT) * pos); srf_vel = vel + Vector3d.Cross(Body.zUpAngularVelocity, pos); HorSrfSpeed = Vector3d.Exclude(rel_pos, srf_vel).magnitude; SrfSpeed = srf_vel.magnitude; if (Atmosphere) { Pressure = Body.GetPressure(Altitude); AtmosphereTemperature = Body.GetTemperature(Altitude); Density = Body.GetDensity(Pressure, AtmosphereTemperature); Mach1 = Body.GetSpeedOfSound(Pressure, Density); var Rho_v = Density * SrfSpeed; DynamicPressure = Rho_v * SrfSpeed / 2; Mach = SrfSpeed / Mach1; SpecificDrag = AtmoSim.Cd * DynamicPressure * PhysicsGlobals.DragCurveValue(PhysicsGlobals.SurfaceCurves, VSL.OnPlanetParams.DragCurveK, (float)Mach) * PhysicsGlobals.DragCurvePseudoReynolds.Evaluate((float)(Rho_v)); var convectiveMachLerp = Math.Pow(UtilMath.Clamp01((Mach - PhysicsGlobals.NewtonianMachTempLerpStartMach) / (PhysicsGlobals.NewtonianMachTempLerpEndMach - PhysicsGlobals.NewtonianMachTempLerpStartMach)), PhysicsGlobals.NewtonianMachTempLerpExponent); ShockTemperature = SrfSpeed * PhysicsGlobals.NewtonianTemperatureFactor; if (convectiveMachLerp > 0.0) { double b = PhysicsGlobals.MachTemperatureScalar * Math.Pow(SrfSpeed, PhysicsGlobals.MachTemperatureVelocityExponent); ShockTemperature = UtilMath.LerpUnclamped(ShockTemperature, b, convectiveMachLerp); } ShockTemperature *= (double)HighLogic.CurrentGame.Parameters.Difficulty.ReentryHeatScale * Body.shockTemperatureMultiplier; ShockTemperature = Math.Max(AtmosphereTemperature, ShockTemperature); //calculate convective coefficient for speed > Mach1; lower speed is not a concern ConvectiveCoefficient = 1E-10 * PhysicsGlobals.MachConvectionFactor; ConvectiveCoefficient *= Density > 1 ? Density : Math.Pow(Density, PhysicsGlobals.MachConvectionDensityExponent); ConvectiveCoefficient *= Math.Pow(SrfSpeed, PhysicsGlobals.MachConvectionVelocityExponent) * Body.convectionMultiplier; } }