@@ -196,7 +196,6 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
196196 public float CarBodyLengthM ;
197197 public float CarCouplerFaceLengthM ;
198198 public float DerailmentCoefficient ;
199- public float CarAirHoseLengthM ;
200199
201200 public float MaxHandbrakeForceN ;
202201 public float MaxBrakeForceN = 89e3f ;
@@ -251,8 +250,13 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
251250
252251 public float FrontAirHoseHeightAdjustmentM ;
253252 public float RearAirHoseHeightAdjustmentM ;
254- public float FrontAirHoseAngleAdjustmentRad ;
255- public float RearAirHoseAngleAdjustmentRad ;
253+ public float FrontAirHoseYAngleAdjustmentRad ;
254+ public float FrontAirHoseZAngleAdjustmentRad ;
255+ public float RearAirHoseYAngleAdjustmentRad ;
256+ public float RearAirHoseZAngleAdjustmentRad ;
257+
258+ public float CarAirHoseLengthM ;
259+ public float CarAirHoseHorizontalLengthM ;
256260
257261 // Used to calculate Carriage Steam Heat Loss
258262 public const float BogieHeightM = 1.06f ; // Height reduced by 1.06m to allow for bogies, etc
@@ -1322,21 +1326,26 @@ public void UpdateTrainDerailmentRisk()
13221326 }
13231327 }
13241328
1325- // Calculate airhose angles and height
1326- var rearairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CouplerDistanceThisCarM , 2 ) ) ;
1327- var frontairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CouplerDistanceBehindCarM , 2 ) ) ;
1329+ // Calculate airhose angles and height adjustment values for the air hose. Firstly the "rest point" is calculated, and then the real time point.
1330+ // The height and angle variation are then calculated against "at rest" reference point. The air hose angle is used to rotate the hose in two directions, ie the Y and Z axis.
1331+
1332+ // Calculate height adjustment.
1333+ var rearairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CarAirHoseHorizontalLengthM , 2 ) ) ;
1334+ var frontairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CarBehind . CarAirHoseHorizontalLengthM , 2 ) ) ;
13281335
1329- RearAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CouplerDistanceThisCarM + CouplerSlackM / 2.0f ) , 2 ) ) ;
1330- CarBehind . FrontAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CouplerDistanceBehindCarM + CouplerSlackM / 2.0f ) , 2 ) ) ;
1336+ // actual airhose height
1337+ RearAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CarAirHoseHorizontalLengthM + CouplerSlackM ) , 2 ) ) ;
1338+ CarBehind . FrontAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CarBehind . CarAirHoseHorizontalLengthM + CouplerSlackM ) , 2 ) ) ;
13311339
13321340 // refererence adjustment heights to rest position
1341+ // If higher then rest position, then +ve adjustment
13331342 if ( RearAirHoseHeightAdjustmentM >= rearairhoseheightadjustmentreferenceM )
13341343 {
13351344 RearAirHoseHeightAdjustmentM -= rearairhoseheightadjustmentreferenceM ;
13361345 }
1337- else
1346+ else // if lower then the rest position, then -ve adjustment
13381347 {
1339- RearAirHoseHeightAdjustmentM = rearairhoseheightadjustmentreferenceM - RearAirHoseHeightAdjustmentM ;
1348+ RearAirHoseHeightAdjustmentM = ( rearairhoseheightadjustmentreferenceM - RearAirHoseHeightAdjustmentM ) ;
13401349 }
13411350
13421351 if ( CarBehind . FrontAirHoseHeightAdjustmentM >= frontairhoseheightadjustmentreferenceM )
@@ -1348,31 +1357,38 @@ public void UpdateTrainDerailmentRisk()
13481357 CarBehind . FrontAirHoseHeightAdjustmentM = frontairhoseheightadjustmentreferenceM - CarBehind . FrontAirHoseHeightAdjustmentM ;
13491358 }
13501359
1351- var rearairhoseangleadjustmentreferenceRad = ( float ) Math . Cos ( CouplerDistanceThisCarM / CarAirHoseLengthM ) ;
1352- var frontairhoseangleadjustmentreferenceRad = ( float ) Math . Cos ( CouplerDistanceBehindCarM / CarAirHoseLengthM ) ;
1360+ // Calculate angle adjustments
1361+ var rearAirhoseAngleAdjustmentReferenceRad = ( float ) Math . Asin ( CarAirHoseHorizontalLengthM / CarAirHoseLengthM ) ;
1362+ var frontAirhoseAngleAdjustmentReferenceRad = ( float ) Math . Asin ( CarBehind . CarAirHoseHorizontalLengthM / CarAirHoseLengthM ) ;
13531363
1354- RearAirHoseAngleAdjustmentRad = ( float ) Math . Cos ( ( CouplerDistanceThisCarM + CouplerSlackM / 2.0f ) / CarAirHoseLengthM ) ;
1355- CarBehind . FrontAirHoseAngleAdjustmentRad = ( float ) Math . Cos ( ( CouplerDistanceBehindCarM + CouplerSlackM / 2.0f ) / CarAirHoseLengthM ) ;
1364+ RearAirHoseZAngleAdjustmentRad = ( float ) Math . Asin ( ( CarAirHoseHorizontalLengthM + CouplerSlackM ) / CarAirHoseLengthM ) ;
1365+ CarBehind . FrontAirHoseZAngleAdjustmentRad = ( float ) Math . Asin ( ( CarBehind . CarAirHoseHorizontalLengthM + CouplerSlackM ) / CarAirHoseLengthM ) ;
13561366
13571367 // refererence adjustment angles to rest position
1358- if ( RearAirHoseAngleAdjustmentRad >= rearairhoseangleadjustmentreferenceRad )
1368+ if ( RearAirHoseZAngleAdjustmentRad >= rearAirhoseAngleAdjustmentReferenceRad )
13591369 {
1360- RearAirHoseAngleAdjustmentRad -= rearairhoseangleadjustmentreferenceRad ;
1370+ RearAirHoseZAngleAdjustmentRad -= rearAirhoseAngleAdjustmentReferenceRad ;
13611371 }
13621372 else
13631373 {
1364- RearAirHoseAngleAdjustmentRad = rearairhoseangleadjustmentreferenceRad - RearAirHoseAngleAdjustmentRad ;
1374+ RearAirHoseZAngleAdjustmentRad = ( rearAirhoseAngleAdjustmentReferenceRad - RearAirHoseZAngleAdjustmentRad ) ;
13651375 }
13661376
1367- if ( CarBehind . FrontAirHoseAngleAdjustmentRad >= frontairhoseangleadjustmentreferenceRad )
1377+ // The Y axis angle adjustment should be the same as the z axis
1378+ RearAirHoseYAngleAdjustmentRad = RearAirHoseZAngleAdjustmentRad ;
1379+
1380+ if ( CarBehind . FrontAirHoseZAngleAdjustmentRad >= frontAirhoseAngleAdjustmentReferenceRad )
13681381 {
1369- CarBehind . FrontAirHoseAngleAdjustmentRad -= frontairhoseangleadjustmentreferenceRad ;
1382+ CarBehind . FrontAirHoseZAngleAdjustmentRad -= frontAirhoseAngleAdjustmentReferenceRad ;
13701383 }
13711384 else
13721385 {
1373- CarBehind . FrontAirHoseAngleAdjustmentRad = frontairhoseangleadjustmentreferenceRad - CarBehind . FrontAirHoseAngleAdjustmentRad ;
1386+ CarBehind . FrontAirHoseZAngleAdjustmentRad = ( frontAirhoseAngleAdjustmentReferenceRad - CarBehind . FrontAirHoseZAngleAdjustmentRad ) ;
13741387 }
13751388
1389+ // The Y axis angle adjustment should be the same as the z axis
1390+ CarBehind . FrontAirHoseYAngleAdjustmentRad = CarBehind . FrontAirHoseZAngleAdjustmentRad ;
1391+
13761392 }
13771393
13781394 // Train will derail if lateral forces on the train exceed the vertical forces holding the train on the railway track.
@@ -1385,14 +1401,13 @@ public void UpdateTrainDerailmentRisk()
13851401 if ( IsPlayerTrain )
13861402 {
13871403 WagonCouplerAngleDerailRad = Math . Abs ( WagonRearCouplerAngleRad ) ;
1388- var numWheels = WagonNumAxles * 2 ;
1389-
1390- // Trace.TraceInformation("Wagon Values - CarID {0} Axles {1} Bogies {2} Wheels {3}", CarID, WagonNumAxles, WagonNumBogies, numWheels);
1404+ var numAxles = LocoNumDrvAxles + WagonNumAxles ;
1405+ var numWheels = numAxles * 2 ;
13911406
13921407 if ( CurrentCurveRadius != 0 )
13931408 {
13941409 var A = MassKG * GravitationalAccelerationMpS2 / numWheels ;
1395- var B1 = ( MassKG / WagonNumAxles ) * ( float ) Math . Pow ( Math . Abs ( SpeedMpS ) , 2 ) / CurrentCurveRadius ;
1410+ var B1 = ( MassKG / numAxles ) * ( float ) Math . Pow ( Math . Abs ( SpeedMpS ) , 2 ) / CurrentCurveRadius ;
13961411 var B2 = GravitationalAccelerationMpS2 * ( float ) Math . Cos ( SuperElevationAngleRad ) ;
13971412 var B3 = CentreOfGravityM . Y / TrackGaugeM ;
13981413
@@ -1404,7 +1419,7 @@ public void UpdateTrainDerailmentRisk()
14041419 if ( CarAhead != null )
14051420 {
14061421 var AA1 = CarAhead . CouplerForceU * ( float ) Math . Sin ( WagonCouplerAngleDerailRad ) / WagonNumBogies ;
1407- var BB1 = MassKG / WagonNumAxles ;
1422+ var BB1 = MassKG / numAxles ;
14081423 var BB2 = ( float ) Math . Pow ( Math . Abs ( SpeedMpS ) , 2 ) / CurrentCurveRadius ;
14091424 var BB3 = GravitationalAccelerationMpS2 * ( float ) Math . Sin ( SuperElevationAngleRad ) ;
14101425
0 commit comments