@@ -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
@@ -1277,21 +1281,26 @@ public void UpdateTrainDerailmentRisk()
12771281 }
12781282 }
12791283
1280- // Calculate airhose angles and height
1281- var rearairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CouplerDistanceThisCarM , 2 ) ) ;
1282- var frontairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CouplerDistanceBehindCarM , 2 ) ) ;
1284+ // Calculate airhose angles and height adjustment values for the air hose. Firstly the "rest point" is calculated, and then the real time point.
1285+ // 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.
1286+
1287+ // Calculate height adjustment.
1288+ var rearairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CarAirHoseHorizontalLengthM , 2 ) ) ;
1289+ var frontairhoseheightadjustmentreferenceM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( CarBehind . CarAirHoseHorizontalLengthM , 2 ) ) ;
12831290
1284- RearAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CouplerDistanceThisCarM + CouplerSlackM / 2.0f ) , 2 ) ) ;
1285- CarBehind . FrontAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CouplerDistanceBehindCarM + CouplerSlackM / 2.0f ) , 2 ) ) ;
1291+ // actual airhose height
1292+ RearAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CarAirHoseHorizontalLengthM + CouplerSlackM ) , 2 ) ) ;
1293+ CarBehind . FrontAirHoseHeightAdjustmentM = ( float ) Math . Sqrt ( ( float ) Math . Pow ( CarAirHoseLengthM , 2 ) - ( float ) Math . Pow ( ( CarBehind . CarAirHoseHorizontalLengthM + CouplerSlackM ) , 2 ) ) ;
12861294
12871295 // refererence adjustment heights to rest position
1296+ // If higher then rest position, then +ve adjustment
12881297 if ( RearAirHoseHeightAdjustmentM >= rearairhoseheightadjustmentreferenceM )
12891298 {
12901299 RearAirHoseHeightAdjustmentM -= rearairhoseheightadjustmentreferenceM ;
12911300 }
1292- else
1301+ else // if lower then the rest position, then -ve adjustment
12931302 {
1294- RearAirHoseHeightAdjustmentM = rearairhoseheightadjustmentreferenceM - RearAirHoseHeightAdjustmentM ;
1303+ RearAirHoseHeightAdjustmentM = ( rearairhoseheightadjustmentreferenceM - RearAirHoseHeightAdjustmentM ) ;
12951304 }
12961305
12971306 if ( CarBehind . FrontAirHoseHeightAdjustmentM >= frontairhoseheightadjustmentreferenceM )
@@ -1303,31 +1312,38 @@ public void UpdateTrainDerailmentRisk()
13031312 CarBehind . FrontAirHoseHeightAdjustmentM = frontairhoseheightadjustmentreferenceM - CarBehind . FrontAirHoseHeightAdjustmentM ;
13041313 }
13051314
1306- var rearairhoseangleadjustmentreferenceRad = ( float ) Math . Cos ( CouplerDistanceThisCarM / CarAirHoseLengthM ) ;
1307- var frontairhoseangleadjustmentreferenceRad = ( float ) Math . Cos ( CouplerDistanceBehindCarM / CarAirHoseLengthM ) ;
1315+ // Calculate angle adjustments
1316+ var rearairhoseangleadjustmentreferenceRad = ( float ) Math . Asin ( CarAirHoseHorizontalLengthM / CarAirHoseLengthM ) ;
1317+ var frontairhoseangleadjustmentreferenceRad = ( float ) Math . Asin ( CarBehind . CarAirHoseHorizontalLengthM / CarAirHoseLengthM ) ;
13081318
1309- RearAirHoseAngleAdjustmentRad = ( float ) Math . Cos ( ( CouplerDistanceThisCarM + CouplerSlackM / 2.0f ) / CarAirHoseLengthM ) ;
1310- CarBehind . FrontAirHoseAngleAdjustmentRad = ( float ) Math . Cos ( ( CouplerDistanceBehindCarM + CouplerSlackM / 2.0f ) / CarAirHoseLengthM ) ;
1319+ RearAirHoseZAngleAdjustmentRad = ( float ) Math . Asin ( ( CarAirHoseHorizontalLengthM + CouplerSlackM ) / CarAirHoseLengthM ) ;
1320+ CarBehind . FrontAirHoseZAngleAdjustmentRad = ( float ) Math . Asin ( ( CarBehind . CarAirHoseHorizontalLengthM + CouplerSlackM ) / CarAirHoseLengthM ) ;
13111321
13121322 // refererence adjustment angles to rest position
1313- if ( RearAirHoseAngleAdjustmentRad >= rearairhoseangleadjustmentreferenceRad )
1323+ if ( RearAirHoseZAngleAdjustmentRad >= rearairhoseangleadjustmentreferenceRad )
13141324 {
1315- RearAirHoseAngleAdjustmentRad -= rearairhoseangleadjustmentreferenceRad ;
1325+ RearAirHoseZAngleAdjustmentRad -= rearairhoseangleadjustmentreferenceRad ;
13161326 }
13171327 else
13181328 {
1319- RearAirHoseAngleAdjustmentRad = rearairhoseangleadjustmentreferenceRad - RearAirHoseAngleAdjustmentRad ;
1329+ RearAirHoseZAngleAdjustmentRad = ( rearairhoseangleadjustmentreferenceRad - RearAirHoseZAngleAdjustmentRad ) ;
13201330 }
13211331
1322- if ( CarBehind . FrontAirHoseAngleAdjustmentRad >= frontairhoseangleadjustmentreferenceRad )
1332+ // The Y axis angle adjustment should be the same as the z axis
1333+ RearAirHoseYAngleAdjustmentRad = RearAirHoseZAngleAdjustmentRad ;
1334+
1335+ if ( CarBehind . FrontAirHoseZAngleAdjustmentRad >= frontairhoseangleadjustmentreferenceRad )
13231336 {
1324- CarBehind . FrontAirHoseAngleAdjustmentRad -= frontairhoseangleadjustmentreferenceRad ;
1337+ CarBehind . FrontAirHoseZAngleAdjustmentRad -= frontairhoseangleadjustmentreferenceRad ;
13251338 }
13261339 else
13271340 {
1328- CarBehind . FrontAirHoseAngleAdjustmentRad = frontairhoseangleadjustmentreferenceRad - CarBehind . FrontAirHoseAngleAdjustmentRad ;
1341+ CarBehind . FrontAirHoseZAngleAdjustmentRad = ( frontairhoseangleadjustmentreferenceRad - CarBehind . FrontAirHoseZAngleAdjustmentRad ) ;
13291342 }
13301343
1344+ // The Y axis angle adjustment should be the same as the z axis
1345+ CarBehind . FrontAirHoseYAngleAdjustmentRad = CarBehind . FrontAirHoseZAngleAdjustmentRad ;
1346+
13311347 }
13321348
13331349 // Train will derail if lateral forces on the train exceed the vertical forces holding the train on the railway track.
0 commit comments