Move the 8 dots up or down to shape the track. Press Play to send the ball along it. Avoid the walls and reach the goal as fast as you can. A shorter route is not always faster: a deeper drop at the start can help the ball gain speed. A track that hits a wall turns red and cannot be played.
Select a dot to use the arrow buttons at the bottom left. Hold a button to keep moving. You can also use the up and down keys.
The ball is treated as a point with no size. It slides under gravity, without rotation or friction, and stays on the track. Only its centre is used to check for wall collisions.
The curve is drawn using B-splines. Moving the control points changes its shape. The control points do not necessarily lie on the curve. Read about B-splines on Wikipedia
Compare with the answer
Press Answer to calculate the fastest course available on this stage and show it as a gold line over your track. This does not start playback. Press Play to start your ball and the gold ball together. You can keep editing while the answer is shown. Press Answer again to hide it.
The answer is a numerical solution for the fastest course that can be made with this game's B-spline and its 8 movable control points. It is not necessarily the fastest among all possible curves. The calculation may take a few seconds, depending on the stage and your device. See Learn for the calculation method.
Change the stage
Select 0, 1 or 2 to change the number of walls. Press Random for a new random stage. Press Manual to move the walls and the goal yourself. Press Done to confirm the layout and return to shaping the track.
A brachistochrone curve gives the shortest travel time for a particle sliding from rest under gravity, without friction, to a lower goal. With no walls or other obstacles, the fastest curve between two horizontally separated points is part of a cycloid, rather than a straight line.
This problem asks which curve gives the shortest time. It is a classic introduction to the calculus of variations in university mathematics and physics.
Below, we explain the mathematics of the brachistochrone problem with walls (obstacles).
The model and travel time
Let x be horizontal and y point upward. We describe the track by the graph of a function f, with y=f(x) for 0≤x≤L. The start is (0,H) and the goal is (L,h), where h<H. We require f(0)=H, f(L)=h, and f(x)<H for x>0. The ball is a point mass starting from rest. We neglect friction, air resistance and rotation, and assume that it stays on a fixed track.
For gravitational acceleration g and mass m, conservation of energy gives
21mv(x)2+mgf(x)v(x)=mgH,=2g(H−f(x)).
A small length along the track is 1+(f′(x))2dx. Dividing by the speed and integrating gives the travel time
T[f]=2g1∫0LH−f(x)1+(f′(x))2dx.
We seek the track that minimizes this time while avoiding the walls. In the classical problem without walls, the fastest curve is a cycloid, which can be derived from the Euler–Lagrange equation[4].
A change of variables and route choices
Using the square root of the drop, u(x)=H−f(x), the travel time becomes
J[u]=2g1∫0Lu(x)−2+4(u′(x))2dx.
The integrand is convex in (u,u′), so J is a convex functional of u. This convex reformulation is known[1].
Consider a wall over a horizontal interval Ij, with bottom ℓj and top rj; for simplicity, assume rj<H. Avoiding it requires either f≥rj throughout the interval or f≤ℓj throughout it. Allowing both route choices gives a nonconvex feasible set. Once we fix the side and use u, we only need one of the linear constraints
u(x)≤H−rj,x∈Ij
or
u(x)≥H−ℓj,x∈Ij.
With N walls, we can enumerate at most 2N choices of above or below, solve the convex problem for each choice, and compare their optimal values. For two walls, the four choices are above–above, above–below, below–above and below–below.
Numerical computation with B-splines
For computation, we fix a horizontal parameterization x=x(s) and express u(x(s)) as a linear combination of B-spline basis functions[2]. The variables are finitely many coefficients. The objective remains convex and the wall constraints remain linear for each fixed route. We approximate the integral by numerical quadrature with positive weights, check the constraints over each entire wall interval, and add constraints where needed. Each finite-dimensional convex problem is solved using a logarithmic barrier and Newton's method[3]. Comparing the optimal values gives a numerical global solution within the chosen B-spline curve family.
A rigorous treatment requires further discussion of the singularity at the stationary start, existence of minimizers, and discretization error. We omit these details here. For the singularity and existence in the classical problem without walls, see[4]; for convex optimization and splines, see[3] and[2].
Previous work on obstacles
Alessi et al., in A Dynamic Programming Approach for the Brachistochrone Problem, discretize the problem on a grid and use dynamic programming to find paths around obstacles[5]. This site uses a different curve representation and solution method: it enumerates the above/below choices for the walls, represents the square root of the drop with B-splines, and solves a convex optimization problem for each choice.
のいずれか片方の線形制約のみを扱えば良いことになります。したがって、壁が N 枚なら上・下の最大 2N 通りを列挙し、通過側を固定した各凸最適化問題を解いて最適値を比較すれば、全体の最適値を求められます。例えば、壁が2枚の場合は、上上、上下、下上、下下の4通りに対応する4つの凸最適化問題を解いて最適値を比較します。
Alessiらの A Dynamic Programming Approach for the Brachistochrone Problem は、障害物を含む問題を格子上に離散化し、動的計画法で経路を求めています[6]。このサイトでは、壁の上下の通過側を列挙し、落差の平方根をBスプラインで表して各通過側の凸最適化問題を解くため、曲線の表現と解法が異なります。