Loading ...
Sorry, an error occurred while loading the content.

Re: Calculating cubic Bezier curve peaks?

Expand Messages
  • a_matseevsky
    ... could ... Given ... yi,...,xn,yn ... on ... to ... the ... Dear Bruce, a lot depends on what sort of result do you wanna get. I believe, you wanna
    Message 1 of 9 , Apr 3, 2008
    • 0 Attachment
      --- In svg-developers@yahoogroups.com, "brucerindahl" <rindahl@...>
      wrote:
      >
      > Frank
      > This is great info. Thank you! I have always wondered if there
      could
      > be an easy generic way of smoothing a line using Bezier curves.
      Given
      > a series of points on a line segment x0 y0, x1 y1,...,xi
      yi,...,xn,yn
      > could a series of control points be computed? The control points
      on
      > either side of a vertex would have to be co-linear with the vertex
      to
      > assure the first derivative is continuous and equal distance from
      the
      > vertex to make the second derivative continuous. The wall I always
      > ran into was how to set the initial (or final) control point and an
      > easy direct iteration calculation for the remaining points. Do you
      > have any ideas on this?
      > Thanks!
      > Bruce Rindahl
      >

      Dear Bruce, a lot depends on what sort of result do you wanna get. I
      believe, you wanna transform each link of your source polyline to
      one link of Bezier curve. If so, you need to place two control poits
      into each link of the source polyline. For similar task I use the
      next code:

      void Contur::Set_sin_cos_for_line() {
      double dx1, dy1, s1, dx2, dy2, s2;
      dx1=xw[1].x-xw[0].x;
      dy1=xw[1].y-xw[0].y;
      s1=sqrt(dx1*dx1+dy1*dy1);
      dx2=xw[2].x-xw[1].x;
      dy2=xw[2].y-xw[1].y;
      s2=sqrt(dx2*dx2+dy2*dy2);
      eFirst.X=s2*dx1*(s2+2*s1)-s1*s1*dx2;
      eFirst.Y=s2*dy1*(s2+2*s1)-s1*s1*dy2;
      s1=sqrt(eFirst.X*eFirst.X+eFirst.Y*eFirst.Y);
      // if(s1==0)
      // s1=s1;
      eFirst.X=eFirst.X/s1;
      eFirst.Y=eFirst.Y/s1;

      dx1=xw[n-1].x-xw[n-2].x;
      dy1=xw[n-1].y-xw[n-2].y;
      s1=sqrt(dx1*dx1+dy1*dy1);
      dx2=xw[n-2].x-xw[n-3].x;
      dy2=xw[n-2].y-xw[n-3].y;
      s2=sqrt(dx2*dx2+dy2*dy2);
      eLast.X=s2*dx1*(s2+2*s1)-s1*s1*dx2;
      eLast.Y=s2*dy1*(s2+2*s1)-s1*s1*dy2;
      s1=sqrt(eLast.X*eLast.X+eLast.Y*eLast.Y);
      // if(s1==0)
      // s1=s1;
      eLast.X=eLast.X/s1;
      eLast.Y=eLast.Y/s1;
      }

      Here xw[k] is the source set of coordinates (my xw[0].x is your x0,
      my xw[0].y is your y0 and so on. The last my point has a number n-1,
      so xw[n-1].x is your xn). you may use eFirst to place the first
      control point P1: as so:

      P1.x=xw[0].x+r*eFirst.X, P1.y=xw[0].y+r*eFirst.Y;
      r=0.33*sqrt((xw[1].x-xw[0].x)*(xw[1].x-xw[0].x)+
      (xw[1].y-xw[0].y)*(xw[1].y-xw[0].y));

      For the last you should use ananlogue (Pn.x=xw[n-1].x+r*eLast.X or
      may be Pn.x=xw[n-1].x-r*eLast.X, I do not remember now)

      Andrew
    • Frank Bruder
      This is something I wanted to implement for quite a while. And now I finally did. Go to http://frankbruder.fr.ohost.de/FeSVGDoc/ and click at Spline
      Message 2 of 9 , Apr 5, 2008
      • 0 Attachment
        This is something I wanted to implement for quite a while. And now I
        finally did.
        Go to
        http://frankbruder.fr.ohost.de/FeSVGDoc/
        and click at "Spline interpolator"

        enjoy!

        I'd actually like to integrate this functionality into my path data
        editor, but that won't happen before next time I rewrite the whole
        editor.

        I also have another idea for how to use cubic splines in a way which
        would simplify the task of creating smooth curves. Well, I can work
        on that when I'm not satisfied with the spline interpolator's results.

        Cheers

        Frank
      • Ken Coar
        ... So the y-coordinates of the curve are related only to the y-coordinates of the control points? A curve with control points at particular y-coordinates
        Message 3 of 9 , Apr 6, 2008
        • 0 Attachment
          --- In svg-developers@yahoogroups.com, "Frank Bruder" <redurbf@...> wrote:
          >
          > Changing the amplitude is easy. That is done by just scaling
          > the y-coordinates of the control points by the same factor
          > by which you wish to scale the amplitude.

          So the y-coordinates of the curve are related only to the
          y-coordinates of the control points? A curve with control points
          at particular y-coordinates will always result in extrema
          (modulo the existence of them in the first place) of the same
          y-amplitude, regardless of changes in the x-coordinates of
          the control points?
        • Frank Bruder
          ... Yes. That is true.
          Message 4 of 9 , Apr 9, 2008
          • 0 Attachment
            --- In svg-developers@yahoogroups.com, "Ken Coar" <Ken@...> wrote:
            >
            > So the y-coordinates of the curve are related only to the
            > y-coordinates of the control points? A curve with control points
            > at particular y-coordinates will always result in extrema
            > (modulo the existence of them in the first place) of the same
            > y-amplitude, regardless of changes in the x-coordinates of
            > the control points?
            >

            Yes. That is true.
          Your message has been successfully submitted and would be delivered to recipients shortly.