Home > Degrafa > Degrafa Cubic Bezier Y at X Update

Degrafa Cubic Bezier Y at X Update

January 21, 2009

A small issue was recently fixed in the cubic Bezier y at x method, so you should upate the code base from SVN.  The following screen shot illustrates the correction.

Cubic Bezier y at x

Cubic Bezier y at x

A few people have asked about the algorithm.  Given x=a, the y-values at the specified x-coordinate occur at t-parameters where x(t) = a, t in [0,1].  The polynomial coefficients are computed, so that x(t) = c0*t + c1*t + c2*t^2 + c3*t^3.  The problem then reduces to finding zeros of the continuous function f(t) = x(t)-a=0.  Since this is a cubic, one root is found by any method.  Then, the factor theorem is used to factor out the root using synthetic division.  Any remaining roots are from a quadratic polynomial.  These can be computed directly using the quadratic formula.

With a non-looping Bezier, there is generally a recognizable root in [0,1]; that is f(0)*f(1) < 0 .  With curves that loop like the one above, bisection is often required to identify intervals with a root.  A typo was made when porting the internal bisection code from Singularity to Degrafa.  Thanks to the poster who identified the issue and I hope this gives you some insight into the method of approach.

  1. January 25, 2009 at 9:41 am

    Hi,
    I’m having a hard time trying to mimic the Illustrator pencil-tool behaviour. Do you see a way to do this with Degrafa, and if it’s not too unpolite, could you provide some hints on it?

    Thanks in advance! Really appreciating all the goods you’re creating.

  2. January 25, 2009 at 5:22 pm

    I’m not familiar with Illustrator – are you talking about line smoothing in an interactive drawing?

    thanks,

    – jim

  3. January 26, 2009 at 12:37 am

    Interactive drawing. When you use the pencil tools, it adds a dot on the position of the cursor on every mousemove event. Then it removes “unnecessary” dots and leaves only those needed to resemble the line as a sum of cubic bezier curves (in order to be able to edit the line afterwards), where the dots left become anchor points, and the control points are determined on the base fo the removed dots (I guess).
    My actual problem is how to determine the anchor points. Trying to use a BezierSpline, setting the coordinates of all the initial dots to its data property, then altered the class so the _beziers property becomes protected for me to be able to access it in a subclass (It’s probably worth adding a getter for it). But then I’m stuck. I tried also determining the x and y peaks on parts of the dotted line, and use them as anchor points, but didn’t make it and an inner feeling tells me that’s not the right way.

    Thank you for taking the time to read this and any hints would be greatly appreciated!

  4. January 26, 2009 at 7:33 am

    Sounds like what you want is line generalization, for which there is ample information in the open literature. You might want to start here for something in Flash,

    http://www.motiondraw.com/md/as_samples/t/LineGeneralization/demo.html

    regards,

    – jim

  5. January 26, 2009 at 8:24 am

    Thanks a bunch!

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: