# calculating coordinates along a clothoid betwen 2 curves

I need to write a program that will calculate coordinates along the designed rails of a proposed subway. The designed polyline representing the rail is composed of lines, arcs (circular curves) and transition spirals which are clothoids (Euler spirals). My problem concerns the clothoids. The simplest case is as follows: A tangent line to a clothoid to an arc to another clothoid to another tangent line. See the first image below. standard clothoid transition spiral

After searching the internet I found a solution for the standard case. It is possible to calculate the variables y and x which are the distance along the tangent and the perpendicular distance to a point on the spiral, defined by the length along the spiral. Using y and x it is easy to calculate the coordinate of the point on the spiral in relation to the tangent line. The given or known values for the solutions are extracted from the Autocad design drawing. They include the coordinates of the tangent points, start and end of arcs, start and end of clothoids, radiuses of arcs and lengths of clothoids. The formula used to calculate y and x are shown above. The calculation is an expansion of Fresnel integrals. A clothoid is used as a transition spiral because the radius changes linearly along the length of the spiral from infinity at the tangent point to the radius of the arc segment at the end of the spiral. My problem is with the more complicated cases the first of which is as follows: Tangent line to Spiral to Curve to Spiral to CURVE to Spiral to Tangent line. The difference between this and the first case is, how do I solve a spiral that is between two arcs? See the spiral labeled S2 below: a spiral between 2 arcs

Thank you John

September 15, 2019 Hello The only way I will be able to understand the solution is by seeing a numerical solution. Here is an example spiral between 2 circular curves. If someone has the time to do this I would be extremely grateful. I have the data in other formats but I can't post the files here. Thanks John

• this is quite simple actually. you have $s_2 r_2 = (s_1 + l) r_2 = s_1 r_1$. just solve it for $s_1$. from $l=15$, $r_1=647.59$, $r_2=355.0$ you get $s_1$, then $s_2$, $A$ and everything follows. – Will Ness Apr 28 at 8:48
• i.e. next you have $x1,y1$ and $x2,y2$ in "clothoid" space. and you are given $X1,Y1$ and $X2,Y2$ in world space. just calculate the translation and rotation needed to make the two pairs coincide, then use this transformation to transform any $x,y$ on the clothoid for any $s$ between $s1$ and $s2$ (or even outside the interval). – Will Ness Apr 28 at 8:58

## Basic clothoid knowlege The clothoid has generic equation $$R*L = A^2$$, where $$R$$ is radius of curvature, $$L$$ is the length along the arc (not straight) and $$A$$ is a scale factor.

Derived from this, we have some other useful relations, like $$t=\frac{L}{2R} = \frac{L^2}{2A^2} = \frac{A^2}{2R^2}$$
where $$t$$ is the angle from the tangent at $$R=\infty$$ (usually handled as $$R=0$$) and the tangent at some point with given $$L,R$$. In the sketch the tangent at $$R=0$$ is the green line $$x'$$. It isn't an angle from the origin, but between tangent lines; see $$t2$$ in the sketch.

There isn't a formula of type $$y=f(x)$$ for the clothoid. You may find some polynomial approximations.
Instead, $$x,y$$ are defined by expanded Fresnel integrals:

$$x' = A * \sqrt {2t} * \sum_{n=1}^\infty (-1)^{n+1} * \frac {t^{2n-2}}{(4n-3)*(2n-2)!} = A * \sqrt {2t} * (1 - \frac{t^2}{10} + \frac {t^4}{216} - ...)$$

$$y' = A * \sqrt {2t} * \sum_{n=1}^\infty (-1)^{n+1} * \frac {t^{2n-1}}{(4n-1)*(2n-1)!} = A * \sqrt {2t} * (\frac{t}{3} - \frac{t^3}{42} + \frac {t^5}{1320} - ...)$$

Notice these x', y' coordinates are in clothoid space, not in general x,yspace. To go from "general" to "clothoid" space use the known equations: $$x' = (x-a)cos(\delta) - (y-b)sin(\delta)$$ $$y' = (x-a)sin(\delta) + (y-b)cos(\delta)$$

where a,b are the coordinates in general space of the point at $$R=\infty, t=0, L=0$$ and $$\delta$$ is the angle from "general" to "clotoid" space.

It's common in surveying to use a different angle criterium: Start at north, grow clockwise. The space transformation formulas above work with normal criterium: Start at east, grow counter-clockwise.
I don't show here how those transformations change with this "survey criterium", nor the formulas for $$x=f(x')$$ direction. But all of them are easy to derive.

## Clothoid between two circumferences

Given data: Radius and centers of both arcs, clothoid parameter A

Circumferences must be tangent to clothoids, and radius of curvature must be the same at each tangent point.

This means that at point $$P1$$ we have $$R=R1$$ and then $$t1= \frac{A^2}{2R1^2}$$.
Now we know $$t$$ we can calculate $$x_1',y_1'$$ by the Fresnel expansions. Repeat the same proccess for the other circumference, calculate $$t2$$ and $$x_2',y_2'$$

Case 1: P1 or P2 is given
Then you can calculate the angle $$\delta$$ by combining angles $$C1 to P1$$ and $$t1$$ or $$C2 to P2$$ and $$t2$$
Then calculate $$a,b$$ using this $$\delta$$ and the $$x,y$$ and $$x',y'$$ data by the rotation&translation transformation formulas.

Be aware of the direction on the clothoid: From $$R1>R2$$ to $$R2$$ or from $$R1 to $$R2$$. This affects the point at $$R=0$$ and all of $$\delta, a, b$$. Pay attention to what $$t$$ angles you are calculating.

Case 2: P1 and P2 are unknown
In this case you build the triangle $$P1C1P2$$ with the goal of calculating the distance $$r_p=C1toP2$$

You already know $$C1toP1=R1$$ and $$d_{12}= P1toP2 = (x_1',y_1')to(x_2',y_2')$$
Working in "clothoid space" you can calculate the angle $$P1P2$$ with the $$x'$$ axis. Adding the $$t1$$ angle you get the angle for the line $$P1toC1$$. With the distances and this angle you solve the triangle can calculate $$r_p$$

Now build a circumference of center = $$C1$$ and radius $$r_p$$. Intersect it with the given circumference $$C2,R2$$. That is the $$P2$$ point.
The $$P1$$ point comes from another intersection: center=$$P2$$ radius $$d_{12}$$ and given circumference $$C1,R1$$
You may check that you use the proper intersection (circ-circ has two intersections).

You can play with angles $$P2toC2$$ and $$t2$$ to obtain angle $$\delta$$. Anyhow, you are now in case 1, solved above.

I'm sure there are many optimizations to this solution, I don't have them at hand.

Then
Now you have all data $$a,b,\delta$$ you can get any point in the clothoid by Fresnel expansions and then calculate the "general" coordinates by undoing the rotation&translation transformation.

You have the special case where the radius of curvature of the clothoid is $0$ at one endpoint. To obtain the general case with two non-zero radii of curvature, $R_1$ and $R_2$, calculate two sets of coordinates along a clothoid, with the radius of curvature $0$ at one endpoint, $R_1$ at the other endpoint in one calculation and $R_2$ in the other calculation. Then, if you want to, you can translate the coordinate system such that the point with radius of curvature $R_1$ is at the origin and rotate it such that the tangent at that point points along the $X$ axis. The angle of rotation is the total angle subtended by the clothoid up to that point, as given in your first image (with $R=R_1$).

• Thank you for your help. After trying hard I am unable to visualize your explanation (I am only a survey engineer and not a mathmatician). If it is possible I think a diagram and/or an example would be very helpful. – John May 16 '16 at 13:01
• Start/end points, tangent angles, curvatures at both ends are given and we have to trace out a clothoid curve... Is that right? – Narasimham Aug 29 '19 at 7:35
• Yes that is exactly right. I have prepared numerical example which I Would like to send to you, but I am having trouble understanding how this site works. John – John Sep 15 '19 at 13:55

Using the 2 tangent to endpoints of circles connected by clothoid you can plot the dα (in fact the rythm of changing of the angle along the path of the clothoid ) on let's say 1.0 m steps.There is a formula providing an exact calculation , then becomes a problem of significant digits you must use in your calculations to have a certain accuracy let's say 0.001 m on the final step of calculation of x,y on the clothoid path.

• Hello I think that only by seeing a numerical example will I be able to understand how to proceed. I have prepared an example that I would like to send to you but I am having trouble understanding how to use this site John – John Sep 15 '19 at 13:51

The interpolation problem is a system of three nonlinear equations with multiple solutions which is difficult to solve also numerically. the solution of this system is reduced to the computation of the zeros of one single function in one variable

A solution exists as a G1 Fitting: https://github.com/ebertolazzi/G1fitting Additional information for the maths behind it: https://www.researchgate.net/publication/237062806_Fast_and_accurate_G1_fitting_of_clothoid_curves