Is there a formula that defines a bezier curve connecting 2 points with starting/ending directions?

1.2k Views Asked by At

Is there a way to generate a bezier curve that connects 2 points, with each point having a direction in which the bezier curve must start and stop with? For example, if point A is at (2, 2) and has a direction of 0 radians and point B is at (6, 0) and has a direction of PI/2 radians, than can I generate a bezier curve connecting the 2 points starting from point A's direction and finishing in point B's direction?

1

There are 1 best solutions below

1
On BEST ANSWER

Assuming a 2D curve, you can use a cubic Bezier curve of the form:

$x(s)=b_{x0} (1-s)^3+3 b_{x1} s(1-s)^2 + 3 b_{x2} s^2 (1-s) + b_{x3} s^3 $ $y(s)=b_{y0} (1-s)^3+3 b_{y1} s(1-s)^2 + 3 b_{y2} s^2 (1-s) + b_{y3} s^3 $


In this expression your first point A is $(b_{x0},b_{y0})$, the point B is $(b_{x3},b_{y3})$. If the tangent vector at A is $(u_x,u_y)$ then you have that $(u_x,u_y)=k_1(b_{x1}-b_{x0},b_{y1}-b_{y0})$, for some constant $k_1$ and similarly at B, with tangent vector $(v_x,v_y)$ you have $(v_x,v_y)=k_2(b_{x2}-b_{x3},b_{y2}-b_{y3})$ for some constant $k_2$. You can think of these constants $k_1$ and $k_2$ as being proportional to the speed of a particle tracing out the curve. This "speed" gives you additional degrees of freedom to play with in addition to the angular direction at the end points. So a Bezier curve with given end points and angular directions is not unique.


Finally you can use $cos()$ and $sin()$ rules for the tangent vector to get the relationship with the angles.