Nekit_SPb
Nekit_SPb

Reputation: 43

How to remove a node of a Bezier curve so that the shape of the curve does not change?

I need a help in writing the algorithm remove nodes Bezier curve. Using cubic Bezier curves, there are two curves (P0, P1, P2, P3 and Q0, Q1, Q2, Q3), which have a common point (P3=Q0). Need to get a single curve (P0, R1, R2, Q3), repeating the shape of two. How to find the coordinates of control points R1, R2?

Thank you!

Upvotes: 4

Views: 1724

Answers (1)

JCooper
JCooper

Reputation: 6525

In the general case, it's not possible to do what you're asking. You're asking to go from 7 degrees of freedom down to 4 but keep the same result. The representative power of the lower DOF system can't match that of the higher. The only time it would be possible is if the more complex curve still happened to lie in the simpler space. For example, if your two Bezier curves came from sub-dividing a single parent curve with points R0, R1, R2, R3. Using the de Casteljau algorithm, we can generate two new curves, P and Q, that lie on the same original curve and share a point that is t distance along the original curve (where t is in [0,1]).

P0 = R0
P1 = R0*(1-t) + R1*t
X  = R1*(1-t) + R2*t
P2 = P1*(1-t) + X*t
Q3 = R3
Q2 = R2*(1-t) + R3*t
Q1 = X*(1-t) + Q2*t
Q0 = P3 = P2*(1-t) + Q1*t

If that relationship doesn't hold for your original points, then you'll have to craft an approximation. But you might get away with pretending that the relationship holds and just invert the equations:

R1 = (P1 - P0*(1-t))/t
R2 = (Q2 - Q3*t)/(1-t)

Where

t = (Q0 - P2)/(Q1 - P2)

This last equation is the problem because, unless P2, Q0, Q1 are co-linear it won't work exactly. t is a scalar, but Q1-P2 is normally an n-dimensional point. So you can solve it separately for each dimension and find the average, or be a bit more sophisticated and minimize the squared error.

Upvotes: 1

Related Questions