You are on page 1of 46

4.

Curve Generation method

Steven Harrington
Hearn & Baker

1
2
• WE have discussed about the basic primitive
object like line,circle,ellipse etc
However, graphics packages allow user to draw
any regular and irregular shaped object like
curves.
A curve is formed by joining a number of small
straight lines segment in a manner such that
smooth curve is produced. Here in this chapter
we will dealing with the methods used for the
curve generation in the graphics packages
The widely used method for curve generation are
Bezier and B-spline curve method
3
• Important properties for designing curves.
Control points : The control points are the points
,which control the shape of the curve in a
predictable manner.
Multiple value :A curve is said to be multivalued
w.r.t all coordinate system.
Axis independent :The curve must be
independent of the coordinate system for the
measurement of control points
Variation Diminishing property: The curves
tend to smooth out any irregularities present in
their shape.
4
• Versatility : A curve representation must allow
a verity of shape to the designer. It allows no of
shape (depending on the location of the control
point)
• Order of continuity : A complex shape is
usually modeled by joining several single
curves together end to end .
The order of continuities are –
zero order continuity : is formed when two curve just
meet .
First order continuity: is formed when the two curves
are tangent at the point of intersection
Second order continuity: is formed when the curve are
formed as a result of join operation.
5
• Bezier curves :The French engineer Bezier
developed this method of curve generation. He used
method first for the design of automobiles bodies.
This method generates an approximating curve formed
out of sequence of polynomial function generated
using a set of control points.
The equation of Bezier curve is as follows –
For n+1 control points ,represented as vectors
Pi = ( xi, yi, zi) for 0≤ i ≤ n
n
Bezier curve P(u) is defined as P(u)=∑ PiBi,n(u)…... (1)
i=0

6
• Where PiBi,n(u) is a bending function, such that

PiBi,n(u)=C(n,i) u i(1-u)n-i where 0≤ u ≤ 1


and C(n,i) is the binomial function coefficient
such that
C(n,i)=n! /( i! (n-i)! )

Equation (1) is a vector equation; it could be


expressed by writing equating for the x, y and z
parametric function separately.

7
n
X(u)=∑ xiBi,n(u) …………….[a]
i=0
n
Y(u)=∑ YiBi,n(u) …………….[b]
i=0
n
Z(u)=∑ ZiBi,n(u) …………….[c]
i=0
Bi,n(u) are called blending function .
8
9
• Properties of Bezier curves :

A very useful property of Bezier curve is that it


always passes through the first and last
control points P(0)=P0 P(1)=Pn

Another important property of Bezier curves is


that it lies within the convex hull of control
point .This follows from the properties of
Bezier blending function :They are all
positive and their sum is always 1.
10
• Example: Derive the parametric equation for a
cubic Bezier curve. For n=3
n
P(u)=∑ PiBi,n(u) 1 eqn
i=0
3
P(u)=∑ PiBi,3(u)
i=0

P(u)=P0B0,3(u)+P1B1,3(u)+P2B2,3(u)+P3B3,3(u)
11
• B0,3(u)= C03 t0 (1-t)3-0

= 3!/0!(3-0)! t0 (1-t)3

=3x2x1 /1x(3x2x1)(1) (1-t)3


= (1-t)3

• B1,3(u)= C13 t1 (1-t)3-1

= 3!/1!(3-1)! t1 (1-t)2
12
• B2,3(u)= C23 t2 (1-t)3-2
= 3!/2!(3-2)! t2 (1-t)1
=3x2x1 /(2x1)(1) t2 (1-t)1
=3t2(1-t)
B3,3(u)= C33 t3 (1-t)3-3
= 3!/3!(3-3)! t3 (1-t)0
=3x2x1 /(3x2x1) t3 (1-t)0
=t3

• P(u)=P0(1-t)3+P1 3t(1-t)2+P2 3t2(1-t)+P3 t3


13
14
15
16
17
18
19
20
• #include <stdio.h> #include <stdlib.h> #include <graphics.h>
• #include <math.h>  
void bezier (int x[4], int y[4])
{ int gd = DETECT, gm; Int i; double t;  
initgraph (&gd, &gm, "..\\bgi");  
for (t = 0.0; t < 1.0; t += 0.0005)
{

double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2) * x[1] + 3 * pow (t, 2)


* (1-t) * x[2] + pow (t, 3) * x[3];  

double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-t, 2) * y[1] + 3 * pow (t, 2)


* (1-t) * y[2] + pow (t, 3) * y[3];  

putpixel (xt, yt, WHITE);


Cont…………
for (i=0; i<4; i++)
putpixel (x[i], y[i], YELLOW);  
getch();
closegraph();
return;
}   void main()
{
int x[4], y[4]; int i;  
printf ("Enter the x- and y-coordinates of the four control
points.\n");
for (i=0; i<4; i++)
scanf ("%d%d", &x[i], &y[i]);  
bezier (x, y);
} End Program
• C program for Bezier curve :
int control [10][2]
float x[200],y[200]
float com_coeff(int n ,int i)
{
Int k;
Float coeff;
Coeff =1.0;
For(k=i+1;k<=n;k++)
{
Coeff=coeff * (float) k;
For ((k=2;k<=n-i;k++)
Coeff=coeff / (float) k; } return (coeff);
} cont…. 23
• float blend_value(int n,int I,float u)
{
int k;
float b;
b=com_coeff(n,i);
For(k=1;k<=I;k++)
{
B=b*u;
}
For (k=1;k<=n-I;k++)
{b=b*(1-u);
}
Return(b);
} cont…..
24
Void bezier (int n,int j,float u)
{
Int I;
float blend;
x[j]=0.0;
Yyj]=0.0
for(i=0;i<=n;i++)
{
blend= blend_value(n,I,u);
x[j]=x[j]+(float)control[i][0]*blend;
y[j]=y[j]+(float)control[i][1]*blend;
}} cont….
25
void main() (int n,int m)
{
int j;
float u;
for (j=0;j<=m;j++)
{
U=((float) j / (float)m);
Bezier(n,u,j);
Put pixel (int x[j], int y[j], WHITE);
}
} End Bezier
26
• B-Spline and surfaces :
These are the most widely used class of
approximating splines.B-spline have two
advantage over Bezier spline
1. The degree of a B- Spline polynomial can be
set independently of the number of control
points
2. B-spline allow local control over the shape of
a spline curve or surface. The trade off is that
B-splines are more complex than Bezier
splines
27
• We can write a general expression for the
calculation of coordinate positions along B-
spline curve in a blending function formulation
as
n
P(u)=∑ PkBk,d(u) umin ≤ u ≤ umax
i=0 2 ≤ d ≤ n+1
Where Pk are an input set of n+1 control point
Bk,d are polynomials of degree d-1 where d is
integer value in the range from 2 up to the no
of control points
28
• The blending function for B-spline curves are
defined by Cox-deBoor recursion formulas:

Bk,1(u)= {1 if uk ≤u ≤uk+1
{0 Otherwise

Bk,d(u)=u-uk Bk,d-1(u)+ uk+d-u Bk+1,d-1(u)


uk+d-1-uk uk+d-u- uk+1

29
B-splines
• B-splines automatically take care of continuity, with
exactly one control vertex per curve segment
• Many types of B-splines: degree may be different (linear,
quadratic, cubic,…) and they may be uniform or non-
uniform
– We will only look closely at uniform B-splines
• With uniform B-splines, continuity is always one degree
lower than the degree of each curve piece
– Linear B-splines have C0 continuity, cubic have C2, etc
Uniform Cubic B-spline on [0,1)
• Four control points are required to define the curve for 0≤t<1 (t is
the parameter)
– Not surprising for a cubic curve with 4 degrees of freedom
• The equation looks just like a Bezier curve, but with different
basis functions
– Also called blending functions - they describe how to blend the
control points to make the curve
Basis Functions on [0,1)
• Does the curve interpolate its
endpoints?
B1, • Does it lie inside its convex
B2, hull?
4
4

B0, B3,
4 4
Uniform Cubic B-spline on [0,1)
• The blending functions sum to one, and are positive everywhere
– The curve lies inside its convex hull
• The curve does not interpolate its endpoints
– Requires hacks or non-uniform B-splines
• There is also a matrix form for the curve:
Uniform Cubic B-splines on
[0,m)
• Curve:

– n is the total number of control points


– d is the order of the curves, 2 ≤ d ≤ n+1, d typically 3
or 4
– Bk,d are the uniform B-spline blending functions of
degree d-1
– Pk are the control points
– Each Bk,d is only non-zero for a small range of t
values, so the curve has local control
Uniform Cubic B-spline Blending Functions

B0, B1, B2, B3, B4, B5, B6,


4 4 4 4 4 4 4
Computing the Curve

P1B1, P4B4,
P0B0, P2B2,
4 4 P6B6,
4 4 P3B3,
4
4 P5B5,
4

The curve can’t start until there are 4 basis functions active
Using Uniform B-splines
• At any point t along a piecewise uniform
cubic B-spline, there are four non-zero
blending functions
• Each of these blending functions is a
translation of B0,4
• Consider the interval 0≤t<1
– We pick up the 4th section of B0,4
– We pick up the 3rd section of B1,4
– We pick up the 2nd section of B2,4
– We pick up the 1st section of B3,4
B-Spline Surfaces
• Defined just like Bezier surfaces:

• Continuity is automatically obtained


everywhere
• BUT, the control points must be in a
rectangular grid

OK Not OK
B-Spline Knot Vectors
• Knots: Define a sequence of parameter values at which the
blending functions will be switched on and off
• Knot values are increasing, and there are n+d+1 of them, forming
a knot vector: (t0,t1,…,tn+d) with t0 ≤ t1 ≤ … ≤ tn+d
• Curve only defined for parameter values between td-1 and tn+1
• These parameter values correspond to the places where the
pieces of the curve meet
• There is one control point for each value in the knot vector
• The blending functions are recursively defined in terms of the
knots and the curve degree
B-Spline Blending Functions

• The recurrence relation starts with the 1st order B-


splines, just boxes, and builds up successively higher
orders
• This algorithm is the Cox - de Boor algorithm
– Carl de Boor was a professor here
Uniform Cubic B-splines
• Uniform cubic B-splines arise when the knot vector is of the form (-
3,-2,-1,0,1,…,n+1)
• Each blending function is non-zero over a parameter interval of
length 4
• All of the blending functions are translations of each other
– Each is shifted one unit across from the previous one
– Bk,d(t)=Bk+1,d(t+1)
• The blending functions are the result of convolving a box with itself d
times, although we will not use this fact
Bk,1
Bk,2
Bk,3
B0,4
B0,4

Note that the functions given on slides 4 and 5 are translates of this
function obtained by using (t-1), (t-2) and (t-3) instead of just t, and
then selecting only a sub-range of t values for each function

You might also like