Archive: inverse-bezier-curve math problem


11th March 2004 10:44 UTC

inverse-bezier-curve math problem
after playing around a lot with those cute bezier-curves, i tried to make some kind of inverse-bezier-curve.
you simply "tell" the curve through which points it should pass and then it calculates the required control-points.
doing this for a cubic bezier-curve was easy as 3.1415926. then i tried the same for a quartic curve, in order to find some
kind of universal formula for inverse-bezier-curve, and must've made a mistake. the curve deforms almost as expected, just
a bit too much. i'll post my solution for the equations here, maybe you can find what i missed.

(sorry for my math-english)

the basics:
4 points, which lie on the curve, are defined.
i=0, i=1/3, i=2/3 and i=1
beziercurvefunction:
(ni=1-i P1,P2,P3 and P4 are the four control points))
ni*ni*ni*P1 + 3*ni*ni*i*P2 + 3*ni*i*i*P3 + i*i*i*P4

so the following applies for the four custom points:
for i=0: P1
for i=1/3: 8*P1/27 + 12*P2/27 + 6*P3/27 + P4/27
for i=2/3: P1/27 + 6*P2/27 + 12*P3/27 + 8*P4/27
for i=1: P4

so we've got P1 and P4, now we need formulas for P2 and P3
(P(1/3) is the second custom point, the others are control points)
P2 = 27/12*(P(1/3) - 8*P1/27 - 6*P3/27 - P4/27);
P3 = 27/12*(P(2/3) - P1/27 - 6*P2/27 - 8*P4/27);

now i combine these two equations to this one
P3 = 27/12*(P(2/3) - P1/27 - 6*(27/12*(P(1/3) - 8*P1/27 - 6*P3/27 - P4/27))/27 - 8*P4/27); |apply factors
P3 = 27/12*(P(2/3) - P1/27 - 0.5*(P(1/3) - 8*P1/27 - 6*P3/27 - P4/27) - 8*P4/27); |again
P3 = 27/12*(P(2/3) - 5*P1/27 - 0.5*P(1/3) - 3*P3/27 - 8.5*P4/27); |sum up
P3 = 27*P(2/3)/12 - 5*P1/12 - 27*P(1/3)/24 - P3/4 - 17*P4/24; |apply factors again
P3 = 4/5*(27*P(2/3)/12 - 5*P1/12 - 27*P(1/3)/24 - 17*P4/24); |+P3/4 |/1.25
P3 = 1.8*P(2/3)3 - P1/3 - 0.9*P(1/3) - 17*P4/30 |apply factors one last time

so for P2 we've got:
P2 = 1.8*P(1/3)3 - P4/3 - 0.9*P(2/3) - 17*P1/30



that's it. i've already killed tons of stupid mistakes, but there must be one very persistent mistake.

btw: if you know this holy universal inverse-bezier-curve-formula-thingy, please tell me! :)

thanks in advance.


15th March 2004 00:50 UTC

The problem could simply be that there is more than one possible patch that can pass through any given set of points. Your maths could be correct.

However from what I know about patches and splines (not just bezier) in general making a quartic spline pass through 5 points requires the solution to a quartic equation.


15th March 2004 10:10 UTC

i also thought that there is more than one possible solutions. but it works quite fine for the quadratic (is it cubic or quadratic? it's got second degree) thingy.
and in graphic programs like blender, gimp, or 3dsmax i've those "inverse-bezier-curves", so there must be a way to do it. maybe someone who's good at coding can look at the gimp source (it's opensource) and tell me how they made it, *hrhr*.


15th March 2004 12:31 UTC

I think in The Gimp or Max, the curves are just piecewise beziers between each point, with the control points calculated/estimated based on the existing points.

Or maybe they're not beziers at all, remember there are endless types of splines.


16th March 2004 03:02 UTC

I'm pretty certain that there is only one parabola through any three distinct points, this is why the quadratic version worked. :P

I know that four points on a conic section are enough to reconstruct the entire section.

For a cubic case though it is easy to see how and four distinct points will be able to define an infinity of curves.

I would doubt that something like MAX would use such a silly method for constructing splines/patches. Trying to make a Bezier curve pass through specific points is a waste of time, why not just make a new type of spline which does pass through its control points? This is infact a much simpler problem and can be dealt with very easily for the first few cases (2,3 or 4 points). Think about the method for finding the equation of a line from two points.


16th March 2004 11:03 UTC

http://collective.valve-erc.com/data...rse_bezier.png
//edit: hm, I thought the [IMG] tag would make the image appear in the post, well it doesn't so please click this link.
An image of those curves thingies in the GIMP.
I dunno how they made it and I'm notgood at reading c++ code.
You're talking about splines all the time. The curves I want to make needn't be beziers, I just want the math for a "go-through-all-those-points-curve", so please tell me more about those splines (I knew them from blender, but was unable to math stuff about it).
One more about this quadratic bezier curve. Afaik a quadratic equation has up to two possible solutions, so why does this work?


16th March 2004 13:43 UTC

A quadratic having two possible solutions and a quadratic passing through three points are seperate things... i don't even know if what i said about that was right. After more thought on the quadratic bezier I realised that the 'middle' control point needn't be central on the curve and so you can have an infinity of quadratic beziers that pass through any three points... also they aren't regular quadratics at all... a cartesian quadratic is something completely different and is always parabolic.

I did cover quartic splines that pass through points at uni... but it was almost 2 years ago now and I can't be arsed to work it all out right now just for you. I'll work it out when i get some spare time or something cos its starting to bug me :) .


16th March 2004 17:59 UTC

Some things to google for:
- b-splines
- nurbs
- catmull-rom
...