Sie sind auf Seite 1von 14

Bezier Curves and Surfaces

Published Apr 27 2002 08:57 PM in Graphics Programming and Theory By Jesper Tveit

Introduction
In this tutorial I will attempt to give you an understanding of a common way to make curved lines and surfaces. I will also give you some coding examples that will show you that it actually works. I will assume that you know how to use c++ in the coding examples. The coding examples also contain some OpenGL function calls, but they are commented and not too hard to understand. I will also assume that you know some basic math, but I'm starting off pretty easy by introducing parametric curves so you should be able to grasp it even if you don't have the greatest math knowledge. I have tested the coding examples, and I have looked over the text several times, so they should be fairly bug free. Still, if you find anything that looks like its wrong, let me know. You can find my email address at the bottom of the page.

Parametric curves
You are probably familiar with curves like y = x f(x)=xA parametric curve is or . similar to those, but the x- and y-values are calculated in separate functions. To do this we need another variable (I will call it a). So instead of f(x), we say X(a) and Y(a), where X(a) gives you an x-value for each value of a, and Y(a) gives you an corresponding yvalue for the same value of a. Here is an example: X(a) = a/2 Y(a) = a+5 If we substitute a with a number we can get a point that lies on the curve/line: a = 6 X(6) = 6/2 = 3 = x Y(6) = 6+5 = 11 = y We now know that (3,11) is a point on the curve. We can easily make a curve in 3D just by defining Z(a).

Bezier curves

Simple line

The simplest form is a straight line from a control point A, to a control point B. I will use Ax to denote the x-coordinate of control point A, and Ay to denote the ycoordinate. The same goes for B. I am introducing another variable, b, just to make it a bit more simple to read the functions. However, the variable b is only a in disguise, b is always equal to 1-a. So if a = 0.2, then b = 1-0.2 = 0.8. So when you see the variable b, think: (1-a). This parametric curve describes a line that goes from point A, to point B when the variable a goes from 1.0 to 0.0: X(a) = Axa + Bxb Y(a) = Aya + Byb Z(a) = Aza + Bzb If you set a = 0.5 (and thus also b = 0.5, since b = 1.0-a = 1.0-0.5 = 0.5) then X(a), Y(a) and Z(a) will give you the 3D coordinate of the point on the middle of the line from point A to point B. Note that the reason this works is because a + b is always equal to one, and when you multiply something with one, it will stay unchanged. This makes the curve behave predictably and lets you place the control points anywhere in the coordinate system, since when a = 1.0 then b = 0.0 thus making the point equal to one of the control points, and completely ignoring the other one.
Quadratic

Ok, now we have done lines, but what about curves? This: (a+b), where b = (1.0-a) is the key to everything. We know that a polynomial function is a curve, so why not try to make (a+b) a polynomial function? Let's try: (a+b) = a + 2ab + b Knowing that b=1-a we see that a 2 b + b still equal to one, since (a+b) = 1, and + a is 1 1. = We now need three control points, A, B and C, where A and C are the end points of the curve, and B decides how much and in which direction it curves. Except for that, it is the same as with the parametric line. X(a) = Axa + Bx2ab + Cxb Y(a) = Aya + By2ab + Cyb Z(a) = Aza + Bz2ab + Czb Still, if you set a = 0.5, then a 0.25, 2 b = 0.5 and b 0.25 giving the middle point, = a = B, the biggest impact and making point A and C pull equally to their sides. If you set a = 1.0, then a 1.0, a = 0.0 and b 0.0 meaning that result is the control point A itself, = b = just the same as setting a = 0.0 will return the coordinates of control point C.
Cubic

We can also increase the number of control points using (a+b) instead of (a+b)giving , you more control over how to bend the curve. (a+b) = a + 3ab + 3ab + b Now we need four control points A, B, C and D, where A and D are the end points. X(a) = Axa + Bx3ab + Cx3ab + Dxb Y(a) = Aya + By3ab + Cy3ab + Dyb Z(a) = Aza + Bz3ab + Cz3ab + Dzb It still works the same way as the previous ones, as a goes from 1.0 to 0.0 (and thus b from 0.0 to 1.0) the functions will return coordinates on a smooth line from control point A to control point D, curving towards B and C on the way. You can easily use (a+b) to the power of n and get n+1 control points (where n is any integer equal to, or greater than one). But remember that the more control points you have, the more work it is, both for you and for the computer. This might not seem like much when only talking about lines, but when it comes to surfaces it definitely has something to say. Personally I like the cubic ones best. You can easily make circles with them, and you can control the direction of the curve independently at each control point. Example of how to draw a cubic curve using OpenGL and C++:

this is how it will look (excluding the red lines and the letters)
// Control points (substitute these values with your own if you like) double Ax = -2.0; double Ay = -1.0; double Az = 1.0; double Bx = -1.0; double By = 3.0; double Bz = 1.0; double Cx = 1.0; double Cy = -3.0; double Cz = -1.0; double Dx = 2.0; double Dy = 1.0; double Dz = -1.0; // Points on the curve double X; double Y; double Z; // Variable

double a = 1.0; double b = 1.0 - a; // Tell OGL to start drawing a line strip glBegin(GL_LINE_STRIP); /* We will not actually draw a curve, but we will divide the curve into small points and draw a line between each point. If the points are close enough, it will appear as a curved line. 20 points are plenty, and since the variable goes from 1.0 to 0.0 we must change it by 1/20 = 0.05 each time */ for(int i = 0; i { // Get a point X = Ax*a*a*a + Y = Ay*a*a*a + Z = Az*a*a*a + <= 20; i++) on the curve Bx*3*a*a*b + Cx*3*a*b*b + Dx*b*b*b; By*3*a*a*b + Cy*3*a*b*b + Dy*b*b*b; Bz*3*a*a*b + Cz*3*a*b*b + Dz*b*b*b;

// Draw the line from point to point (assuming OGL is set up properly) glVertex3d(X, Y, Z); // Change the variable a -= 0.05; b = 1.0 - a; } // Tell OGL to stop drawing the line strip glEnd(); /* Normally you will want to save the coordinates to an array for later use. And you will probably not need to calculate the curve each frame. This code demonstrates an easily understandable way to do it, not necessarily the most useful way. */

Curved Surfaces

If you think of a line as 1D, and a surface as 2D, and understand that a square can be defined as length width, then you are not far from understanding that a curved bezier surface can be defined as a bezierCurve bezierCurve. This can be done with any (a+b) to the power of n -type curve (with n greater than or equal to one). I will demonstrate how to do this with the cubic one (n = 3). This defines our first cubic curve (leaving out the control points): (a+b) = a + 3ab + 3ab + b But now we need two, so here is the second one: (c+d) = c + 3cd + 3cd + c In the last one, d=1-c, just the same way that b=1-a in the first one. The next step is to multiply them by each other: (a + 3ab + 3ab + b)(c + 3cd + 3cd + d) = ac + 3acd + 3acd + ad + 3abc + 9abcd + 9abcd + 3abd + 3abc + 9abcd + 9abcd + 3abd + bc + 3bcd + 3bcd + bd This is still equal to one, since (a+b) 1, and (c+d) 1, and 1 = 1. = = 1 The cubic curves had four control points, so it makes sense that we get sixteen control points when we multiply two of them with each other. I'm calling the control points A, B, C, D, E, F, G, H, I, J, K, L, M, N, O and P. Here is how the functions will look when we multiply in the control points: X(a,c) = Axac + Bx3acd + Cx3acd + Dxad + Ex3abc + Fx9abcd + Gx9abcd + Hx3abd + Ix3abc + Jx9abcd + Kx9abcd + Lx3abd + Mxbc + Nx3bcd + Ox3bcd + Pxbd Y(a,c) = Ayac + By3acd + Cy3acd + Dyad + Ey3abc + Fy9abcd + Gy9abcd + Hy3abd + Iy3abc + Jy9abcd + Ky9abcd + Ly3abd + Mybc + Ny3bcd + Oy3bcd + Pybd Z(a,c) = Azac + Bz3acd + Cz3acd + Dzad + Ez3abc + Fz9abcd

+ + + + +

Gz9abcd + Hz3abd Iz3abc + Jz9abcd Kz9abcd + Lz3abd Mzbc + Nz3bcd Oz3bcd + Pzbd

The functions now have two variables: a and c. Passing values of a and c between 0 and 1 into the functions will give you a point on the surface. Remember that the values of a and c vary independently. Now you can draw a curved surface, but to make it look good it needs proper lighting. To do that we need normal vectors for each point on the surface that we want to draw. To find the normal vectors we will go through four steps. First we need to find the derivative with respect to a (remember that b has to be treated as (1-a), and that c and d remain untouched): XDA(a,c) = Ax3ac + Bx9acd + Cx9acd + Dx3ad + Ex3(2a-3a)c + Fx9(2a-3a)cd + Gx9(2a-3a)cd + Hx3(2a-3a)d + Ix3(1-4a+3a)c + Jx9(1-4a+3a)cd + Kx9(1-4a+3a)cd + Lx3(1-4a+3a)d + Mx3(2a-1-a)c + Nx9(2a-1-a)cd + Ox9(2a-1-a)cd + Px3(2a-1-a)d YDA(a,c) = Ay3ac + By9acd + Cy9acd + Dy3ad + Ey3(2a-3a)c + Fy9(2a-3a)cd + Gy9(2a-3a)cd + Hy3(2a-3a)d + Iy3(1-4a+3a)c + Jy9(1-4a+3a)cd + Ky9(1-4a+3a)cd + Ly3(1-4a+3a)d + My3(2a-1-a)c + Ny9(2a-1-a)cd + Oy9(2a-1-a)cd + Py3(2a-1-a)d ZDA(a,c) = Az3ac + Bz9acd + Cz9acd + Dz3ad + Ez3(2a-3a)c + Fz9(2a-3a)cd + Gz9(2a-3a)cd + Hz3(2a-3a)d + Iz3(1-4a+3a)c + Jz9(1-4a+3a)cd + Kz9(1-4a+3a)cd + Lz3(1-4a+3a)d + Mz3(2a-1-a)c + Nz9(2a-1-a)cd + Oz9(2a-1-a)cd + Pz3(2a-1-a)d If you are unfamiliar with derivation and think this seems very confusing then don't worry, this looks pretty confusing to anyone. The nice patterns we had have disappeared. Derivation is a complex theme so I will not explain it in depth here. Briefly though, the reason why we do this is that the derivative functions allow us to find tangent vectors on the surface, so later on we can use them to calculate the normal vectors.

The second step is to find the derivative with respect to c (this is easy, since we already have the recipe from the last one): XDC(a,c) = Ax3ac + Bx3a(2c-3c) + Cx3a(1-4c+3c) + Dx3a(-1+2c-c) + Ex9abc + Fx9ab(2c-3c) + Gx9ab(1-4c+3c) + Hx9ab(-1+2c-c) + Ix9abc + Jx9ab(2c-3c) + Kx9ab(1-4c+3c) + Lx9ab(-1+2c-c) + Mx3bc + Nx3b(2c-3c) + Ox3b(1-4c+3c) + Px3b(-1+2c-c) YDC(a,c) = Ay3ac + By3a(2c-3c) + Cy3a(1-4c+3c) + Dy3a(-1+2c-c) + Ey9abc + Fy9ab(2c-3c) + Gy9ab(1-4c+3c) + Hy9ab(-1+2c-c) + Iy9abc + Jy9ab(2c-3c) + Ky9ab(1-4c+3c) + Ly9ab(-1+2c-c) + My3bc + Ny3b(2c-3c) + Oy3b(1-4c+3c) + Py3b(-1+2c-c) ZDC(a,c) = Az3ac + Bz3a(2c-3c) + Cz3a(1-4c+3c) + Dz3a(-1+2c-c) + Ez9abc + Fz9ab(2c-3c) + Gz9ab(1-4c+3c) + Hz9ab(-1+2c-c) + Iz9abc + Jz9ab(2c-3c) + Kz9ab(1-4c+3c) + Lz9ab(-1+2c-c) + Mz3bc + Nz3b(2c-3c) + Oz3b(1-4c+3c) + Pz3b(-1+2c-c) Now we have a way to describe two tangent vectors on each point on the surface. This mean that we will be able to calculate the normal vector of any point on the surface. In general, if you have two vectors, V={vx, vy, vz} and U={ux, uy, uz} then those two vectors can be 'crossed' to produce a new vector N={nx, ny, nz} that is orthogonal to both V and U (Two vectors beeing orthogonal means that the angle between them are 90 ). This is how you cross two vectors V and U and put the result in N: nx = (vyuz)-(uyvz) ny = -((vxuz)-(uxvz)) nz = (vxuy)-(uxvy) This is normally refered to as V U=N You might have guessed what the third step is. Since we have two tangent vectors on the surface (the derived functions: {XDC, YDC, ZDC}, denoted by DC, and {XDA, YDA, ZDA} denoted by DA) we can obtain a normal vector (N={Nx, Ny, Nz}) like this: N = DA DC Which is equivalent to:

Nx = (YDAZDC)-(YDCZDA) Ny = -((XDAZDC)-(XDCZDA)) Nz = (XDAYDC)-(XDCYDA) The fourth step is to normalize the normal vectors (to normalize a vector means to make its length equal to one; in many cases it will be assumed that a normal vector has length equal to one). To normalize a vector we must first find the its length (L): L = sqrt(Nx+Ny+Nz) Then we divide it by its length to obtain a new vector (N' = {Nx',Ny',Nz'}) of length one: Nx'= Nx/L Ny'= Ny/L Nz'= Nz/L N' together with X(a,c), Y(a,c) and Z(a,c) give us all we need to make a smoothly shaded curved surface. Example of how to draw a curved surface using OpenGL and c++:

this is how it will look (excluding the red lines and the letters)
// Sixteen control points (substitute these values with your own if you like) double Ax = -2.0; double Ay = 2.0; double Az = 1.0; double Bx = -1.0; double By = 3.0; double Bz = -1.0; double Cx = 1.0; double Cy = 3.0; double Cz = 1.0; double Dx = 2.0; double Dy = 2.0; double Dz = -1.0; double double double double double double double double Ex Fx Gx Hx Ix Jx Kx Lx = -1.5; double Ey = = -0.5; double Fy = = 1.5; double Gy = = 2.5; double Hy = = -2.5; double Iy = = -1.5; double Jy = = 0.5; double Ky = = 1.5; double Ly = 1.0; 1.5; 1.5; 1.0; -1.0; -0.5; -0.5; -1.0; double double double double double double double double Ez Fz Gz Hz Iz Jz Kz Lz = 1.0; = -1.0; = 1.0; = -1.0; = 1.0; = -1.0; = 1.0; = -1.0;

double double double double

Mx Nx Ox Px

= -2.0; double My = = -1.0; double Ny = = 1.0; double Oy = = 2.0; double Py =

-2.0; -1.0; -1.0; -2.0;

double double double double

Mz Nz Oz Pz

= 1.0; = -1.0; = 1.0; = -1.0;

/* We will not actually draw a curved surface, but we will divide the surface into small quads and draw them. If the quads are small enough, it will appear as a curved surface. We will use a variable, detail, to define how many quads to use. Since the variables goes from 1.0 to 0.0 we must change them by 1/detail from vertex to vertex. We will also store the vertices and the normal vectors in arrays and draw them in a separate loop */ // Detail of 10 mean that we will calculate 1111 vertices int detail = 10; double change = 1.0 / (double)detail; // Vertices (maximum detail will now be 2020 quads) double Xv[21][21]; double Yv[21][21]; double Zv[21][21]; // Normal vectors double Xn[21][21]; double Yn[21][21]; double Zn[21][21]; // Just making sure that the detail level is not set too high if(detail > 20) { detail = 20; } // Variables double a = 1.0; double b = 1.0 - a; double c = 1.0; double d = 1.0 - c; // Tangent vectors double Xta; double Yta; double Zta; double Xtc; double Ytc; double Ztc; /* Since we have two variables, we need two loops, we will change the a-variable from 1.0 to 0.0 by steps of 1/detail ( = change), and for each step we loop the c-variable from 1.0 to 0.0, thus creating a grid of points covering the surface. Note that we could have had separate detail levels for the a-variable and the c-variable if we wanted to */ for(int i = 0; i <= detail; i++)

{ for(int j = 0; j <= detail; j++) { // First get the vertices Xv[i][j] = Ax*a*a*a*c*c*c + Bx*3*a*a*a*c*c*d + Cx*3*a*a*a*c*d*d + Dx*a*a*a*d*d*d + Ex*3*a*a*b*c*c*c + Fx*9*a*a*b*c*c*d + Gx*9*a*a*b*c*d*d + Hx*3*a*a*b*d*d*d + Ix*3*a*b*b*c*c*c + Jx*9*a*b*b*c*c*d + Kx*9*a*b*b*c*d*d + Lx*3*a*b*b*d*d*d + Mx*b*b*b*c*c*c + Nx*3*b*b*b*c*c*d + Ox*3*b*b*b*c*d*d + Px*b*b*b*d*d*d; Yv[i][j] = Ay*a*a*a*c*c*c + + Cy*3*a*a*a*c*d*d + Ey*3*a*a*b*c*c*c + Gy*9*a*a*b*c*d*d + Iy*3*a*b*b*c*c*c + Ky*9*a*b*b*c*d*d + My*b*b*b*c*c*c + Oy*3*b*b*b*c*d*d Zv[i][j] = Az*a*a*a*c*c*c + + Cz*3*a*a*a*c*d*d + Ez*3*a*a*b*c*c*c + Gz*9*a*a*b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*c) + Hx*9*a*a*b*(-1+2*c-c*c) + Jx*9*a*b*b*(2*c-3*c*c) + Lx*9*a*b*b*(-1+2*c-c*c) + Nx*3*b*b*b*(2*c-3*c*c) + Px*3*b*b*b*(-1+2*c-c*c); + By*3*a*a*a*(2*c-3*c*c) + Dy*3*a*a*a*(-1+2*c-c*c) + Fy*9*a*a*b*(2*c-3*c*c) + Hy*9*a*a*b*(-1+2*c-c*c) + Jy*9*a*b*b*(2*c-3*c*c) + Ly*9*a*b*b*(-1+2*c-c*c) + Ny*3*b*b*b*(2*c-3*c*c) + Py*3*b*b*b*(-1+2*c-c*c); + Bz*3*a*a*a*(2*c-3*c*c) + Dz*3*a*a*a*(-1+2*c-c*c) + Fz*9*a*a*b*(2*c-3*c*c) + Hz*9*a*a*b*(-1+2*c-c*c) + Jz*9*a*b*b*(2*c-3*c*c) + Lz*9*a*b*b*(-1+2*c-c*c) + Nz*3*b*b*b*(2*c-3*c*c) + Pz*3*b*b*b*(-1+2*c-c*c);

// Cross array // Note: (Xta*Ztc) Xn[i][j] Yn[i][j] Zn[i][j]

the tangent vectors, put the result to the normal vector I simplified -((Xta*Ztc)-(Xtc*Zta)) to (Xtc*Zta) = (Yta*Ztc) - (Ytc*Zta); = (Xtc*Zta) - (Xta*Ztc); = (Xta*Ytc) - (Xtc*Yta);

// Find length of normal vector double length = sqrt((Xn[i][j]*Xn[i][j])+(Yn[i][j] *Yn[i][j])+(Zn[i][j]*Zn[i][j])); // Normalize (and prevent divide by zero error) if(length > 0) { length = 1.0/length; Xn[i][j] *= length; Yn[i][j] *= length; Zn[i][j] *= length; } //change the c-variable within the inner loop c -= change; d = 1.0 - c; } //change the a-variable outside the inner loop a -= change; b = 1.0 - a;

// Reset the c-variable to make it ready for the inner loop again c = 1.0; d = 1.0 - c; } /* Now we have two arrays, one with vertices, and one with normal vectors, drawing them is straightforward if you know how to use a graphics API. Following is one way to do it using openGL and triangle strips. (assuming GL_LIGHTING etc.. has been properly set up) */ for(int m = 0; m < detail; m++) { glBegin(GL_TRIANGLE_STRIP); for(int n = 0; n <= detail; n++) { glNormal3d(Xn[m][n],Yn[m][n],Zn[m][n]); glVertex3d(Xv[m][n],Yv[m][n],Zv[m][n]); // Note that I used real-less-than in the first loop, since I want to // access the m+1 entry in the array to properly draw the triangle strip glNormal3d(Xn[m+1][n],Yn[m+1][n],Zn[m+1][n]); glVertex3d(Xv[m+1][n],Yv[m+1][n],Zv[m+1][n]); } glEnd(); }

Comment
Bezier curves do not necessarily have to be curves in 3D or 2D space, they might just as well be color curves (by substituting x,y,z coordinates with r,g,b values), curves in 4D space or anything else. Personally I find it useful to use a 2D bezier patch to calculate texture coordinates that fit on a 3D bezier surface.

Sources
Various web sites and my head ;)

Questions, comments, report mistakes etc.


My name: Jesper Tveit E-mail : 7396@online.no Website: http://7396.home.online.no/bw/ For background info, try a google search for "Etienne B zier"

That's it! Thanks for your attention

Das könnte Ihnen auch gefallen