Results 1 to 11 of 11

Thread: Determine Bezier control points

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Determine Bezier control points

    Is there a way to determine the control points of a bezier curve that passes through 4 points? The points are (0,0), (1,1), (8,2) and (27,3). From the points we can know the curve is y = (x)^(1/3), but how do we plot in Bezier curves? Also the curves must be C1 continuous. I really appreciate any help. thx in advance

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Determine Bezier control points

    Welcome to the forums!

    Hmm, sounds interesting. Need more info, though:

    1. Do you want a single Bezier segment through all 4 points or 3 segments joined together, each connecting 2 points?

    2. What order Bezier? Cubic?


    I believe a single cubic Bezier can be constructed through the 4 points.
    Last edited by VBAhack; Aug 2nd, 2007 at 10:35 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: Determine Bezier control points

    1. It should be 3 segments, from 0<x<1, 1<x<8, 8<x<27.
    2. Use either quadratic or cubic. Example from point (0,0) to (1,1) which are the endpoints, we need to find another control point in between to draw the quadratic bezier. If use cubic need to find 2 control points which is the problem.

  4. #4
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Determine Bezier control points

    Quote Originally Posted by series001
    Is there a way to determine the control points of a bezier curve that passes through 4 points?
    Sure there is. If you follow the Parametric Cubic Spline tutorial link in my signature, you can find the coefficients of 3 parametric cubic splines. However, use a different method of determining the independent variable s. Instead of using the distance between points, just use s1 = 0, s2 = 1, s3 = 2 and s4 = 3 and don't scale them. The net result of this is that each parametric cubic spline segment will have (s-s0) varying from 0 to 1, which is what you want for Bezier segments. In fact, I think I'll modify the tutorial to do it this way.

    After you have the spline coefficients for each segment, use the following well known relation for cubic Bezier curves:
    Code:
    ┌          	┐ ┌        ┐  ┌      ┐
    │-1   3  -3   1	│ │p0x  p0y│  │ax  ay│
    │ 3  -6   3   0	│ │p1x  p1y│= │bx  by│ 
    │-3   3   0   0	│ │p2x  p2y│  │cx  cy│
    │ 1   0   0   0	│ │p3x  p3y│  │dx  dy│
    └         	┘ └        ┘  └      ┘
    Where the ax, etc. are the coefficients of the cubic splines:

    x = f1(s) = ax(s-s0)3 + bx(s-s0)2 + cx(s-s0) + dx
    y = f2(s) = ay(s-s0)3 + by(s-s0)2 + cy(s-s0) + dy

    Just solve the matrix equation for pix and piy , which are the Bezier control points. There are perhaps other (easier) ways, but this works.
    .
    Attached Images Attached Images  
    Last edited by VBAhack; Aug 2nd, 2007 at 03:56 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: Determine Bezier control points

    Quote Originally Posted by VBAhack

    x = f1(s) = ax(s-s0)3 + bx(s-s0)2 + cx(s-s0) + dx
    y = f2(s) = ay(s-s0)3 + by(s-s0)2 + cy(s-s0) + dy

    .
    I'm sorry i do not understand this formula. Does this formula also apply to quadratic Bezier? Is there any other method? Thanks a lot for your help by the way...

  6. #6
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Determine Bezier control points

    It's just a variation of the classic form of a 3rd order Bezier. If you look in Wikipedia:

    http://en.wikipedia.org/wiki/B%C3%A9zier_curve

    B(t) = (1-t)3P0 + 3t(1-t)2P1 + 3t2(1-t)P2 + t3P3

    Where P0, P1, P2, P3 are the Bezier control points and t is the independent variable. Since P0 = (x0,y0), P1 = (x1,y1), P2 = (x2,y2), P3 = (x3,y3), the above equation is just a compact way of expressing the 2 defining equations for a cubic Bezier:

    x(t) = (1-t)3x0 + 3t(1-t)2x1 + 3t2(1-t)x2 + t3x3
    y(t) = (1-t)3y0 + 3t(1-t)2y1 + 3t2(1-t)y2 + t3y3

    If you were to expand and collect terms, the equations can be represented in the following form:

    x(t) = axt3 + bxt2 + cxt + dx
    y(t) = ayt3 + byt2 + cyt + dy

    where:

    ax = -x0 + 3x1 - 3x2 + x3
    bx = 3x0 – 6x1 + 3x2
    cx = -3x0 + 3x1
    dx = x0

    ay = -y0 + 3y1 – 3y2 + y3
    by = 3y0 – 6y1 + 3y2
    cy = -3y0 + 3y1
    dy = y0

    What I stated was just a more generalized version, and I used s instead of t as the independent variable. Hope this helps.
    Last edited by VBAhack; Aug 3rd, 2007 at 11:16 AM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: Determine Bezier control points

    Oh now i see something. In fact, i've gone through your tutorial and i got stucked at this matrix

    ┌ ┐ ┌ ┐ ┌ ┐
    │1 0 0 0 │ │y1" │ │ 0 │
    │1 4 1 0 │ │y2" │ = 6/(h*h) │ y3 - 2y2 + y1 │
    │ 0 1 4 1 │ │y3" │ │ y4 - 2y3 + y2 │
    │ 0 0 0 1 │ │y4" │ │ 0 │
    └ ┘ └ ┘ └ ┘

    and to find the coefficients,
    a1 = (y2"-y1")/6h1
    b1 = y1"/2
    c1 = (y2-y1)/h1 – y2"h1/6 – y1"h1/3
    d1 = y1?

    So where is that y4 and y4" coming from? Are my equations correct?

  8. #8
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Determine Bezier control points

    Quote Originally Posted by series001
    Oh now i see something. In fact, i've gone through your tutorial and i got stucked at this matrix
    Code:
    ┌		┐ ┌   ┐           ┌             ┐
    │ 1   0   0   0	│ │y1"│           │      0      │
    │ 1   4   1   0	│ │y2"│ = 6/(h*h) │y3 - 2y2 + y1│
    │ 0   1   4   1	│ │y3"│           │y4 - 2y3 + y2│
    │ 0   0   0   1	│ │y4"│           │      0      │
    └        	┘ └   ┘           └             ┘
    Quote Originally Posted by series001
    and to find the coefficients,
    a1 = (y2"-y1")/6h1
    b1 = y1"/2
    c1 = (y2-y1)/h1 – y2"h1/6 – y1"h1/3
    d1 = y1?

    So where is that y4 and y4" coming from? Are my equations correct?
    I'm not sure I understand the question. The above equation represents a case where you have 4 points (x1,y1), (x2,y2), (x3,y3), (x4,y4) and equal spacing of the points. You already provided the 4 points, so you know y4. Re y4", that's an unknown (along with y1", y2", y3") that are determined by the solution of the above equation. Note: in the case of natural boundary conditions, y1" and y4" are zero.

    Maybe you need to word your question another way.
    Last edited by VBAhack; Aug 6th, 2007 at 11:26 AM.

  9. #9
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Determine Bezier control points

    Maybe this will help.

    1. The 4 points to be fit are (x1,y1)=(0,0), (x2,y2)=(1,1), (x3,y3)=(8,2), (x4,y4)=(27,3)

    2. Pick values of the independent parameter, s. For convenience, I suggested picking s = (0,1,2,3). This means h1=h2=h3=h=1, allowing the simplified equations to be used.

    3. The sets of points to fit result in one equation for (s1,x1), (s2,x2), (s3,x3), (s4,x4) and a second equation for (s1,y1), (s2,y2), (s3,y3), (s4,y4)

    4. Choose boundary conditions for x1", x4", y1", y4". If natural boundary are chosen, all of these are zero.

    5. Solve the following matrix equation for xi" (Note assumes natural boundary conditions):
    Code:
    ┌		┐ ┌   ┐           ┌             ┐
    │ 1   0   0   0	│ │x1"│           │      0      │
    │ 1   4   1   0	│ │x2"│ = 6/(h*h) │x3 - 2x2 + x1│
    │ 0   1   4   1	│ │x3"│           │x4 - 2x3 + x2│
    │ 0   0   0   1	│ │x4"│           │      0      │
    └        	┘ └   ┘           └             ┘
    6. Solve the following matrix equation for yi" (Note assumes natural boundary conditions):
    Code:
    ┌		┐ ┌   ┐           ┌             ┐
    │ 1   0   0   0	│ │y1"│           │      0      │
    │ 1   4   1   0	│ │y2"│ = 6/(h*h) │y3 - 2y2 + y1│
    │ 0   1   4   1	│ │y3"│           │y4 - 2y3 + y2│
    │ 0   0   0   1	│ │y4"│           │      0      │
    └        	┘ └   ┘           └             ┘
    7. Calculate the parametric cubic polynomial coefficients for each segment (ax, bx, cx, dx, ay, by, cy, dy) using the results of 1,2,5,6. For example, ay,by,cy,dy for segment 1 would be:

    a1 = (y2"-y1")/6h1
    b1 = y1"/2
    c1 = (y2-y1)/h1 – y2"h1/6 - y1"h1/3
    d1 = y1

    There is a similar one for ax,bx,cx,dx for the 1st segment. Repeat for each of the 3 segments.

    8. Calculate the Bezier control points (p0x,p0y), (p1x,p1y), (p2x,p2y), (p3x,p3y) for each segment using the following relation:
    Code:
    ┌          	┐ ┌        ┐  ┌      ┐
    │-1   3  -3   1	│ │p0x  p0y│  │ax  ay│
    │ 3  -6   3   0	│ │p1x  p1y│= │bx  by│ 
    │-3   3   0   0	│ │p2x  p2y│  │cx  cy│
    │ 1   0   0   0	│ │p3x  p3y│  │dx  dy│
    └         	┘ └        ┘  └      ┘
    Last edited by VBAhack; Aug 6th, 2007 at 12:35 PM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    Re: Determine Bezier control points

    So we need to assume the boundary conditions first in order to find the coefficients. Now i know how to solve it, thanks a lot.

  11. #11
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Determine Bezier control points

    Quote Originally Posted by series001
    So we need to assume the boundary conditions first in order to find the coefficients. Now i know how to solve it, thanks a lot.
    Yep, choosing end point boundary conditions are a necessary part of spline interpolation, whether standard or parametric. And, you are welcome.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width