Gradient Problem

Let me catch up here. I started a post last night that got too long and I kept falling asleep and gave up.

@BuilderBob
That the gradient might be calculated over a linear distance was my first concern, but that was easily dismissed. That the arc distance calculation might be inaccurate did occur to me, but I was not originally concerned with the actual path length calculation - I just needed it to be long enough to get the required height change at the given (average) gradient - the exact length needed to achieve that didn't matter. That approach also means that any need to project the track onto the horizontal plane to calculate distance would not affect things.
You kind of lost me here. Are you saying the projected horizontal distance doesn't matter? Because it does - in fact it's vital. The height difference between the spline points is directly proportional to the projected horizontal distance. The gradeient is the difference in height between two adjacent spline points divided by the projected horz distance of the arc length between them. Expressed as a ratio or percentage or whatever way you care to do it. If you plot out the track route elevation the vertical axis should be the height and the horizontal axis must then be the horizontal projected distance of the arc length. Unless you follow this convention the gradients will appear distorted.

This is the height map. As you can see, the variations are extreme, and do not seem to be related to any problem smoothing the 2% into the start and end - in fact, the top section where it flattens is quite well smoothed. The bottom portion is a 2% straight through a tunnel and that also smooths into the first section quite well. Perhaps I need more tunnels and bridges. A B C D E F are the spline points, and the numbers next to them are the gradient in that direction.

The map makes it clear that the problem is associated with the spline points, but since the spline points also define the horizontal curvature then that probably doesn't help much.
Based on what I said above I have to ask what is the scale you used for the horizontal axis in the above plot? Also how did you measure the projected horz distance? Or as a practical matter just the arc length of the track since for most rr work the difference between the 2 is very small and could be for most practical cases be ignored. Based on the height difference the arc length of the track for this portion of the route should be about 4.4km.

If you only used points A thru F how did you determine the elevation curve you plotted thru them as the track height can only be measured at the spline points?

In the gradient plot the curve drops to 0 between each spline point. If the grade was layed out correctly I wouldn't expect to see this. How did you measure this as the gradient is only available in the hud displays in Driver and the spline points aren't?

The Trainz track spline does infact act a bit like this as the curvature tend to be larger near the spline points and flattens out as you approach the middle - at least when you have long sections of spline between widely space points. But because of the way the adjacent sections effect the shape I wouldn't expect to see every section doing the same thing.

The Trainz track spline is a bit of a mystery as no one outside N3V apparently knows its exact make up. I have my own ideas based on a lot of testing that it's a type of cubic bezier spline. Normally 4 points are required to define this curve. 2 end points that it passes thru and 2 intermediate points that is doesn't pass thru unless it is a straight line. The 2 intermediate points are used to control the shape of the curve. In Trainz though we only have the end points to control the shape. Since 4 points are required the game must create the other two for us.

Those 2 intermediate don't exist as points in the route, a mathematical location works just as well and in fact another formulation of the spline using end points and end tangents could also conceivably work. The location of the intermediate points though would lie on the extensions of the chords of the adjacent spline sections at some fixed fraction of the chord length from the end points. Hence the end point of the next section can be used to change the shape of the curve but end points further away have no effect on it. Not as fexlible as the normal bezier formulation but we've traded some flexibility for assurance that the curve will be well behaved and suitable for running trains - wiggles not included. At least that's the way I see them and have programmed them in some of the utility programs I use. If you were using TRS06 I could read the trk file and plot out everything I need to figure out what's going on but TS12 I can't work with yet.

Bob Pearson
 
Ice Cubes: America's only renewable natural resource - Secret Recipie (don't tell no one): Add water to tray ... apply coldness.
=========================================================
Trainz are just a bunch of straightened lines, connected by curves ... no big deal !
=========================================================
In order to make a perfect radius curve, with easements, I have to lay track like this for every curve ... Using FT 1000m Straight track, FT 10m Straight track, & FT 10 Degree 200m track.
=======================================================
Curves, and the lead-in/lead-out Curve Easements are made by using:

Example: Laying FT 100m Straight track on the HOG straight aways ...
Laying many assembled segments of: FT 10 Degree 200m Radius track & FT 10m Straight track ...
Sliding the assembled FT tracks so that it lines up with the HOG FT 100m Straight trackstraight aways
Screen_001-34.jpg


Then laying and sliding assembled single track spline points, right over top of the FT Track spline points (using the FT Track as a curve guide)
Screen_002-32.jpg


Then extending, and sliding the last single track curve spline point, to the last spline point circle of four assemled FT 10m Straight Track.
The purpose of this is to create a gentle sweeping Easement ... a longer track curve segment on the lead in/lead out curve radius on the outermost curve segments.
Screen_003-25.jpg


Slide all the single track spline points into place over top of the FT Track spline points.
Screen_004-22.jpg


Then lastly the assembled segments of FT Track can be slid away, and deleted ... or recycled for use, somewhere else on the route.
Screen_005-16.jpg


The last segment of the curve easement should measure 200m Radius, (leading out of the curve) ... or and @ 2000m Radius on the lead out of the curve easement.
I have worked with Mr_Den curve guides ... but the even the smallest 4 degree radius curve guide is a whopping 1432 m radius ... as opposed to most US mainlines are only @ 200 m radius !
The Horseshoe Curve is @ a 609 ft radius ... or @ a 200 m radius curve.
=====================================================
I make my crossovers 200' long, from switch point, to switch point.
=====================================================
All my double overlaping straightened spline points, are formed by using the configuration of a slightly overlapping figure "8" ... which resembles an infinity symbol: " ∞ ".

=====================================================
Getting back to the topic of Gradients ...

Zooming your Surveyor FOV to the maximum setting ... And by looking straight down, from directly above, is the the best way to lay track, by ignoring all the spine point heights, and gradients ...

These gradients can be adjusted much later on, after the curve radius and straight segments are allready in their finished placement.

Most DEM's are frequntly off by as much as 20' in all the x-y-z track positions ... and a track may be errantly shown way down inside a river channel, or a river channel way up on a mountain hillside.

I allmost sink all my track spline points in the terrain on a DEM, and then I measure the gradient ... if it is in excess of 1.75%, I lower the offending spline point, and make a "Cut" in the hillside terrain, by using the "Smooth Spline" tool button.

Laying gradients is an art ... and most gradients are best kept well below 2% ... I will try to explain my own techniques that I use later ... when I get around to a posting a screenshot link.

If one section of track has a 2%, the next section a 3%, the next section a 4% ... add the numerals 2+3+4 = 9 ... and divide 9, by 3 (which gives the average of those numerals).
Apply that 3% grade to the tracks ... sometimes this works to even out rollercoaster up and down trackage.

Screen_001-35.jpg


Screen_002-33.jpg


Screen_003-26.jpg


All the single track spline points are now slid over top of the FT track spline points.
Screen_004-23.jpg


Slide the FT tracks out of the way, delete them, or recycle them for later use in other areas on your route.
Screen_005-17.jpg

The "Tools" I used to make a perfect "S" Curve ... Complete with Easements
 
Last edited:
I have my own ideas based on a lot of testing that it's a type of cubic bezier spline.

Bob Pearson

Getting off topic, but the spline curve is definitely a bezier, though I have never been able to work out exactly what the specifics are. The problem is that a bezier is the exact opposite of a railway curve. I suspect the programing attraction was that a bezier is pretty easy to plot....
 
Let me catch up here. I started a post last night that got too long and I kept falling asleep and gave up.

@BuilderBob You kind of lost me here. Are you saying the projected horizontal distance doesn't matter? Because it does - in fact it's vital. The height difference between the spline points is directly proportional to the projected horizontal distance. The gradeient is the difference in height between two adjacent spline points divided by the projected horz distance of the arc length between them. Expressed as a ratio or percentage or whatever way you care to do it. If you plot out the track route elevation the vertical axis should be the height and the horizontal axis must then be the horizontal projected distance of the arc length. Unless you follow this convention the gradients will appear distorted.

Bob Pearson

What I meant was that the horizontal distance doesn't matter as far as the route is concerned. I had start and end points both with fixed heights, originally as one section. I then reduced the gradient by inserting spline points and lengthening the horizontal distance by moving those points to create my loops. Then I ran from top to bottom, setting the gradient to 2. Then widen the loops and repeat until the top 3 segments could be gently merged into the predetermined end point. This gave me a minimal distance for the nominated gradient. I figured that by having most of the sections the exact same grade I minimized the fluctuations within the section!

Based on what I said above I have to ask what is the scale you used for the horizontal axis in the above plot? Also how did you measure the projected horz distance? Or as a practical matter just the arc length of the track since for most rr work the difference between the 2 is very small and could be for most practical cases be ignored. Based on the height difference the arc length of the track for this portion of the route should be about 4.4km.

Bob Pearson

The horizontal ticks are 100m, giving a full scale length of 4.5km. The projected distance was measured using a 100m consist, and confirmed from the odometer in the HUD.

If you only used points A thru F how did you determine the elevation curve you plotted thru them as the track height can only be measured at the spline points?

Bob Pearson

The ground has been brought up to the track through the full length. Those measurements are actually ground heights at the 100m marks. I spot checked at the spline points to confirm that the ground heights were a consistent measure of the track heights.

In the gradient plot the curve drops to 0 between each spline point. If the grade was layed out correctly I wouldn't expect to see this. How did you measure this as the gradient is only available in the hud displays in Driver and the spline points aren't?

Bob Pearson

It doesn't actually drop to zero - just close to it. The minimums are 0.21, 0.27, 0.39, 0.58, 1.24 and 0.36. Those last two are the last points in their sections - the other are around the middle.

The 100m tick marks and the spline points are all marked so I can see them in Driver.

The Trainz track spline does infact act a bit like this as the curvature tend to be larger near the spline points and flattens out as you approach the middle - at least when you have long sections of spline between widely space points. But because of the way the adjacent sections effect the shape I wouldn't expect to see every section doing the same thing.

The Trainz track spline is a bit of a mystery as no one outside N3V apparently knows its exact make up. I have my own ideas based on a lot of testing that it's a type of cubic bezier spline. Normally 4 points are required to define this curve. 2 end points that it passes thru and 2 intermediate points that is doesn't pass thru unless it is a straight line. The 2 intermediate points are used to control the shape of the curve. In Trainz though we only have the end points to control the shape. Since 4 points are required the game must create the other two for us.

Those 2 intermediate don't exist as points in the route, a mathematical location works just as well and in fact another formulation of the spline using end points and end tangents could also conceivably work. The location of the intermediate points though would lie on the extensions of the chords of the adjacent spline sections at some fixed fraction of the chord length from the end points. Hence the end point of the next section can be used to change the shape of the curve but end points further away have no effect on it. Not as fexlible as the normal bezier formulation but we've traded some flexibility for assurance that the curve will be well behaved and suitable for running trains - wiggles not included. At least that's the way I see them and have programmed them in some of the utility programs I use. If you were using TRS06 I could read the trk file and plot out everything I need to figure out what's going on but TS12 I can't work with yet.

Bob Pearson

I figured it was some form of Bezier, and that meant that there was an arbitrary factor somewhere in calculation of the intermediate points. If there was an additional calculation that limits the rate of change then I could see how the point gradient at one end of a section could be affected by the point gradient at the other end, when the section length was too short to allow for a full transition. If that was the case a 'wave' could propogate through multiple sections. But I believe I have demonstrated that the calculation of the intermediate points is based only on the adjacent section (which is what I would expect anyway) and that there are no other rules that somehow force the calculation to respond to more remote sections. By deleting sections and noting what changes it is possible to show that only adjacent sections affect eachother.

I think your comment "curvature tend to be larger near the spline points and flattens out as you approach the middle" is the clue to the problem, although it doesn't explain the whole behaviour. It's what I suspected from the casual analysis, and seems to be confirmed in the graph. Because of the way I constructed the path, the sections are tightly curved at their ends, with long middle sections with only a slight curve.
 
Gradient Problem Redux

The updated height map is below. A B C D E F are the original spline points. The sections of interest are AB BC and CD. The last two (DE EF)show that it is possible to get a smooth height transition. AB BC and CD are long sections with compound curves and most of their curvature concentrated at the ends of the section.

The blue line is the original gradient and demonstrates the problem. The original sections had a significant over-compensation of the gradient smoothing (in fact, minimal smoothing should have been required) and that compensation was concentrated at the ends of the section. The over-compensation meant that the middles had significantly less gradient than they should have had. The result is a step, not a smooth transition.

The green line is after inserting straight sections of track (200-400m) in the (nearly straight) middle portion of those original sections. This creates two smaller steps where there was originally one. The original spline points are still joins of two compound curves (although shorter than before) and there is still a significant peak in the slope, and a significant decrease in gradient in the middle of those sections. Note that these new peaks are less than the original peaks, presumably because the curvature at the ends of their adjacent sections are less. But the adjacent sections are still compound curves.

The purple line is after inserting additional spline points near the ends of the original sections. That is, dividing the curves at the ends of those sections into two. The long sections therefore have very little curvature at their ends, and the two short sections that meet at the original spline point are now simple curves. This pretty much smooths out the gradient. The long connecting sections are still compound curves, however, and that is (presumably) creating the dip midway between the original spline points.

So the upshot seems to be:
- The gradient tool does not apply the gradient equally along the section even if the adjacent sections have the same gradient. It concentrates the height change at the ends of the section.
- The gradient tool seems to overcompensate when smoothing the gradient along the length of the section, resulting in bumps and hollows that should not be necessary.
- If the section is a compound curve, that exagerates the problem.
- The tighter the curves the greater the problem.
- The longer the section the greater the problem (based on the effect of breaking down the longest sections - the green line).
- The problem might be less when the gradients differ between sections (a guess, based on the fact that I haven't noticed the problem until I tried to create a stretch of track with the exact same gradient in contiguous sections).

 
Back
Top