0

I am actually a programmer, not hugely expert in math, trying to draw smooth curves between points. I was wondering if any one knows the curve equation that is typically used in roads and railways to connect two different altitudes whilst keeping a smooth gradient between the two...

This is a visual of what i mean:

enter image description here

As you can guess the top one is unacceptable for a road or train as its too angular.

Poor quality drawing i admit, but i am wondering what kinda equation would generate a curve shown in the bottom of the picture when you know two points (x,y,z) and (x',y',z') ?

Théophile
  • 24,627
WDUK
  • 480
  • Can you describe your problem a little more clearly? Which curve is the problem curve? The bottom green one? The top one? I'm missing details. Most generally, when a curve is fitted to several data points, one usually uses a polynomial fit or a spline curve. Read here. – Mnifldz Apr 08 '20 at 03:57
  • The general name for curves like these is sigmoid function (https://en.wikipedia.org/wiki/Sigmoid_function). – BHT Apr 08 '20 at 04:00
  • @EthanMacBrough had a quick fiddle with it, is it possible to get sigmoid function normalized from (-1,-1) to (1,1) though ? See here: https://www.desmos.com/calculator/7jnlhlqv8m is it not possible to get it precise? – WDUK Apr 08 '20 at 04:17
  • @WDUK the standard sigmoid functions typically go from $(-1,0)$ to $(1,1)$, so all you need to do is replace $f(x)$ with $2f(x)-1$. – BHT Apr 08 '20 at 04:27

2 Answers2

1

For roads and railways in particular, the important principle is to design a track whose curvature has no sudden changes; for example, you don't want to just attach a quarter-circle to a straight segment (like you see in some wooden toys, for example).

Here's the relevant Wikipedia article.


Here's an example (13.3, #60) from James Stewart's Calculus:

Let's consider the problem of designing a railroad track to make a smooth transition between sections of straight track. Existing track along the negative x-axis is to be joined smoothly to a track along the line $y=1$ for $x\geq1$.

(a) Find a polynomial $P=P(x)$ of degree $5$ such that the function defined by is continuous and has continuous slope and continuous curvature.

The idea is to use the curvature formula for plane curves $$\kappa(x) = \frac{|f''(x)|}{[1+(f'(x))^2]^{3/2}}.$$

Now, with $P(x) = a_5x^5 + a_4x^4 + \cdots + a_0$, you have six unknowns. There are six things that need to match up: the position of each endpoint, the first derivative at each endpoint, and the curvature at each endpoint.

This will give you a system of six equations; solving for the $a_i$, you'll get $P(x)=6a^5-15a^4+10a^3$. (Try graphing this to confirm that it makes a nice transition, or transfer curve.)

Théophile
  • 24,627
  • Yes i use perfect arcs for lateral movement though i don't adjust radius over time for the Euler spiral i don't quite understand how to do that when interpolating from A to B. – WDUK Apr 08 '20 at 04:11
  • @WDUK I edited to include an example. The key is the curvature formula. If you use some kind of sigmoidal function or cubic spline, as others have suggested, you could try to work in the curvature in a similar way to the example problem here. – Théophile Apr 11 '20 at 04:39
1

For arbitrary piece-wise smooth curves I recommend cubic splines since they're versatile and can approximate any curve you'd use in application.

CyclotomicField
  • 11,018
  • 1
  • 12
  • 29