Quadratic bezier problem

  • Context: Graduate 
  • Thread starter Thread starter makc
  • Start date Start date
  • Tags Tags
    Quadratic
Click For Summary

Discussion Overview

The discussion revolves around the challenge of creating smooth curves connecting multiple points using quadratic Bezier splines in flash scripting. Participants explore methods to calculate control points for these splines, aiming for a visually appealing curve similar to Catmull-Rom splines.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the use of the quadratic Bezier spline formula and the "curveTo" command in flash, expressing a desire to connect N points smoothly using N-1 segments.
  • The same participant initially attempts to derive control points based on the derivatives of the segments but finds that the control points behave erratically.
  • Another participant suggests that simply equating derivatives does not adequately constrain the curve's shape, noting that cardinal splines impose directionality constraints on the curve.
  • This second participant proposes using two quadratic segments per curve segment to introduce more control points, which could help achieve a smoother curve while maintaining the desired shape.
  • A later reply requests specific x,y values to better understand the problem, indicating a need for more concrete data to assist in the discussion.

Areas of Agreement / Disagreement

Participants express differing views on the constraints necessary for achieving smooth curves with quadratic splines. There is no consensus on the best approach to calculate the control points or on the effectiveness of the proposed methods.

Contextual Notes

Participants acknowledge the complexity of the problem, particularly in balancing the number of constraints with the available control points. The discussion highlights the challenges of fitting curves in two dimensions while addressing the limitations of quadratic segments.

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?
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K