If you Google "equation of a circle" there are any number of explanations, for example this one
http://www.analyzemath.com/CircleEq/Tutorials.html
The important thing to rememeber when applying this to BVE coding (certainly track geometry) is that we are looking at relative displacements between the circle and a straight line parallel to the y axis, hence when you see the equation written in the form
(x - h)2 + (y - k)2 = r2 it can be simplified to x2 + y2 = r2.
Normally, we know the radius of the curves we are working with and given that we wish to calculate displacements (x) at known values of y (the distance along the track), it is more useful to rearrange this equation to x
2 = r
2 - y
2.
Do not use the route distance as y - this must be set as being the point of divergence.
now get the calculator out....
If we apply this to generate (for example) the displacement (x) of a 750m (r)radius curve at 25m (y) from
the point of divergence, we calculate the following;
r
2 = 750 * 750 = 562500
y
2 = 25 * 25 = 625
so, if x
2 = r
2 - y
2 then x2 = 562500 - 625 = 561875
taking the square root of this will give us x = 749.58322.
Now for the important bit...
if we perform the same calculation at 0m we obtain the following;
r
2 = 750 * 750 = 562500
y
2 = 0 * 0 = 0
so, if x
2 = r
2 - y
2 then x2 = 562500 - 0 = 562500
taking the square root of this will give us x = 750 - the radius of the curve.
It is the
difference between the calculated displacements that are used when constructing diverging (or converging) curves, in this example at 25m the offset is given by 750-749.58322 = 0.41678m.
Similarly, for the same curve, 50m from the
point of divergence,
r
2 = 750 * 750 = 562500
y
2 = 50 * 50 = 2500
so, if x
2 = r
2 - y
2 then x2 = 562500 - 2500 = 560000
taking the square root of this will give us x = 748.33148.
and the offset will be given by 750 - 748.33148 = 1.66852m
If we were to use this as the basis for a curve in BVE, the code would look something like this (if we are starting the curve at 1000m)
1000,.railstart 1;0,
1025,.rail 1;0.41678,
1050,.rail 1;1.66852,
and so on. If the curve goes to the left, just use negative values of the calculated displacements.
There is no real need to use more than two decimal places in the route coding and the calculations can be performed much more rapidly in a spreadsheet.
In the spreadsheet on my website, to calculate the required offsets, just enter the radius into the cell indicated (C5, text coloured red) and the offsets (at 25m intervals) are returned as the green numbers in column H. So to use that spreadsheet, all you have to do is type in the radius of the curve.