0% found this document useful (0 votes)
7 views

Co3150- Unit II

The document discusses computer graphics techniques, focusing on line and circle drawing algorithms. It covers various methods such as the Digital Differential Analyzer (DDA) and Bresenham's algorithm for line drawing, as well as the midpoint circle drawing algorithm. The document also addresses issues like pixel plotting, rasterization, and optimization for efficient rendering of graphics.

Uploaded by

aaminasiddiqui82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Co3150- Unit II

The document discusses computer graphics techniques, focusing on line and circle drawing algorithms. It covers various methods such as the Digital Differential Analyzer (DDA) and Bresenham's algorithm for line drawing, as well as the midpoint circle drawing algorithm. The document also addresses issues like pixel plotting, rasterization, and optimization for efficient rendering of graphics.

Uploaded by

aaminasiddiqui82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 130

Computer Graphics (CO-3150)

M. Sarosh Umar
Department of Computer Engineering,
Aligarh Muslim University, Aligarh
Email: [email protected]

1
Computer Graphics
• Point Plotting Techniques

2
Scan Converting Lines
Line Drawing
• Draw a line on a raster screen between two points
• What’s wrong with statement of problem?
- doesn’t say anything about which points are allowed as endpoints
- doesn’t give a clear meaning of “draw”
- doesn’t say what constitutes a “line” in raster world
- doesn’t say how to measure success of proposed algorithms

Problem Statement
• Given two points P and Q in XY plane, both with integer coordinates,
determine which pixels on raster screen should be on in order to make
picture of a unit-width line segment starting at P and ending at Q
Finding next pixel:
Special case:
• Horizontal Line:
Draw pixel P and increment x coordinate value by 1 to get next pixel.

• Vertical Line:
Draw pixel P and increment y coordinate value by 1 to get next pixel.

• Diagonal Line:
Draw pixel P and increment both x and y coordinate by 1 to get next
pixel.

• What should we do in general case?


- Increment x coordinate by 1 and choose point closest to
line.
- But how do we measure “closest”?
Vertical Distance
• Why can we use vertical distance as measure of which point is closer?
- because vertical distance is proportional to actual distance
- how do we show this?
- with similar triangles
(x1, y1)

(x2, y2)

• By similar triangles we can see that true distances to line (in blue) are
directly proportional to vertical distances to line (in black) for each point
• Therefore, point with smaller vertical distance to line is closest to line
Strategy 1 - Incremental
Basic Algorithm
• Find equation of line that connects two points P and Q
• Starting with leftmost point P, increment xi by 1 to calculate yi = mxi + B
where m = slope, B = y intercept
• Intensify pixel at (xi, Round(yi)) where
Round (yi) = Floor (0.5 + yi)

Incremental Algorithm:
• Each iteration requires a floating-point multiplication
- therefore, modify algorithm.
• yi+1 = mxi+1 + B = m(xi + Dx) + B = yi + m Dx
• If Dx = 1, then yi+1 = yi + m
• At each step, we make incremental calculations based on preceding
step to find next y value
Strategy 1 - Incremental
( xi , yi ) ( xi + 1, Round ( yi + m))

( xi , Round ( yi )) ( xi + 1, yi + m)
Objectives

• Survey Line Drawing Algorithms


- DDA
- Bresenham’s Algorithm
• Aliasing and Antialiasing
Rasterization

• Rasterization (scan conversion)


- Determine which pixels that are inside primitive
specified by a set of vertices
- Produces a set of fragments
- Fragments have a location (pixel location) and
other attributes such as color and texture
coordinates that are determined by interpolating
values at vertices
• Pixel colors determined later using color,
texture, and other vertex properties
Scan Conversion of Line
Segments
• Start with line segment in window
coordinates with integer values for
endpoints
• Assume implementation has a
write_pixel function
y = mx + h
Dy
m=
Dx
DDA Algorithm

• Digital Differential Analyzer


- DDA was a mechanical device for numerical
solution of differential equations
- Line y=mx+ h satisfies differential equation
dy/dx = m = Dy/Dx = y2-y1/x2-x1
• Along scan line Dx = 1
For(x=x1; x<=x2,ix++) {
y+=m;
write_pixel(x, round(y), line_color)
}
Problem

• DDA = for each x plot pixel at closest y


- Problems for steep lines
Using Symmetry

• Use for 1 ³ m ³ 0
• For m > 1, swap role of x and y
- For each y, plot closest x
DDA Algo (General)
#include “device. h“
#define ROUND (a) ((int)(a+0.5))
void lineDDA (int xa, int ya, int xb, int yb)
{
int dx = xb - xa, dy = yb - ya, steps, k;
float xIncrement, yIncrement, x = xa, y = ya;
if (abs (dx) > abs (dy)) steps = abs (dx) ;
else steps = abs (dy);
xIncrement = dx / steps;
yIncrement = dy / steps;

setpixel (ROUND(x), ROUND(y));


for (k=0; k<steps; k++) {
x += xIncrement;
y += yIncrement;
setpixel (ROUND(x), ROUND(y));
}
}
Criteria for Drawing Lines
1. Must compute integer coordinates of pixels which lie on or near a
line.
2. Pixel level algorithms are invoked hundreds or thousands of times
when an image is created or modified.
3. Lines must create visually satisfactory images.
• Lines should appear straight
• Lines should terminate accurately
• Lines should have constant density
• Line density should be independent of line length and angle.
DDA Algo

Rounding and floating point operations


take time
Bresenham’s Algorithm

• DDA requires one floating point addition per step


• We can eliminate all fp through Bresenham’s
algorithm
• Consider only 1 ³ m ³ 0
- Other cases by symmetry
• Assume pixel centers are at half integers
• If we start at a pixel that has been written, there
are only two candidates for the next pixel to be
written into the frame buffer
Bresenham’s Algo (|m|<1)

y = mx + b

d2
y = m(x+1) + b
y d1

x x+1

19
Bresenham’s Algo (|m|<1)
d1=y-yk= m(xk+1)+b-yk

d2=(yk+1)-y= yk+1- m(xk+1) – b

d1-d2= 2m(xk+1) -2yk +2b-1

Dx (d1-d2) =2 Dy(xk+1) -2 Dx yk + Dx (2b-1)

Dx (d1-d2) =2 Dy.xk - 2 Dx. yk + 2 Dy + Dx (2b-1)

pk= 2 Dy.xk - 2 Dx. yk + c where c = 2 Dy + Dx (2b-1)

If d1<d2 i.e. pk is –ve ;yk is closer to line so plot (xk+1 , yk )


Bresenham’s Algo (|m|<1)
1. Input the two line endpoints and store the left endpoint in (x0,y0)
2. Load (x0,y0) into the frame buffer; that is, plot the first point.
3. Calculate constants ∆x, ∆ y, 2∆y, and 2∆y-2∆x, and obtain the starting
value for the decision parameter as
p0 = 2∆y - ∆x

4. At each xk along the line, starting at k = 0, perform the following test:


If pk < 0, the next point to plot is (xk + 1, yk ) and
pk +1= pk + 2 ∆y
Otherwise, the next point to plot is (xk + 1, yk + 1) and
pk +1= pk + 2 ∆y - 2 ∆x

5. Repeat step 4 ∆x times.


Bresenham’s Algo (|m|<1)
void lineBres (int xa, int ya, int xb, int yb)
{
int dx = abs (xa – xb) , dy = abs (ya - yb);
int p = 2 * dy - dx ;
int twoDy = 2 * dy, twoDyDx = 2 * (dy - dx);
int x , y, xEnd;
/* Determine which point to use as start, which as end */
if (xa > x b ) {
x = xb;
y = yb;
xEnd = xa;
}
else {
x = xa;
y = ya;
xEnd = xb; }
Bresenham’s Algo (|m|<1)

setpixel (x, y);


while (x < xEnd) {
x++;
if (p < 0)
p += twoDy;
else {
y++;
p += twoDyDx;
}
setpixel ( x , y);
}
}
Bresenham’s Algo (|m|<1)

Plot a line b/w (20,10) and (30,18)

p0 = 2∆y - ∆x = 16-10 =6
Wide Lines & Line styles

• 3, 5 and more pixel-wide lines can be drawn by


invoking pixels above and below the computed
(plotted) pixel for m<1

• Line Styles can also be chosen:


Dashed, dotted, solid, combination etc.

--- - --- - ---


---- ---- ---- ----
Wide Lines & Line styles

struct linesettingstype
{
int linestyle;
unsigned upattern;
int thickness;
};
Wide Lines & Line styles
Wide Lines & Line styles

Pattern:
• 16-bit pattern that applies only if linestyle is
USERBIT_LINE (4)
• whenever a bit in the upattern word is 1, the
corresponding pixel in the line is drawn in the
current drawing color
• a solid line corresponds to a pattern of 0xFFFF
(all pixels drawn), and a dashed line can
correspond to a upattern of 0x3333 or 0x0F0F
Wide Lines & Line styles

Pattern:
• How to extract a bit from the pattern to decide
that the pixel is to be plotted?

P=10011011
M=00000001
--------------------
R= P&M
Wide Lines & Line styles

• How to achieve different patterns??


Dashed, dotted, solid, combination etc.

--- - --- - ---


---- ---- ---- ----
Wide Lines & Line styles
Circle Drawing
Algorithms

32
Circle generating
algorithms

• Direct
• Polar coordinate based
• Bresenham’s
Direct circle algorithm

• Cartesian coordinates
• Circle equation:
( x - xc )2 + ( y - yc )2 = r2
• Step along x axis from xc - r to xc + r and
calculate
y = yc ± Ö r2 - ( x - xc )2
• Considerable computations!!
• Spacing is not uniform – > interchange x & y
whenever |slope| > 1
Polar coordinates

• Polar coordinate equation


x = xc + r cosj
y = yc + r sinj
• Step through values of j from 0 to 2π
Midpoint Circle Drawing
Algorithm
• To determine the closest pixel position to the specified
circle path at each step.
• For given radius r and screen center position (xc, yc),
calculate pixel positions around a circle path centered
at the coodinate origin (0,0).
• Then, move each calculated position (x, y) to its
proper screen position by adding xc to x and yc to y.
• Along the circle section from x=0 to x=y in the first
quadrant, the gradient varies from 0 to -1.

36
Optimisation and speed-up
n 8 segments of octants for a circle:
• Symmetry of a (-x,y) (x,y)
circle can be
used
(-y,x) (y,x)

• Calculations of
(-y,-x) (y,-x)
point
coordinates only
for a first one- (-x,-y) (x,-y)
eighth of a circle
37
Midpoint Circle Drawing
Algorithm
n 8 segments of octants for a circle:

38
Midpoint Circle Drawing
Algorithm
n Circle function: fcircle (x,y) = x2 + y2 –r2

{
> 0, (x,y) outside the circle

fcircle (x,y) = < 0, (x,y) inside the circle

= 0, (x,y) is on the circle


boundary

39
Midpoint Circle Drawing
Algorithm
yk yk
midpoint midpoint

yk-1 yk-1

pk = fcircle(xk+1, yk- ½)
pk < 0 pk >= 0
yk+1 = yk yk+1 = yk - 1
Next pixel = (xk+1, yk) Next pixel = (xk+1, yk-1)

40
Midpoint Circle Drawing
Algorithm
We know xk+1 = xk+1,
pk = fcircle(xk+1, yk- ½)
pk = (xk +1)2 + (yk - ½)2 - r2 -------- (1)
pk+1 = fcircle(xk+1+1, yk+1- ½)
pk+1 = (xk +2)2 + (yk+1 - ½)2 - r2 -------- (2)
(2) – (1)
pk+1 = pk + 2(xk+1) + (y2k+1 – y2k) - (yk+1 – yk) + 1

If pk < 0, pk+1 = pk + 2xk+1+1


If pk >= 0, pk+1 = pk + 2xk+1+1 – 2yk+1 41
Midpoint Circle Drawing
Algorithm
For the initial point, (x0 , y0) = (0, r)

p0 = fcircle (1, r-½ )


= 1 + (r-½ )2 – r2
= 5–r
4
≈ 1–r

42
Midpoint Circle Drawing
Algorithm
1. Input radius r and circle centre (xc, yc), and obtain the first point
on the circumference of a circle centred on the origin as (0,r)
2. Calculate the initial value of the decision parameter as
p0 = 5/4 – r

3. At each xk position, starting at k = 0, perform the following test:


If pk < 0, the next point along the circle centred on (0,0) is
(xk+1, yk) and pk+1 = pk + 2xk+1+1

Otherwise, the next point along the circle is (xk+1, yk-1)


and
pk+1 = pk + 2xk+1+1 – 2yk+1

where 2xk+1 = 2xk+ 2 and 2yk+1 = 2yk - 2. 43


Midpoint Circle Drawing
Algorithm
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (x, y) onto the circular path
centred on (xc, yc) and plot the coordinate values:

x=x+xc and
y=y+yc

6. Repeat steps 3 through 5 until x ≥ y.

44
Midpoint Circle Drawing
Algorithm
Example:
Given a circle radius = 10, determine the circle octant in
the first quadrant from x=0 to x=y.

Solution:
p0 = 5 – r
4
= 5 – 10
4
= -8.75
≈ –9
45
Midpoint Circle Drawing
Algorithm
Initial (x0, y0) = (1,10)
Decision parameters are: 2x0 = 2, 2y0 = 20
k pk x y 2xk+1 2yk+1
0 -9 1 10 2 20
1 -9+2+1=-6 2 10 4 20
2 -6+4+1=-1 3 10 6 20
3 -1+6+1=6 4 9 8 18
4 6+8+1-18=-3 5 9 10 18
5 -3+10+1=8 6 8 12 16
6 8+12+1-16=5 7 7 14 14

46
Midpoint Circle Drawing
Algorithm
void circleMidpoint (int xCenter, int yCenter, int radius)
{
int x = 0;
Int y = radius;
int f = 1 – radius;
circlePlotPoints(xCenter, yCenter, x, y);
while (x < y) {
x++;
if (p < 0)
p += 2*x+1;
else {
y--;
p += 2*(x-y)+1; }
}
circlePlotPoints(xCenter, yCenter, x, y);
47
}
Midpoint Circle Drawing
Algorithm
void circlePlotPoints (int xCenter, int yCenter, int x,
int y)
{
setPixel (xCenter + x, yCenter + y);
setPixel (xCenter – x, yCenter + y);
setPixel (xCenter + x, yCenter – y);
setPixel (xCenter – x, yCenter – y);
setPixel (xCenter + y, yCenter + x);
setPixel (xCenter – y, yCenter + x);
setPixel (xCenter + y, yCenter – x);
setPixel (xCenter – y, yCenter – x);
}

48
Curves

Curves for Airplane wings, car hoods and human faces are
not simple circles or ellipses!
Curves
Curves

Three main ways to define a curve


Function: y = x3 + 3x
Implicit function: x2 + y2 + xy= 25
Parametric Function: (x, y) = (5 cos(t), 5 sin(t))
Curves

Parametric representation:

Represent a line
P(t) = p0 + (p1-p0)t

( x, y ) = (1 - t ) p0 + tp1
x = x0 (1 - t ) + x1t
y = y0 (1 - t ) + y1t
z = z0 (1 - t ) + z1t
Curves

Circle:

x = xc + r cosj
y = yc + r sinj

P (u ) = (cos(u ), sin(u ))
Surfaces with two
parameters u,v
P (u ) = ( x(u ), y (u ),z (u ))
P (u , v) = ( x(u , v), y (u , v),z (u , v))
Curves

Advantage of parametric representation:


1. Difference b/w 2 & 3 dimensions is just the
addition of a 3rd equation for z
2. All directions are treated equally
3. Allows multiple values i.e. curves can double
back or even cross themselves
Curves

Lets invent a function:


Suppose we want a curve that passes thru n
sample points
p1, p2, p3, ….., pn

Where pi = (xi, yi, zi)


Construct a function such that there is one term
for each point
Curves

n
x (u ) = å x B (u )
i i
i =1
n
y (u ) = å y B (u ) i i
i =1
n
z (u ) = å z B (u )
i i
i =1

• Bi(u) is called Blending function


• For each value of u, Bi(u) determines how much
ith sample point affects the position of the curve
• Each sample point tries to pull the curve in its
direction
Curves

• Bi(u) decides how hard ith sample point is pulling


• If for some value of u, Bi(u) = 1 and for each j≠i
Bj(u) = 0 then ith sample point has complete
control of the curve
(curve will pass thru ith sample point)
• Similarly, if at some other value of u, one of the
other sample point has complete control then the
curve will pass thru that point as well
Curves

• Create Blending function for which p1 has


complete control when u=-1; p2 when u=0; p3
when u=1, and so on
• Therefore
u i Bi(u) Bj≠i(u)
-1 1 1 0
0 2 1 0
1 3 1 0

n-2 n 1 0
Curves

• For B1(u) we need a function which is 1 at u=-1


and 0 for u=0,1,2,3,……n-2
Curves

• An expression which is 0 at correct places is


u(u-1)(u-2)……..[(u-(n-2)] …(1)

At u=-1 it is
(-1)(-2)(-3)…….[1-n] ….(2)

Dividing (1) by (2) gives us 1 at u=-1


u(u - 1)(u - 2) ……..[(u - (n - 2)]
B1(u ) =
(-1)(-2)(-3) …….[1 - n]
Curves

• Similarly

(u + 1)(u - 1)(u - 2) ……..[(u - (n - 2)]


B 2(u ) =
(1)(-1)(-2)(-3)…….[2 - n]
• ith Blending function is 1 at u=i-2 and 0 at other
integers
Curves

• ith Blending function is 1 at u=i-2 and 0 at other


integers
(u + 1)u(u -1)(u - 2) …[u - (i - 3)][u - (i - 1)]…..[(u - (n - 2)]
Bi (u) =
(i - 1)(i - 2)(i - 3) …(1)(-1) ….[i - n]

Example: For 4 sample points

u(u - 1)(u - 2)
B1(u ) =
(-1)(-2)(-3)
Curves

(u + 1)(u - 1)(u - 2)
B 2(u ) =
(1)(-1)(-2)
(u + 1)u(u - 2)
B3(u ) =
(2)(1)(-1)

(u + 1)u(u - 1)
B 4(u ) =
(3)(2)(1)
Curves

x=x1B1 (u)+x2B2 (u)+x3B3 (u)+x4B4 (u)


y=y1B1 (u)+y2B2 (u)+y3B3 (u)+y4B4 (u)
z=z1B1 (u)+z2B2 (u)+z3B3 (u)+z4B4 (u)
Important Properties for
Designing Curves
1. Control Points: A common way to
control the shape of the curves. The
curve may or may not pass thru the
CPs. Called knots when they lie on the
curve
Important Properties for
Designing Curves
2. Multiple Values: In general a curve is
not a graph of a single valued function
of a coordinate
3. Axis Independence: The shape of the
curve must not change when the CPs
are measured in different coordinates
e.g. if CPs are rotated by 900 then the
curve must also rotate by 900
Important Properties for
Designing Curves
4. Global or Local Control: If a CP is
changed, the curve may change shape
only in the region near the C, or it may
change shape throughout.
Important Properties for
Designing Curves
5. Variation Diminishing Property: Some
mathematical representations tend to
amplify the small irregularities in
shapes. Some tend to smooth out a
sequence of CPs
Important Properties for
Designing Curves
6. Versatility: The curve representation
should allow wide variety of shapes e.g.
addition or removal of CPs should be
simple

7. Order of Continuity: A complex shape is


not modeled by a single curve but by
several curves pieced together.
Important Properties for
Designing Curves
• Consider two curves defined by p0…p3 and
v0…v3
• If p3=v0, then they will have C0 continuity
• If (p3-p2)=(v1-v0), then they will have C1
continuity
• C2 continuity
v1 is more difficult…
p 2
p2 v3
p1 P3 v0
p1 v3
v1
P3 v0
v2
v2 p0
p0

C0 continuity C1 continuity 70
Important Properties for
Designing Curves
Bezier Method

P. Bezier worked for Renault and designed the


panels of several cars.
The curve P(u) is defined in terms of n+1
Control points
n
P(u ) = å p i Bi ,n (u )
i =0

Where Bi,n(u) is the Blending function


Bi ,n (u ) = C (n, i )u i (1 - u )
n -i

C(n,i) is the binomial coefficient


Bezier Method

n
P (u ) = å p i Bi ,n (u ), 0 £ u £1
i =0

n -i n!
Bi ,n (u ) = C (n, i )u (1 - u ) ,
i
C (n, i) =
i!(n - i )!
n
x(u ) = å x B (u )
i i, n
i =0
n
y (u ) = å y B (u ) i i, n
i =0
n
z (u ) = å z B (u )
i i, n
i =0
Bezier Method – Blending
functions for n=3

1.2

0.8 B0
B1
0.6
B2

0.4 B3

0.2

0
Bezier Method – Blending
functions for n=3
Bezier Method – Blending
functions for n=3
The Blending function curves represent the
influence that each control point exerts on
the curve for various values of u.
B0,3(u) is most influential when u=0
p1 and p2 are most influential for u=1/3 and 2/3
respectively
Important Properties for
Bezier Curves
1. Control Points: The curve passes
through p0 and pn
The curve is tangent at the end points
P0 to (P1-P0) and at Pn to (Pn-Pn-1)
Important Properties for
Bezier Curves
Control Points:
Important Properties for
Bezier Curves
2. Multiple Values: The parametric form
allows multiple values. If the 1st and last
CPs coincide, the curve is closed.
3. Axis Independence: Bezier curves is
independent of coordinate system used
to measure the location of CPs
Important Properties for
Bezier Curves
4. Global or Local Control: These curves
do not provide localized control. The
location of each CP influences the
curve location almost everywhere.
Important Properties for
Bezier Curves
5. Variation Diminishing Property: Bezier
curves are variation diminishing. The
curve always lies within the convex hull
of the CPs. Bezier curves never oscillate
wildly away from its defining CPs.
Important Properties for
Bezier Curves
• If we take all of the control points for a Bezier curve and
construct a convex polygon around them, we have the
convex hull of the curve
• An important property of Bezier curves is that every point on
the curve itself will be somewhere within the convex hull of
the control points

p1 p3

p0
p2
Important Properties for
Bezier Curves
6. Versatility: CPs govern the versatility of
Bezier curves.

7. Order of Continuity: Bezier curves of


modest order can be pieced together to
design a more complex curve.
Important Properties for
Designing Curves
• Consider two curves defined by p0…p3 and
v0…v3
• If p3=v0, then they will have C0 continuity
• If (p3-p2)=(v1-v0), then they will have C1
continuity
• C2 continuity
v1 is more difficult…
p 2
p2 v3
p1 P3 v0
p1 v3
v1
P3 v0
v2
v2 p0
p0

C0 continuity C1 continuity 84
Bezier Continuity
Bezier Continuity

P0,1 P0,2

P0,0
P1,3
J

P1,2
P1,1

PowerPoint curves are not Bezier curves, they are interpolating piecewise quadratic curves! This
diagram is an approximation.
Bézier Surfaces
• Bezier surfaces are generated by Cartesian product of two
curves. Two similar Bézier blending functions are used, one
for each parameter. CPs: (n+1)x(m+1)

n m
P(u, v) = åå pi , j Bi ,n (u)B j ,m (v) 0 £ u, v £ 1
i =0 j =0
Bézier Surfaces
• Two sets of curves are drawn: One set holds the parameter
u constant and allows v to vary from 0 to 1; the other set
holds v constant and varies u.

n m
P(u, v) = åå pi , j Bi ,n (u)B j ,m (v) 0 £ u, v £ 1
i =0 j =0
Bézier Patches
• A common form of approximating larger surfaces by tiling
with cubic Bézier patches. m=n=3
• 4 by 4 = 16 control points.
Neat Bezier Spline
Trick
• A Bezier curve with 4 control points:
- P0 P1 P2 P3
• Can be split into 2 new Bezier curves:
- P0 P’1 P’2 P’3
- P’3 P’4 P’5 P3 A Bézier curve
is bounded by
the convex hull
of its control
points.

92
De Casteljau's Method

Gives simple recursive method to draw curve

Keep dividing until each subpiece of the curve is


almost straight

93
Alternate Method:
Bézier Curve
• de Casteljau's algorithm for constructing Bézier
curves

t t t
t
t

94
De Casteljau Algorithm

Compute points on the curve without evaluating


polynomials
Can use the midpoints, so only need to shift right

95
De Casteljau

r0 = (1 - u) p0 + u p1
r1 = (1 - u) p1 + u p2
r2 = (1 - u) p2 + u p3
Notation differs
from figure
s0 = (1 - u)r0 + ur1
s1 = (1 - u)r1 + ur2

t 0 = (1 - u)s0 + u s1
Expand one level

r0 = (1- u)p0 + u p1
r1 = (1- u)p1 + u p2

s0 = (1- u)r0 + ur1


= (1- u)((1- u) p0 + u p1 ) + u ((1- u) p1 + u p2 )
= (1- u) p0 + 2u(1- u) p1 + u p2
2 2

Similarly

s1 = (1- u) p1 + 2u(1- u)p2 + u p3


2 2
Find third level

s0 = (1- u) p0 + 2u(1- u)p1 + u p2


2 2

s1 = (1- u) p1 + 2u(1- u)p2 + u p3


2 2

t 0 = (1- u)s0 + us1

= (1- u) p0 + 3u(1- u) p1 + 3u (1- u) p2 + u p3


3 2 2 3
Find third level

t 0 = (1 - u ) p0 + 3u (1 - u ) p1 + 3u (1 - u ) p2 + u p3
3 2 2 3

Recall!!
n
P (u ) = å p i Bi ,n (u ), 0 £ u £1
i =0

n -i n!
Bi ,n (u ) = C (n, i )u (1 - u ) ,
i
C(n,i) =
i!(n - i )!
Splines

Approximate rather than interpolate (blue vs red


curves)
(Image is of a traditional spline used in boat building)

100
Splines

• Motivated by loftman’s spline


- Long narrow strip of wood or plastic
- Shaped by lead weights (called ducks)
B-Spline Basis
Consider designing the profile of a vase.
• The left figure below is a Bézier curve of degree 11; but, it is difficult to
bend the "neck" toward the line segment P4P5.
• The middle figure above uses this idea. It has three Bézier curve
segments of degree 3 with joining points marked with yellow rectangles.
• The right figure above is a B-spline curve of degree 3 defined by 8
control points .
B-Spline Basis
• Little dots subdivide the B-spline curve into curve
segments.
• One can move control points for modifying the shape of the
curve just like what we do to Bézier curves.
• We can also modify the subdivision of the curve. Therefore,
B-spline curves have higher degree of freedom for curve
design.
B-Spline Basis
• Subdividing the curve directly is difficult to do.
Instead, we subdivide the domain of the curve.
• The domain of a curve is [0,1], this closed interval is
subdivided by points called knots.
• These knots be 0 <= u0 <= u1 <= ... <= um <= 1.
• Modifying the subdivision of [0,1] changes the shape of the
curve.
B-Spline Basis
• In summary: to design a B-spline curve,
we need a set of control points, a set of
knots and a set of coefficients, one for each
control point, so that all curve segments are
joined together satisfying certain continuity
condition.
B-Spline Basis

• The computation of the coefficients is


perhaps the most complex step because they
must ensure certain continuity conditions.
B-Spline Curves
B-Spline Curves
(Two Advantages)

1. The degree of a B-spline polynmial can


be set independently of the number of
control points.

2. B-splines allow local control over the


shape of a spline curve (or surface)
B-Spline Curves
(Two Advantages)

n A B-spline curve that is defined by 6 control point,


and shows the effect of varying the degree of the
polynomials (2,3, and 4)
n Q3 is defined by P0,P1,P2,P3
n Q4 is defined by P1,P2,P3,P4
n Q5 is defined by P2,P3,P4,P5

n Each curve segment


shares control points.
B-Spline Curves
(Two Advantages)
n The effect of changing the position of control
point P4 (locality property).
B-Spline Curves

Bézier Curve B-Spline Curve


B-Spline Curves

Curves of degree k-1 and n+1 CPs


n
P(u ) = å p i N i ,k (u ), 0£u £ n-k +2
i =0

ì1 if ti £ u < ti +1
N i ,1 (0) = í
î0 otherwise
(u - ti ) (ti + k - u )
N i ,k (u ) = N i ,k -1 (u ) + N i +1,k -1 (u )
ti + k -1 - ti ti + k - ti +1
112
B-Spline Curves

Knot values (ti) relate parameter u to the CPs


Two Choices of knot values:
a) Uniform non-periodic B-Spline
ti =0 if i<k
i-k+1 if k ≤i≤n
n-k+2 if i>n

b) Periodic B-Spline ti =i

N i , k (u ) = N 0 , k ((u - i + n + 1) mod(n + 1))


0 £ u £ n +1
113
B-Spline Curves

n To change the shape of a B-spline


curve, one can modify one or more of
these control parameters:
1. The positions of control points
2. The positions of knots
3. The degree of the curve

114
B-Spline Curves

115
Important Properties for B-
Spline Curves
1. Control Points: The location of the curve
depends only on few control points.
Several consecutive CPs at the same
location introduces corners.

k controls the order of the curve.


B-Spline Curves

117
Important Properties for B-
Spline Curves
2. Multiple Values: The parametric form
allows multiple values. If the 1st and last
CPs coincide, the curve is closed.
3. Axis Independence: B-Spline curve is
independent of coordinate system used
to measure the location of CPs
Important Properties for B-
Spline Curves
4. Local Control: These curves provide
localized control. The shape of the curve
changes only in the vicinity of a changed
CP.
Important Properties for B-
Spline Curves
5. Variation Diminishing Property: B-Spine
curves are variation diminishing. The
curve always lies within the convex hull
of the CPs.
Important Properties for B-
Spline Curves
Graphical Interactive Input
Methods
• Graphics system used for (examples):
• Architectural Design
- construct and display views of buildings by
positioning walls, doors, windows, and other
building components.
• Facility layout system
- objects could be defined as a set of furniture
items (tables, chairs, etc.), and the available
operations would include those for positioning
and removing different pieces of furniture within
the facility layout 123
Graphical Interactive Input
Methods
• Graphics system used for (contd):
• Circuit design application
- might use electrical or logic elements
- adding or deleting elements

User Dialogue

124
Graphical Interactive Input
Methods
• User Dialogue considerations
- Windows and Icons:
• opening and closing windows, repositioning windows,
resizing windows, and display routines that provide interior
and exterior clipping and other graphics functions
• application icons - The icons representing objects
• control icons, or command icons – The icons representing
actions, such as rotate, magnify, scale, clip, and paste
- Consistency
• Icon shapes, combination of keys, colour codes etc should
have a single meaning
• Menus should be placed on same relative position

125
Graphical Interactive Input
Methods
• User Dialogue considerations
- Minimize memorization
- Backup and Error Handling
• Undo
• Good diagnostics and Error messages: Not allowing to
paste if nothing is on clipboard
- Feedback
• As each input is received, the system provides some type
of response e.g. An object is highlighted or blinks, an icon
appears, colour changes or a message is displayed
• Without feedback, uncertainty is there regarding what the
system is doing and whether the input should be given
again
126
Graphical Interactive Input
Methods
Logical Classification of Input Devices
• LOCATOR- a device for specifying a coordinate
position ( x , y)
• STROKE- a device for specifying a series of
coordinate positions
• STRING- a device for specifying text input
• VALUATOR- a device for specifying scalar value
• CHOICE- a device for selecting menu options
• PICK-a device for selecting picture components

127
Graphical Interactive Input
Methods
Interactive Picture Construction Techniques
Positioning: Moving the cursor to the desired spot
on the screen + clicking a button or key
(A very commonly used operation!!)
E.g. A single positioning operation can be used to
insert a symbol
Two in succession can define end points of a line.

What about rectangles, circles, arcs??

128
Graphical Interactive Input
Methods
Interactive Picture Construction Techniques
Problem:
Very difficult to align input information with other
information already on the screen. Accurate
positioning cannot be achieved without assistance
from the computer.
Solution:
Geometric Constraints

129
Graphical Interactive Input
Methods
Interactive Picture Construction Techniques
Constraints are the rules that we wish certain
information such as input coordinates to obey.

• Modular
• Directional
• Gravity Field Effect
• Scales & Guidelines

130
Graphical Interactive Input
Methods
Interactive Picture Construction Techniques
Positioning Feedback:

• Rubber Banding Technique


• Dragging: Symbol is attached to the cursor
• Positioning Text
• Dimensioning Techniques and Graphical
Potentiometer

131
Graphical Interactive Input
Methods
Interactive Picture Construction Techniques
Pointing & Selection

132

You might also like