Here's a simple test (written in Codea/Lua on the iPad) for calculating the 'nearest point' on a Bezier curve (shown in Orange) from an arbitrary point lying on a 2d plane shown in Red.

The Red circle is actually a 'touch' event (that returns an x,y position in 2D) that can be moved around interactively on the iPad.

Useful R&D for game-development shenanigans!

Nerdy Stuff...

Mathematically, there are a number of numerical methods for calculating this position which can be quite computationally intensive, I've used a simpler brute force method that samples the curve along a 'span' and works out the minimum distance to the sampled point from the touch position using simple trig. The higher the number of samples (and computation effort) the more accurate the result..

Loading more stuff…

Hmm…it looks like things are taking a while to load. Try again?

Loading videos…