CodingTrain / CodingTrain/Suggestion-Box
Challenge: Brachistochrone Game -- Bezier/Spline Curves, etc.
- Dominant language
- No language data
- Stars
- 570
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
The basic idea of this game to write a program that will allow the user to attempt to draw a curve going from point A to point B. Then, they can press play and it will simulate a "ball" rolling down the curve from point A to point B.

The curve above happens to have been mathematically proven to be the fastest possible way for the ball to get to point B, called a [brachistochrone](https://en.wikipedia.org/wiki/Brachistochrone_curve). There are tons of super interesting things about this curve (like it is the same as a [cycloid](https://en.wikipedia.org/wiki/Cycloid) and it is also called a [tautochrone](https://en.wikipedia.org/wiki/Tautochrone_curve) for another property it has).
So, the goal of the game would be to create a curve that takes the least amount of time for the ball to roll down, also letting the user fool around and see what works (having an earlier drop in the curve means the ball has a higher velocity for more of the curve, but at the cost of increasing the length of the curve).
I am currently in the process of trying to make this myself as well, and I originally thought this would be fairly easy but then I found out that some parts of it are actually **_way way WAY_** harder than I originally thought.
For example, using a cubic Bezier curve that the user can edit makes sense to me, but finding the tangent of the Bezier curve at a given point (not at a given t-value, at a given **point**) is quite difficult. There's a very useful StackOverflow post [here](https://math.stackexchange.com/questions/527005/find-value-of-t-at-a-point-on-a-cubic-bezier-curve) that explores how to extract the t-value from a given point on or near the Bezier curve, as well as a [paper](https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=1000&context=facpub) by Tom Sederberg linked in that post (Chapter 17) giving (quite interesting albeit somewhat hard to understand) methods to invert a Bezier curve.
Alternatively, you might be able to use a quadratic Bezier curve with quadraticVertex() (or a series of them for more detail) with draggable control points, making the numerical root solution proposed by the answerer of the post more feasible because the polynomial to solve would be a third degree (or second degree if you use the version that assumes the point is perfectly on the curve, which won't be perfectly accurate but should be very close) and making the tangent calculation easier in general if you were to use Tom Sederberg's method.
I also considered using spline curves, but I don't know much about them or how to calculate anything with them but they could be easier if you would like to look into a slightly easier method.
I am currently in the process of attempting to make this work (I'm sticking with my initial cubic Bezier idea for now because the math is super interesting), but I'd really like to see how you would approach this and see the finished product!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.