# Creation of a rail profile from a drawing

## Method

The profile is built-up by three arcs R1.r=300, R2.r=80 and R3.r=13, and one straight section with slope 1:20.

Search for the locations of the three origins and where the straight section starts:

```
X1= 20.456/2.                                  # Breakpoints on rail head
X2= 52.053/2.
X3= 72.000/2.

R1.x0= 0                                       # Centre of R1
R1.y0= 300

R2.x0= R1.x0 + (R1.r-R2.r)*sin(R1.fi)          # Centre of R2
R2.y0= R1.y0 - (R1.r-R2.r)*cos(R1.fi)
Where R1.fi= asin(X1/R1.r)

R3.x0= R2.x0 + (R2.r-R3.r)*sin(R2.fi)          # Centre of R3
R3.y0= R2.y0 - (R2.r-R3.r)*cos(R2.fi)
Where R2.fi= asin((X2-R2.x0)/R2.r)

S.xs= R3.x0  +  R3.r*sin(R3.fi)                # Straight section starting coordinate
S.ys= R3.y0  -  R3.r*cos(R3.fi)
Where R3.fi= asin((X3-R3.x0)/R3.r)
```
When the above data is known, it is easy to generate the profile. Use a for-loop or use the gensys func-program. Please remember to make the output very dense, preferable 50 values per millimeter.

## Example: A script for Octave

```
output_precision(15);

%
% ----------------------------------------
R1= 300
R2=  80
R3=  13

%
% -------------------------------------------
X1= 20.456/2.
X2= 52.053/2.
X3= 72.000/2.

%
% Slope after R13
% -------------------------------------------
Slope= 1/20

%
% -------------------------------------------
x10=  0.
y10=  R1
fi1= asin(X1/R1)

%
% Max angle for radius R2
% -------------------------------------------
x20= x10 + (R1-R2)*sin(fi1)
y20= y10 - (R1-R2)*cos(fi1)
fi2= asin((X2-x20)/R2)

%
% Max angle for radius R3
% -------------------------------------------
x30= x20 + (R2-R3)*sin(fi2)
y30= y20 - (R2-R3)*cos(fi2)
fi3= asin((X3-x30)/R3)

%
% Start coordinate for the straight line
% -------------------------------------------
x40= x30 +     R3 *sin(fi3)
y40= y30 -     R3 *cos(fi3)

%
% End coordinate for the straight line
% -------------------------------------------
x50= x40 + 40*Slope
y50= y40 + 40

profR1= create_circle (x10, y10, R1, 0., X1, 0.02, -1);
profR2= create_circle (x20, y20, R2, X1, X2, 0.02, -1);
profR3= create_circle (x30, y30, R3, X2, X3, 0.02, -1);
profSlope= create_line (x40, y40, x50, y50, 0.02);

%
% Concatenate the parts from negative to positive coordinates
% -----------------------------------------------------------
iprof= 0;
clear prof;
for ii = length(profSlope):-1:1
++iprof;
prof(iprof,1)= -profSlope(ii,1);
prof(iprof,2)=  profSlope(ii,2);
end

for ii = length(profR3):-1:1
++iprof;
prof(iprof,1)= -profR3(ii,1);
prof(iprof,2)=  profR3(ii,2);
end

for ii = length(profR2):-1:1
++iprof;
prof(iprof,1)= -profR2(ii,1);
prof(iprof,2)=  profR2(ii,2);
end

for ii = length(profR1):-1:1
++iprof;
prof(iprof,1)= -profR1(ii,1);
prof(iprof,2)=  profR1(ii,2);
end

% ------------------------------------ Rail Center line

for ii = 1:length(profR1)
++iprof;
prof(iprof,1)=  profR1(ii,1);
prof(iprof,2)=  profR1(ii,2);
end

for ii = 1:length(profR2)
++iprof;
prof(iprof,1)=  profR2(ii,1);
prof(iprof,2)=  profR2(ii,2);
end

for ii = 1:length(profR3)
++iprof;
prof(iprof,1)=  profR3(ii,1);
prof(iprof,2)=  profR3(ii,2);
end

for ii = 1:length(profSlope)
++iprof;
prof(iprof,1)=  profSlope(ii,1);
prof(iprof,2)=  profSlope(ii,2);
end

plot (prof(:,1), prof(:,2))

% ------------------------------------ Export data

write_2col_file ('uic60.rail', prof(:,1), prof(:,2))

```