Create a (transition) curve that lines up with a circle with a missing quarter and that stays within the bounding box of the circle

curvesparametric

I'm trying to create the transition curve that is red in my diagram.

scenario

It starts at point P, which is the top-left corner of the bounding box of the black circle and it aligns with the black circle, that is missing one quarter.

I have found the following parametric formula to create the points of the transition curve

$x = s – \frac{s^2}{40r^2L^2}$

$y = \frac{s^3}{6rL} – \frac{s^7}{336r^3L^3}$

Where

  • $s$ the length of the transition curve from $0$ to the current position
  • $r$ the radius of the circle
  • $L$ the total length of the transition curve

It looks like the only meaningful parameter I can play with is $L$ and given a large enough $L$ the transition curve will align with the circle. But it is not clear to me what formula I should use to pick the right value for $L$. If i have the right value of $L$ I could always adjust the $x$ values to stay within the bounding box.

The formula I have found here, but I'm not necessarily tied to this type of (transition) curve if another curve type is easier to get this effect with I'm OK with that.

Just in case you are curious why I have these specific requirements. I'm trying to generate transition curves for train tracks in a video game, and it would help immensely if they are of a specific size. In this case exactly as wide as regular 90 degree turn and exactly twice as long as a 90 degree turn.

Best Answer

A naive parameterization can be:

$$ \mathbf{r}(u) := \left(a+b\,u+c\,u^2+d\,u^3,\,e+f\,u+g\,u^2+h\,u^3\right), \quad \quad \text{with} \; u \in [0,1]. $$

So, once the tangent unit vector and the curvature have been calculated:

$$ \mathbf{t}(u) := \frac{\mathbf{r}'(u)}{||\mathbf{r}'(u)||}, \quad \quad \quad \kappa(u) := \frac{||\mathbf{t}'(u)||}{||\mathbf{r}'(u)||} $$

it's enough to impose:

$$ \begin{cases} \mathbf{r}(0) = (0,\,2R) \\ \mathbf{t}(0) = (1,\,0) \\ \kappa(0) = 0 \\ \mathbf{r}(1) = (2R,\,R) \\ \mathbf{t}(1) = (0,\,-1) \\ \kappa(1) = 1/R \end{cases} \quad \quad \quad \Rightarrow \quad \quad \quad \begin{cases} a = 0 \\ b = 3R/2 \\ c = 3R \\ d = -5R/2 \\ e = 2R \\ f = 0 \\ g = 0 \\ h = -R \\ \end{cases} $$

to get a transition curve of the required type:

$\quad\quad\quad\quad\quad\quad$enter image description here


TO KNOW MORE

If, in addition to the geometric problem mentioned above, we also want to deal with engineering problems in the railway and road fields, above all to limit the abrupt variation of the centripetal acceleration, we need to refer to a transition curve whose curvature varies linearly with respect to the curvilinear abscissa $s$ and this leads us to choose a clothoid like:

$$ \mathbf{r}(s) := \left(a\int_0^s\cos\left(\frac{u^2}{2RL}\right)\text{d}u,\,2R-a\int_0^s\sin\left(\frac{u^2}{2RL}\right)\text{d}u\right), \quad \quad \text{with} \; s \in [0,L] $$

from which, in fact, it follows that:

$$ \mathbf{t}(s) := \frac{\mathbf{r}'(s)}{||\mathbf{r}'(s)||} = \left(\cos\left(\frac{s^2}{2RL}\right),\,-\sin\left(\frac{s^2}{2RL}\right)\right), \quad \quad \quad \kappa(s) := \frac{||\mathbf{t}'(s)||}{||\mathbf{r}'(s)||} = \frac{s}{aRL} $$

i.e

$$ \mathbf{r}(0) = (0,\,2R), \quad \quad \quad \mathbf{t}(0) = (1,\,0), \quad \quad \quad \kappa(0) = 0. $$

On the other hand, to simplify the calculations, we prefer to expand into Maclaurin series:

$$ \mathbf{r}(s) = \left(as-\frac{as^5}{40R^2L^2},\,2R-\frac{as^3}{6RL}+\frac{as^7}{336R^3L^3}\right), \quad \quad \text{with} \; s \in [0,L] $$

which are essentially the formulas you found in the video, which work well if $R \gg 1$.

In this way, the resolution of the following system of nonlinear equations is no longer prohibitive:

$$ \begin{cases} \mathbf{r}(L) = (2R,\,R) \\ \mathbf{t}(L) = (0,\,-1) \\ \kappa(L) = 1/R \\ \end{cases} \quad \quad \quad \Rightarrow \quad \quad \quad \begin{cases} a = \dots \\ L = \dots \\ \end{cases} $$

at least if understood as a search for the solution that minimizes the sum of the squared deviations.

For example, assuming $R=5$ we obtain $a=0.888553$ and $L=14.0085$ from which:

$\quad\quad\quad\quad\quad\quad$enter image description here

where in red I have dashed the cubic curve above, an indication of the fact that if we aren't interested in engineering problems it's by far preferable as it's easier to determine (which, after all, was what was done before the 1960s when computers weren't available). Happy Sunday, bye!