1

Given the following path: alt text http://img198.imageshack.us/img198/3692/curve.png

How could these smooth curves be generated given that the user provides the points and that cubic bezier is used? How would the control points or bezier handles be solved for, or how could I compute these points using cubic bezier given the user points above (the red squares) ? Basically I have an algorithm to solve for a cubic bezier curve given 4 points but the user only provides the points below so there are no control points, how do I obtain these?

Thanks

sbi
  • 219,715
  • 46
  • 258
  • 445
jmasterx
  • 52,639
  • 96
  • 311
  • 557

2 Answers2

3

Look up Catmull-Rom splines. Here's an introduction.

Further reading:

Community
  • 1
  • 1
Chris Dennett
  • 22,412
  • 8
  • 58
  • 84
  • But this does not give me a way to solve for the 4 points, I want to solve for the bezier handles, not use a different algorithm since the rest of my application uses cubic bezier – jmasterx Jul 24 '10 at 04:15
  • Oh, this is basically Catmull-Rom to Bezier then. Some discussion is here: http://processing.org/discourse/yabb2/YaBB.pl?num=1212123950 – Chris Dennett Jul 24 '10 at 04:21
  • How do you handle cases where the whole path is less than 4 points or not a multiple of 4? – jmasterx Jul 24 '10 at 04:32
  • As long as you have properly-defined catmull-rom control points (you only need a few and it works, your example has around 16, I haven't counted), you can always convert to bezier control points (as per the example in the comment), or am I missing something? :) – Chris Dennett Jul 24 '10 at 05:01
  • Would it look decent if instead of this I simply used cubic bezier where P0 is the first point, P1 is the second etc..., this would effectivly divide my number of points by 2... – jmasterx Jul 24 '10 at 05:05
  • @ChrisDennett the link is dead :( – Emperor Orionii Apr 23 '13 at 13:45
0

See http://en.wikipedia.org/wiki/Spline_interpolation#Cubic_spline_interpolation

lhf
  • 70,581
  • 9
  • 108
  • 149