image
Physics Forums Logo
image
image
* Register * Upgrade Blogs Library Staff Rules Mark Forums Read
image
image   image
image

Go Back   Physics Forums > Mathematics > General Math


Reply

image Quadratic bezier problem Share It Thread Tools Search this Thread image
Old May15-07, 07:30 AM                  #1
makc

makc is Offline:
Posts: 49
Quadratic bezier problem

This is about flash scripting, actually. There's that thing called quadratic bezier spline,

LaTeX Code: 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 LaTeX Code: xsingle-quote_{i-1}(1) = xsingle-quote_i(0) for subsequent control points (LaTeX Code: p_{1,i} ) and same for y'-s:

LaTeX Code: 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 LaTeX Code: 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., LaTeX Code: 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.
  Reply With Quote
Old May16-07, 09:34 AM                  #2
makc

makc is Offline:
Posts: 49
I've suddenly realized that my pitfall was attempting to solve 2D problem in 1D... so, get ready for another update.
  Reply With Quote
Old Oct8-07, 12:42 AM                  #3
brien_rtb

brien_rtb is Offline:
Posts: 1
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
  Reply With Quote
Old Oct8-07, 03:46 PM                  #4
hotvette

hotvette is Offline:
Posts: 459
Recognitions:
Homework Helper Homework Helper
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?
  Reply With Quote
image image
Reply
Thread Tools


Similar Threads for: Quadratic bezier problem
Thread Thread Starter Forum Replies Last Post
quadratic equations and inequalities / applications of quadratic functions question ben328i Precalculus Mathematics 3 Nov19-07 04:58 PM
[SOLVED] Quadratic Equations and Inequalities question about properties of quadratic ben328i General Math 2 Nov18-07 04:09 PM
Bezier Plotting problem PerlTrader Differential Equations 0 May17-07 08:25 PM
Quadratic Problem dhris Calculus & Analysis 2 Dec7-03 04:26 AM

Powered by vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd. © 2009 Physics Forums
Sciam | physorgPhysorg.com Science News Partner
image
image   image