# Coding brachistochrone curve in Metapost

I need a picture like this one (without vector s, start and end) in metapost. The blue curve is an inverted cycloid, the green one is an arc of circle. I have no idea how to do it, so any kind of help would be great.

The brachistochrone is an inverted cycloid. You can plot one in Metapost by imagining that you are rolling a wheel along the x-axis. Here is another cycloid diagram question.

``````prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);
numeric u, r;
u = 5mm;
r = 4u;

path xx, yy, A, B, C;
xx = (left -- 8 right) scaled u;
yy = (up   -- 8 down)  scaled u;

% define an inverted cycloid
A = origin for t=5 step 5 until 200: -- (0,r) rotated t shifted(r*t/57.29578,-r) endfor;

% find the point on it where it crosses the line y=-x
z0 = A intersectionpoint ((u,-u) -- (10u,-10u));

% define the straight line and the arc
B = origin -- z0;
C = quartercircle rotated 180 scaled 2x0 shifted (x0,0);

draw A cutafter z0 withcolor .53 blue;
draw B             withcolor .67 red;
draw C             withcolor .48 green;

draw (0,y0) -- z0 -- (x0,0) dashed withdots scaled 1/3;

drawarrow xx withcolor .5 white;
drawarrow yy withcolor .5 white;

dotlabel.urt("Start", origin);
dotlabel.lrt ("End", z0);

endfig;
end.
``````