问题
I know:
The control points a and d (start and end point of a 2D cubic bezier curve)
The slopes a->b, c->d, and b->c (b,c the other control points)
Where the halfway point of the Bézier curve is.
Now, given this information, what is the formula for the positions of control points b and c ?
回答1:
I know this question is old, but there is no correct or complete answer provided, so I thought I'd chime in with a solution. Note that David's calculations contain several errors and his solution is incomplete even if these errors are corrected.
First, define vectors T0
, T1
and T2
using the three slopes:
T0 = ( b - a ) / u0
T1 = ( c - b ) / u1
T2 = ( d - c ) / u2
If we knew both the direction and distance between each pair of control points then we would not need the scale factors u0
, u1
and u2
. Since we only know slope then u0
, u1
and u2
are unknown scalar quantities. Also, we assume that u0
, u1
and u2
are nonzero since slope is defined.
We can rewrite these equations in several different ways to obtain expressions for each control point in terms of the other control points. For example:
b = a + T0*u0
c = b + T1*u1
d = c + T2*u2
The question also states that we have the "halfway point" of the cubic Bezier curve. I take this to mean we have the point at the midpoint of the curve's parameter range. I will call this point p
:
p = ( a + 3*b + 3*c + d ) / 8
Rewriting with unknowns on the left hand side yields:
b + c = ( 8*p - a - d ) / 3
We can now substitute for b
and c
in various ways using the earlier expressions. It turns out that ambiguities arise when we have parallel vectors T0
, T1
or T2
. There are four cases to consider.
Case 1: T0
is not parallel to T1
Substitute b = a + T0*u0
and c = a + T0*u0 + T1*u1
and solve for u0
and u1
:
2*T0*u0 + T1*u1 = ( 8*p - 7*a - d ) / 3
This is two equations and two unknowns since T0
and T1
are vectors. Substitute u0
and u1
back into b = a + T0*u0
and c = a + T0*u0 + T1*u1
to obtain the missing control points b
and c
.
Case 2: T1
is not parallel to T2
Substitute c = d - T2*u2
and b = d - T2*u2 - T1*u1
and solve for u1
and u2
:
T1*u1 + 2*T2*u2 = ( a + 7*d - 8*p ) / 3
Case 3: T0
is not parallel to T2
Substitute b = a + T0*u0
and c = d - T2*u2
and solve for u0
and u2
:
T0*u0 - T2*u2 = ( 8*p - 4*a - 4*d ) / 3
Case 4: T0
, T1
and T2
are all parallel
In this case a
, b
, c
and d
are all collinear and T0
, T1
and T2
are all equivalent to within a scale factor. There is not enough information to obtain a unique solution. One simple solution would be to simply pick b
by setting u0 = 1
:
b = a + T0
(a + T0) + c = ( 8*p - a - d ) / 3
c = ( 8*p - 4*a - d - 3*T0 ) / 3
An infinite number of solutions exist. In essence, picking b
defines c
or picking c
will define b
.
Extending to 3D
The question specifically asked about planar Bezier curves, but I think it's interesting to note that the point p
is not necessary when extending this problem to a non-planar 3D cubic Bezier curve. In this case, we can simply solve this equation for u0
, u1
and u2
:
T0*u0 + T1*u1 + T2*u2 = d - a
This is three equations (the vectors are 3D) and three unknowns (u0
, u1
and u2
). Substitution into b = a + T0*u0
and c = b + T1*u1
or c = d - T2*u2
yields b
and c
.
回答2:
Let's say your slopes are normalized, then for some u,v you have
u * slope(a->b)+a = b, v * slope(c->d)+d = c
you know the values of a,d, and q:=(a+b+c+d)/8
(the halfway point of the curve)
so c = 8(q-a-d-b)
plugging the above equations in the last one you get
v * slope(c->d)+d = 8(q-a-d-a-u * slope(a->b))
which is 2 equations (a 2d vector equation) in two variables (u,v)
You don't need the third slope.
来源:https://stackoverflow.com/questions/404861/calculation-of-cubic-b%c3%a9zier-with-known-halfway-point