/// <summary> /// Get the curvature for the current section index in a vector track node. /// </summary> /// <param name="vectorNode">The vector track node</param> /// <param name="tvsi">The tracknode vector section index in the given verctor track node</param> /// <param name="isForward">Is the path in the same direction as the vector track node?</param> private float GetCurvature(TrVectorNode vectorNode, int tvsi, bool isForward) { TrVectorSection tvs = vectorNode.TrVectorSections[tvsi]; TrackSection trackSection = tsectionDat.TrackSections.Get(tvs.SectionIndex); float curvature = 0; if (trackSection != null) // if it is null, something is wrong but we do not want to crash { SectionCurve thisCurve = trackSection.SectionCurve; if (thisCurve != null) { curvature = Math.Sign(thisCurve.Angle) / thisCurve.Radius; if (!isForward) { curvature *= -1; } } } return(curvature); }
//check TDB for long curves and determine each section's position/elev in the curve public SuperElevation(Simulator simulator) { Curves = new List <List <TrVectorSection> >(); Sections = new Dictionary <int, List <TrVectorSection> >(); MaximumAllowedM = 0.07f + simulator.UseSuperElevation / 100f;//max allowed elevation controlled by user setting var SectionList = new List <TrVectorSection>(); foreach (var node in simulator.TDB.TrackDB.TrackNodes) { if (node == null || node.TrJunctionNode != null || node.TrEndNode == true) { continue; } var StartCurve = false; var CurveDir = 0; var Len = 0.0f; SectionList.Clear(); SectionCurve theCurve = null; int i = 0; int count = node.TrVectorNode.TrVectorSections.Length; foreach (var section in node.TrVectorNode.TrVectorSections)//loop all curves { i++; var sec = simulator.TSectionDat.TrackSections.Get(section.SectionIndex); if (sec == null) { continue; } theCurve = sec.SectionCurve; if (sec.SectionSize != null && Math.Abs(sec.SectionSize.Width - simulator.SuperElevationGauge) > 0.2) { continue; //the main route has a gauge different than mine } if (theCurve != null && !theCurve.Angle.AlmostEqual(0f, 0.01f)) //a good curve { if (i == 1 || i == count) { //if (theCurve.Radius * (float)Math.Abs(theCurve.Angle * 0.0174) < 15f) continue; } //do not want the first and last piece of short curved track to be in the curve (they connected to switches) if (StartCurve == false) //we are beginning a curve { StartCurve = true; CurveDir = Math.Sign(sec.SectionCurve.Angle); Len = 0f; } else if (CurveDir != Math.Sign(sec.SectionCurve.Angle)) //we are in curve, but bending different dir { MarkSections(simulator, SectionList, Len); //treat the sections encountered so far, then restart with other dir CurveDir = Math.Sign(sec.SectionCurve.Angle); SectionList.Clear(); Len = 0f; //StartCurve remains true as we are still in a curve } Len += theCurve.Radius * (float)Math.Abs(theCurve.Angle * 0.0174); //0.0174=3.14/180 SectionList.Add(section); } else //meet a straight line { if (StartCurve == true) //we are in a curve, need to finish { MarkSections(simulator, SectionList, Len); Len = 0f; SectionList.Clear(); } StartCurve = false; } } if (StartCurve == true) // we are in a curve after looking at every section { MarkSections(simulator, SectionList, Len); } Len = 0f; StartCurve = false; SectionList.Clear(); } }
public AESectionCurve(SectionCurve sectionCurve) { Radius = sectionCurve.Radius; Angle = sectionCurve.Angle; }