I'm fighting a problem with brachistochrone program.
I'd like to find the path between two chosen points, A and B, in the uniform gravitation field, which is the fastest one.
Brachistochrone is a well known problem solved by calculus of variation and it's known that the analytical solution is a cycloid. But I don't want to solve it analytically, I would like to find the solution through a program.
I've tried it very simple way and it didn't work. I've tried to find some programs at the intnernet for inspiration but I found only those inspired by cycloid or in mathematica/matlab solving problem by solving differential equations. But I would need solution writable in C/C++ or Pascal.
(I've tried it in Pascal but as for me I don't mind about which one it is since I'm not advanced programmer and I know both languages only a little)
I thought it may work by linesearch. I tried to rewrite one maybe useful program in matlab but I don't understand the core of the routine what'S a big mistake and obstacle. THe program gives me only the travel time and not the discrete point of the path.
If you can help me to get into the code that I'd able to make the program draw the path... or if you have any idea how to find the path more easily for me (it could take more computing time but I would be able to write it and understand it
the xend, yend are the coordinates of the ending point, the first call for function Find is for x= x start and y= y start,
the it should itterate and after succesful itteration get true into the B_test array which is boolean and full of false at the beginning
function Find(x,y:real):real; begin xi:=round(x/dx+1); yi:=round(y/dy+1); yMin1:=y+dx*(yend-y)/(xend-x); yiMin1:=Ny-trunc(abs(yend-yMin1)/dy); yiMin2:=0; if yi >1 then begin if (B_test[yi-1,xi])=true then yiMin2:=B_yi_1[yi-1,xi]; end; if (yiMin1> yiMin2)=true then yiMin:=round(yiMin1) else yiMin:=round(yiMin2); chooseT:=10000000; optim_Y:=10000000; chooseDdeltat:=10000000; writeln(textt,B_x[yi,xi],' ',B_y[yi,xi]); xi:=round(x/dx+2); for yi:=yiMin to Nya do begin if (B_test[yi,xi])=false then begin B_x[yi,xi]:=x+dx; B_y[yi,xi]:=(double(yi)-1)*dy; Find(b_x[yi,xi],b_y[yi,xi]); B_test[yi,xi]:=true; end; end; deltat:=Tr(y, B_y[yi,xi]); tdoc:=deltat+B_T[yi,xi]; if (tdoc>chooseT)=true then exit else begin chooseT:=tdoc; optim_Y:=round(yi); chooseDdeltat:=deltat; end; writeln(B_x[optim_Y,xi],' ',B_y[optim_Y,xi]); writeln(textt,B_x[optim_Y,xi],' ',B_y[optim_Y,xi]); tmax:=chooseT; yi_1:=optim_Y; ddeltat:=chooseDdeltat; Find:=tmax; end;
Edited by macosxnerd101: Fixed end code tag. Please, .