@@ -127,11 +127,6 @@ public class MSTSWagon : TrainCar
127
127
float TenderWagonMaxCoalMassKG ;
128
128
float TenderWagonMaxWaterMassKG ;
129
129
130
- // Wind Impacts
131
- float WagonDirectionDeg ;
132
- float WagonResultantWindComponentDeg ;
133
- float WagonWindResultantSpeedMpS ;
134
-
135
130
protected float FrictionC1 ; // MSTS Friction parameters
136
131
protected float FrictionE1 ; // MSTS Friction parameters
137
132
protected float FrictionV2 ; // MSTS Friction parameters
@@ -2870,135 +2865,134 @@ private void UpdateWheelBearingTemperature(float elapsedClockSeconds)
2870
2865
private void UpdateWindForce ( )
2871
2866
{
2872
2867
// Calculate compensation for wind
2873
- // There are two components due to wind -
2868
+ // There are two components due to wind -
2874
2869
// Drag, impact of wind on train, will increase resistance when head on, will decrease resistance when acting as a tailwind.
2875
2870
// Lateral resistance - due to wheel flange being pushed against rail due to side wind.
2876
2871
// Calculation based upon information provided in AREA 1942 Proceedings - https://archive.org/details/proceedingsofann431942amer - pg 56
2877
2872
2878
- if ( ! CarTunnelData . FrontPositionBeyondStartOfTunnel . HasValue && AbsSpeedMpS > 2.2352 ) // Only calculate wind resistance if option selected in options menu, and not in a tunnel, and speed is sufficient for wind effects (>5mph)
2873
+ // Only calculate wind resistance if option selected in options menu, and not in a tunnel, and speed is sufficient for wind effects (>5mph)
2874
+ if ( ! CarTunnelData . FrontPositionBeyondStartOfTunnel . HasValue && AbsSpeedMpS > 2.2352 )
2879
2875
{
2880
-
2881
2876
// Wagon Direction
2882
- float direction = ( float ) Math . Atan2 ( WorldPosition . XNAMatrix . M13 , WorldPosition . XNAMatrix . M11 ) ;
2883
- WagonDirectionDeg = MathHelper . ToDegrees ( ( float ) direction ) ;
2877
+ var directionRad = ( float ) Math . Atan2 ( WorldPosition . XNAMatrix . M13 , WorldPosition . XNAMatrix . M11 ) ;
2878
+ var directionDeg = MathHelper . ToDegrees ( directionRad ) ;
2884
2879
2885
- // If car is flipped, then the car's direction will be reversed by 180 compared to the rest of the train, and thus for calculation purposes only,
2880
+ // If car is flipped, then the car's direction will be reversed by 180 compared to the rest of the train, and thus for calculation purposes only,
2886
2881
// it is necessary to reverse the "assumed" direction of the car back again. This shouldn't impact the visual appearance of the car.
2887
2882
if ( Flipped )
2888
2883
{
2889
- WagonDirectionDeg += 180.0f ; // Reverse direction of car
2890
- if ( WagonDirectionDeg > 360 ) // If this results in an angle greater then 360, then convert it back to an angle between 0 & 360.
2891
- {
2892
- WagonDirectionDeg -= 360 ;
2893
- }
2894
- }
2884
+ // Reverse direction of car
2885
+ directionDeg += 180.0f ;
2886
+
2887
+ // If this results in an angle greater then 360, then convert it back to an angle between 0 & 360.
2888
+ if ( directionDeg > 360 )
2889
+ directionDeg -= 360 ;
2890
+ }
2895
2891
2896
2892
// If a westerly direction (ie -ve) convert to an angle between 0 and 360
2897
- if ( WagonDirectionDeg < 0 )
2898
- WagonDirectionDeg += 360 ;
2893
+ if ( directionDeg < 0 )
2894
+ directionDeg += 360 ;
2899
2895
2900
- float TrainSpeedMpS = Math . Abs ( SpeedMpS ) ;
2901
-
2902
2896
// Find angle between wind and direction of train
2903
- if ( Train . PhysicsWindDirectionDeg > WagonDirectionDeg )
2904
- WagonResultantWindComponentDeg = Train . PhysicsWindDirectionDeg - WagonDirectionDeg ;
2905
- else if ( WagonDirectionDeg > Train . PhysicsWindDirectionDeg )
2906
- WagonResultantWindComponentDeg = WagonDirectionDeg - Train . PhysicsWindDirectionDeg ;
2907
- else
2908
- WagonResultantWindComponentDeg = 0.0f ;
2897
+ var resultantWindComponentDeg = 0.0f ;
2898
+ if ( Train . PhysicsWindDirectionDeg > directionDeg )
2899
+ resultantWindComponentDeg = Train . PhysicsWindDirectionDeg - directionDeg ;
2900
+ else if ( directionDeg > Train . PhysicsWindDirectionDeg )
2901
+ resultantWindComponentDeg = directionDeg - Train . PhysicsWindDirectionDeg ;
2909
2902
2910
2903
// Correct wind direction if it is greater then 360 deg, then correct to a value less then 360
2911
- if ( Math . Abs ( WagonResultantWindComponentDeg ) > 360 )
2912
- WagonResultantWindComponentDeg = WagonResultantWindComponentDeg - 360.0f ;
2904
+ if ( Math . Abs ( resultantWindComponentDeg ) > 360 )
2905
+ resultantWindComponentDeg -= 360.0f ;
2913
2906
2914
2907
// Wind angle should be kept between 0 and 180 the formulas do not cope with angles > 180. If angle > 180, denotes wind of "other" side of train
2915
- if ( WagonResultantWindComponentDeg > 180 )
2916
- WagonResultantWindComponentDeg = 360 - WagonResultantWindComponentDeg ;
2908
+ if ( resultantWindComponentDeg > 180 )
2909
+ resultantWindComponentDeg = 360 - resultantWindComponentDeg ;
2917
2910
2918
- float ResultantWindComponentRad = MathHelper . ToRadians ( WagonResultantWindComponentDeg ) ;
2911
+ var resultantWindComponentRad = MathHelper . ToRadians ( resultantWindComponentDeg ) ;
2919
2912
2920
2913
// Find the resultand wind vector for the combination of wind and train speed
2921
- WagonWindResultantSpeedMpS = ( float ) Math . Sqrt ( TrainSpeedMpS * TrainSpeedMpS + Train . PhysicsWindSpeedMpS * Train . PhysicsWindSpeedMpS + 2.0f * TrainSpeedMpS * Train . PhysicsWindSpeedMpS * ( float ) Math . Cos ( ResultantWindComponentRad ) ) ;
2914
+ var windResultantSpeedMpS = ( float ) Math . Sqrt ( AbsSpeedMpS * AbsSpeedMpS + Train . PhysicsWindSpeedMpS * Train . PhysicsWindSpeedMpS + 2.0f * AbsSpeedMpS * Train . PhysicsWindSpeedMpS * ( float ) Math . Cos ( resultantWindComponentRad ) ) ;
2922
2915
2923
2916
// Calculate Drag Resistance
2924
- // The drag resistance will be the difference between the STILL firction calculated using the standard Davies equation,
2917
+ // The drag resistance will be the difference between the STILL firction calculated using the standard Davies equation,
2925
2918
// and that produced using the wind resultant speed (combination of wind speed and train speed)
2926
- float TempStillDragResistanceForceN = AbsSpeedMpS * AbsSpeedMpS * DavisCNSSpMM ;
2927
- float TempCombinedDragResistanceForceN = WagonWindResultantSpeedMpS * WagonWindResultantSpeedMpS * DavisCNSSpMM ; // R3 of Davis formula taking into account wind
2928
- float WindDragResistanceForceN = 0.0f ;
2919
+ var tempStillDragResistanceForceN = AbsSpeedMpS * AbsSpeedMpS * DavisCNSSpMM ;
2920
+ var tempCombinedDragResistanceForceN = windResultantSpeedMpS * windResultantSpeedMpS * DavisCNSSpMM ; // R3 of Davis formula taking into account wind
2921
+ float windDragResistanceForceN ;
2929
2922
2930
2923
// Find the difference between the Still and combined resistances
2931
2924
// This difference will be added or subtracted from the overall friction force depending upon the estimated wind direction.
2932
- // Wind typically headon to train - increase resistance - +ve differential
2933
- if ( TempCombinedDragResistanceForceN > TempStillDragResistanceForceN )
2925
+ if ( tempCombinedDragResistanceForceN > tempStillDragResistanceForceN )
2934
2926
{
2935
- WindDragResistanceForceN = TempCombinedDragResistanceForceN - TempStillDragResistanceForceN ;
2927
+ // Wind typically headon to train - increase resistance - +ve differential
2928
+ windDragResistanceForceN = tempCombinedDragResistanceForceN - tempStillDragResistanceForceN ;
2936
2929
}
2937
- else // wind typically following train - reduce resistance - -ve differential
2930
+ else
2938
2931
{
2939
- WindDragResistanceForceN = TempStillDragResistanceForceN - TempCombinedDragResistanceForceN ;
2940
- WindDragResistanceForceN *= - 1.0f ; // Convert to negative number to allow subtraction from ForceN
2932
+ // Wind typically following train - reduce resistance - -ve differential
2933
+ windDragResistanceForceN = tempStillDragResistanceForceN - tempCombinedDragResistanceForceN ;
2934
+ windDragResistanceForceN *= - 1.0f ; // Convert to negative number to allow subtraction from ForceN
2941
2935
}
2942
2936
2943
2937
// Calculate Lateral Resistance
2944
2938
2945
2939
// Calculate lateral resistance due to wind
2946
2940
// Resistance is due to the wheel flanges being pushed further onto rails when a cross wind is experienced by a train
2947
- float A = Train . PhysicsWindSpeedMpS / AbsSpeedMpS ;
2948
- float C = ( float ) Math . Sqrt ( ( 1 + ( A * A ) + 2.0f * A * Math . Cos ( ResultantWindComponentRad ) ) ) ;
2949
- float WindConstant = 8.25f ;
2950
- float TrainSpeedMpH = Me . ToMi ( pS . TopH ( AbsSpeedMpS ) ) ;
2951
- float WindSpeedMpH = Me . ToMi ( pS . TopH ( Train . PhysicsWindSpeedMpS ) ) ;
2941
+ var a = Train . PhysicsWindSpeedMpS / AbsSpeedMpS ;
2942
+ var c = ( float ) Math . Sqrt ( ( 1 + ( a * a ) + 2.0f * a * Math . Cos ( resultantWindComponentRad ) ) ) ;
2943
+ var windConstant = 8.25f ;
2944
+ var speedMpH = Me . ToMi ( pS . TopH ( AbsSpeedMpS ) ) ;
2952
2945
2953
- float WagonFrontalAreaFt2 = Me2 . ToFt2 ( WagonFrontalAreaM2 ) ;
2946
+ var wagonFrontalAreaFt2 = Me2 . ToFt2 ( WagonFrontalAreaM2 ) ;
2954
2947
2955
- LateralWindForceN = N . FromLbf ( WindConstant * A * ( float ) Math . Sin ( ResultantWindComponentRad ) * DavisDragConstant * WagonFrontalAreaFt2 * TrainSpeedMpH * TrainSpeedMpH * C ) ;
2948
+ LateralWindForceN = N . FromLbf ( windConstant * a * ( float ) Math . Sin ( resultantWindComponentRad ) * DavisDragConstant * wagonFrontalAreaFt2 * speedMpH * speedMpH * c ) ;
2956
2949
2957
- float LateralWindResistanceForceN = N . FromLbf ( WindConstant * A * ( float ) Math . Sin ( ResultantWindComponentRad ) * DavisDragConstant * WagonFrontalAreaFt2 * TrainSpeedMpH * TrainSpeedMpH * C * Train . WagonCoefficientFriction ) ;
2950
+ var lateralWindResistanceForceN = N . FromLbf ( windConstant * a * ( float ) Math . Sin ( resultantWindComponentRad ) * DavisDragConstant * wagonFrontalAreaFt2 * speedMpH * speedMpH * c * Train . WagonCoefficientFriction ) ;
2958
2951
2959
2952
// if this car is a locomotive, but not the lead one then recalculate the resistance with lower C value as drag will not be as high on trailing locomotives
2960
2953
if ( WagonType == WagonTypes . Engine && Train . LeadLocomotive != this )
2961
2954
{
2962
- LateralWindResistanceForceN *= TrailLocoResistanceFactor ;
2955
+ lateralWindResistanceForceN *= TrailLocoResistanceFactor ;
2963
2956
}
2964
2957
2965
2958
// Test to identify whether a tender is attached to the leading engine, if not then the resistance should also be derated as for the locomotive
2966
- bool IsLeadTender = false ;
2959
+ var isLeadTender = false ;
2967
2960
if ( WagonType == WagonTypes . Tender )
2968
2961
{
2969
- bool PrevCarLead = false ;
2962
+ var prevCarLead = false ;
2970
2963
foreach ( var car in Train . Cars )
2971
2964
{
2972
2965
// If this car is a tender and the previous car is the lead locomotive then set the flag so that resistance will be reduced
2973
- if ( car == this && PrevCarLead )
2966
+ if ( car == this && prevCarLead )
2974
2967
{
2975
- IsLeadTender = true ;
2968
+ isLeadTender = true ;
2976
2969
break ; // If the tender has been identified then break out of the loop, otherwise keep going until whole train is done.
2977
2970
}
2971
+
2978
2972
// Identify whether car is a lead locomotive or not. This is kept for when the next iteration (next car) is checked.
2979
2973
if ( Train . LeadLocomotive == car )
2980
2974
{
2981
- PrevCarLead = true ;
2975
+ prevCarLead = true ;
2982
2976
}
2983
2977
else
2984
2978
{
2985
- PrevCarLead = false ;
2979
+ prevCarLead = false ;
2986
2980
}
2987
2981
}
2988
2982
2989
2983
// If tender is coupled to a trailing locomotive then reduce resistance
2990
- if ( ! IsLeadTender )
2984
+ if ( ! isLeadTender )
2991
2985
{
2992
- LateralWindResistanceForceN *= TrailLocoResistanceFactor ;
2986
+ lateralWindResistanceForceN *= TrailLocoResistanceFactor ;
2993
2987
}
2994
2988
}
2995
- WindForceN = LateralWindResistanceForceN + WindDragResistanceForceN ;
2989
+
2990
+ WindForceN = lateralWindResistanceForceN + windDragResistanceForceN ;
2996
2991
}
2997
2992
else
2998
2993
{
2999
2994
WindForceN = 0.0f ; // Set to zero if wind resistance is not to be calculated
3000
2995
}
3001
-
3002
2996
}
3003
2997
3004
2998
private void UpdateTenderLoad ( )
0 commit comments