PDA

Click to See Complete Forum and Search --> : Determine Bezier control points


series001
Aug 2nd, 2007, 10:48 AM
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

VBAhack
Aug 2nd, 2007, 11:31 AM
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.

series001
Aug 2nd, 2007, 12:03 PM
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.

VBAhack
Aug 2nd, 2007, 03:04 PM
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:

┌ ┐ ┌ ┐ ┌ ┐
│-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. :thumb:
.

series001
Aug 2nd, 2007, 11:25 PM
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...

VBAhack
Aug 3rd, 2007, 12:03 PM
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.

series001
Aug 4th, 2007, 09:13 AM
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?

VBAhack
Aug 6th, 2007, 12:23 PM
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?

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.

VBAhack
Aug 6th, 2007, 12:42 PM
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):

┌ ┐ ┌ ┐ ┌ ┐
│ 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):

┌ ┐ ┌ ┐ ┌ ┐
│ 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:

┌ ┐ ┌ ┐ ┌ ┐
│-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│
└ ┘ └ ┘ └ ┘

series001
Aug 8th, 2007, 09:15 PM
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.

VBAhack
Aug 9th, 2007, 01:23 AM
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.
:)