Quadratic bezier problem

  • Thread starter Thread starter makc
  • Start date Start date
  • Tags Tags
    Quadratic
makc
Messages
65
Reaction score
0
This is about flash scripting, actually. There's that thing called quadratic bezier spline,

p_0(1-t)^2+2p_1 t(1-t)+p_2 t^2,

right, and flash plugin has that "curveTo" command that apparently uses above expression for x(t) and y(t) to draw a curve between two points on screen. So, I was wondering how do I make it so that N points could be connected by smooth curve using N-1 such segments.

What I did originally was solving x'_{i-1}(1) = x'_i(0) for subsequent control points (p_{1,i}) and same for y'-s:

p_{1,i} = 2p_{2,i-1} - p_{1,i-1},

but this did not worked out well, because control points tend to jump around like crazy this way.

So, my next step was getting dx/dy to be same. I concluded that the curve will be still smooth if you multiply x' and y' by any positive number, and so my solution is now p_{1,i} = p_{2,i-1} + a ((2p_{2,i-1} - p_{1,i-1}) - p_{2,i-1}), 0 < a < 1 (see example for a = 0.6 here; click a few times in white rectangle).

My problem is that I don't like the way "a" hangs in it as free parameter. I need some idea how to calculate it based on real curve data (e.g., x_i, y_i). The objective can be vaguely described as getting curve to look as nice as Catmull-Rom spline does.

Thanks for reading.
 
Mathematics news on Phys.org
I've suddenly realized that my pitfall was attempting to solve 2D problem in 1D... so, get ready for another update.
 
hey makc,

Just solving p_0'(1)=p_1'(0) puts no constraint on how you want the curve to look. That is, imagine all the possible solutions to that constraint, like fitting a sinusoidal wave through your corner points. Cardinal splines put a constraint on the shape of the curve, namely that the derivative at each corner point must be in the general direction of the curve (p_i+1 - p_i-1).

You can come up with similar constraints for a spline with quadratic segments, although the details are different. With cubic segments, for each segment, you have two free control points and two constraints -- the derivatives are equal to the general direction of the curve. With quadratic segments, for each segment, you have one free control point and two constraints -- the same two. So using just a single quadratic per segment is overconstrained (there isn't a solution that satisfies both constraints) ... you need to introduce more free control points in the segment ...

One approach is to make each segment a sequence of two quadratics, which in total yields three free points per segment. The first and last should be solved using the normal Cardinal spline method. The middle can be c1, by using your original approach. Since the two end points are molded into the general shape using the Cardinal spline method, this floating center point usually comes out nicely for small "alpha" (i.e. tight). When the spline is loose, the floating middle point usually starts to turn into a visible hump.

Anyway, I have an implementation if you care for it. Just send me a note (bubble.up.soda@gmail.com).

Hope that helps.

Brien
 
For some reason the links to the pics don't work. Can you post a specific set of x,y values you are trying to fit?
 
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Thread 'Imaginary pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top