Professional Documents
Culture Documents
GVC-432 Ref: Donald Hearn & M. Pauline Baker ,: Lecture - 4
GVC-432 Ref: Donald Hearn & M. Pauline Baker ,: Lecture - 4
GVC-432 Ref: Donald Hearn & M. Pauline Baker ,: Lecture - 4
Lecture - 4
Ref: Donald Hearn & M. Pauline Baker ,
Computer Graphics
Foley, van Dam, Feiner & Hughes,
Computer Graphics Principles & Practice
Dr Pavan Chakraborty
IIIT-Allahabad
x Cartesian
y
Coordinates
• Often we use the • This works if we know the
Cartesian coordinate max min values.
convention ie x,y
coordinates (or x,y,z in • Common values are eg
3D) and map this to
640 columns x 320 rows
our display
• Or 1024x768 or better
• Usually column
corresponds to x, and
-row corresponds to y • Aspect ratio is the ratio of
these eg 4:3 - Chosen to suit
the common display devices
eg TV screens or monitors
Indian Institute of Information Technology - Allahabad
Drawing Space or Canvas
• Coordinate Systems • We do not want to write our
application programs
worrying about pixel
• Drawing Primitives resolutions
Start point - ( x1 , y1 )
End point - ( x2 , y 2 ) x(t ) x1 t ( x2 x1 )
y (t ) y1 t ( y2 y1 )
• Start at t = 0
dx
• At each step, increment t by dt xnew xold
dt
dy
• Choose appropriate value for dt ynew yold
dt
• Ensure no pixels are missed:
– Implies: dx and dy
1 1
dt dt
0.0 m 1.0 x 1 yk 1 yk m
1
1.0 m y 1 xk 1 xk
m
Indian Institute of Information Technology - Allahabad
DDA Algorithm
#include 'device. h"
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 / (float) steps;
yIncrement = dy / (float) steps;
{ n - range of t.
float x,y;
int dx = x2-x1, dy = y2-y1;
int n = max(abs(dx),abs(dy));
float dt = n, dxdt = dx/dt, dydt = dy/dt;
x = x1;
y = y1;
while( n-- ) {
point(round(x),round(y));
x += dxdt;
y += dydt;
}
}
F ( x, y ) ax by c 0
• Easy to prove F<0 for points above the
line, F>0 for points below.
• So:
dy
y mx b and so y xb
dx
F ( x, y ) dy.x dx. y c 0
NE
M
E
If E chosen :
1 1
d new F ( x p 2, y p ) a ( x p 2) b( y p ) c
2 2
But recall :
1
d old F ( x p 1, y p )
NE 2
1
M a ( x p 1) b( y p ) c
2
E
Previous Choices for
So :
d new d old a
Pixel Choices for Next pixel
(xp,yp) Current pixel d old dy
Indian Institute of Information Technology - Allahabad
Decision variable.
If NE was chosen :
3 3
d new F ( x p 2, y p ) a ( x p 2) b( y p ) c
2 2
M So :
NE
d new d old a b
E
d old dy dx
Previous Choices for
Pixel Choices for Next pixel
(xp,yp) Current pixel
d start dy dx / 2
Conventional to multiply by 2 to remove fraction doesn’t effect sign.
M
SE