Bezier Curves

by Mightymo
Use Bezier curves in your games.
ID:1768310
 
When you need things to curve in your game, from projectile paths to tracing, Bezier curves are often a god fit. This library provides everything you need to create and manipulate Bezier curves, as well as providing various information about the curve.

There are two things that are vital. Create a new curve with new().
var/BezierPath/path = new(list(10,10, 20,20, 30,1, 40,40),order=3)

Then, call getPoint() to get the coordinates partway through the curve.
var/list/coords = path.getPoint(0.5)

The above would give you the coords of the point 50% of the way through the curve. This is all that really matters, although the other functions can be useful as well.
Kind of. If you look at my readme, getPoint() takes a percentage, which is a number between 0 and 1. You would change the value accordingly in the loop.

Although not necessarily incorrect, I doubt your Move() is what you want. getPoint() returns a set of coords, not a change from your last position. So, with the way you have it, even if it returned 1,1 every time, the object would still move. Probably not what you want. Most likely, you want to move to the coordinates provided.
Increment by whatever percentage fits your needs.
for(i=0; i <= 1; i += 0.01) // 1% each loop. This is arbitrary, of course.
coords=path.getPoint(i)
I'm not entirely certain what you mean by angle. Do you mean at the critical points of the curve? Or the angle between curves of a path? Something else entirely?

Also, it is important to note that mathematically speaking, there are a lot of curves that Bezier curves cannot match, only approximate (like circles).
Nifty and easy to use. Fanned and thanks for sharing.
I would recommend some modifications to the lib, if you haven't considered them already.

The short of it is that you can precalculate a lot of coefficients that you're re-calculating on each iteration, including with three calls to a factorial proc which is probably the least efficient way to go. A number of multiplication and division operations can also be simplified out.
My plan is to change the system to use forward differencing. While this does force the curve to use discreet intervals, it allows the entire curve to be calculated using only addition after calculating several values. I believe that this will be considerably faster than my current method or even its simplification. Regardless, I do plan to make efficiency changes, although I've been a bit too busy to do so recently.