Any royal road to Bezier curves...?

Scott David Daniels scott.daniels at acm.org
Wed Nov 23 12:43:01 EST 2005


Warren Francis wrote:
> For my purposes, I think you're right about the natural cubic splines. 
> Guaranteeing that an object passes through an exact point in space will be 
> more immediately useful than trying to create rules governing where control 
> points ought to be placed so that the object passes close enough to where I 
> intended it to go.  Thanks for the insight, I never would have found that on 
> my own.  At least not until Google labs comes out with a search engine that 
> gives names for what you're thinking of. ;-)
> 
> I know this is a fairly pitiful request, since it just involves parsing your 
> code, but I'm new enough to this that I'd benefit greatly from an couple of 
> lines of example code, implementing your classes... how do I go from a set 
> of coordinates to a Natural Cubic Spline, using your python code?
> 
> Thanks for all the help, everybody!
> 
> Warren
> 
> "Tom Anderson" <twic at urchin.earth.li> wrote in message 
> news:Pine.LNX.4.62.0511212322010.29591 at urchin.earth.li...
> 
>>On Mon, 21 Nov 2005, Tom Anderson wrote:
>>
>>
>>>On Sun, 20 Nov 2005, Warren Francis wrote:
>>>
>>>
>>>>Basically, I'd like to specify a curved path of an object through space. 
>>>>3D space would be wonderful, but I could jimmy-rig something if I could 
>>>>just get 2D...  Are bezier curves really what I want after all?
>>>
>>>No. You want a natural cubic spline:
>>
>>In a fit of code fury (a short fit - this is python, so it didn't take 
>>long), i ported my old java code to python, and tidied it up a bit in the 
>>process:
>>
>>http://urchin.earth.li/~twic/splines.py
>>
>>That gives you a natural cubic spline, plus my blended quadratic spline, 
>>and a framework for implementing other kinds of splines.
>>
>>tom
>>
>>-- 
>>Gin makes a man mean; let's booze up and riot! 
> 
> 
> 
Half the points on a cubic Bezier curve are knots -- points through
which the curve must pass.  If you have four points for a bezier:
          a
                    d
            b     c

Then the curve must pass through a and d, and it should be tangent
to a-b at a, and tangent to c-d at d.  All parts of the curve must lie
within the convex hull of a-b-c-d (that is, the largest quadrilateral
with those four corners).  It is simple to subdivide a bezier curve into
a pair that produce the same curve (so you can cut them nicely).  If you
connect two curves together, the tangent requirement is enough to make the
joint look smooth:

        a           e      f
                 d
          b    c           g

In this diagram, there are two curves: a-b-c-d and d-e-f-g.  If c-d-e is
a line, then the connection will look smooth.

This is why it is so easy to work with beziers, lots of properties make
visual sense.  In fact I've even used the bezier algorithm to control
not only x, y, and z, but also r, g, and b.  Controlling all six, I can
enforce smooth controllable color transitions that I can even tweak to
satisfy my visual aesthetic.  The convex hull property guarantees me
that all colors will exit.  Knots-only systems go outside the hulls,
so colors don't make as much sense.

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list