Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate a bezier spline to get from point to point

I have 2 points in X,Y + Rotation and I need to calculate a bezier spline (a collection of quadratic beziers) that connects these 2 points smoothly. (see pic) The point represents a unit in a game which can only rotate slowly. So to get from point A to B, it has to take a long path. The attached picture shows quite an exaggeratedly curvy path, but you get the idea.

alt text

What formulas can I use to calculate such a bezier spline?

like image 352
Robin Rodricks Avatar asked Dec 10 '09 07:12

Robin Rodricks


People also ask

How do you get points on a Bézier curve?

Following the construction of a Bézier curve, the next important task is to find the point C(u) on the curve for a particular u. A simple way is to plug u into every basis function, compute the product of each basis function and its corresponding control point, and finally add them together.

How do you find the equation of a Bézier curve?

Number of points i.e. k=4, Hence, we know that the degree of the Bezier curve is n= k-1= 4-1= 3. Hence, P0(2,2,0) and B0,3=(1−u)3,P1(2,3,0) and B1,3=3u(1−u)2,P2(3,3,0) and B2,3=3u2(1−u) andP2(3,2,0) and B3,3=u3.


1 Answers

Just saw that I misunderstood your question. Couldn't you use a single cubic hermite splines instead since you have a start and end point and two directions (tangents)? Are there any additional constraints?

To calculate the start and end tangents just use the start and end direction and scale them with the distance between the start and end points (and additionally some other constant factor like 0.5 depending on how curvy you want the path to be).:

p0 = startpoint;
p1 = endpoint;
float scale = distance(p0, p1);
m0 = Vec2(cos(startangle), sin(startangle)) * scale;
m1 = Vec2(cos(endangle), sin(endangle)) * scale;

I use this system to interpolate camera paths in a game I'm working on and it works great.

like image 199
Andreas Brinck Avatar answered Oct 28 '22 16:10

Andreas Brinck