Introduction To Computer Graphics: Unit - I
Introduction To Computer Graphics: Unit - I
Introduction To Computer Graphics: Unit - I
Introduction to Computer
Graphics
Computer Graphics: Definition
• Computer Graphics is an art of drawing pictures, lines, charts etc.
on computer screen by using a programming language.
• Objects are presented as collections of discrete picture element
called PIXEL. Pixel is smallest unit of screen element in a
computer screen.
• The user can edit graphic object (pixel) with the help of keyboard,
mouse and touch sensitive panel, on the screen.
Graphic Devices= I/P Devices+ Display (O/P) Devices.
Definition Contd.....
• It involves computation, creation & manipulation of graphical
data.
• Computer Graphics acts as rendering tool for generation &
manipulation of images.
• It involves display, manipulation and storage of picture & data
related to visualization using computer.
• Uses computer to define, store, interrogate and present pictorial
output.
Representation of an Image
• In computer graphics, a graphic object is represented as a
collection of discrete picture elements, called pixels.
• Hence, a pixel is smallest addressable screen element. It is the
smallest piece of display screen which can be controlled.
• This control is achieved by setting the intensity and color of pixel,
which compose the screen.
Representation of an Image Contd..
• Each pixel represent a region, which theoretically can
contain infinite no of points.
• But in general a point is represented by the integer part
of x coordinates, and y coordinates.
• For example, P1 are represented by (4, 3), irrespective of
their exact values.
Representation of an Image Contd...
• There are special procedure which determine, which pixel will
provide best approximation to the desired picture or graphic
objects.
• The process of determining the appropriate pixels for
representing picture or graphic object is called rasterization.
• The process of representing continuous picture or graphic object
as a collection of discrete pixels is called scan conversion.
Computer Graphics vs Computer Vision
• In case of line, it can be possible that any pixel may have any floating
value like, (2.7, 9), which will not be considered by the system.
Scan Conversion
• Therefore, the process of representing these coordinates
according to system assumption . i.e (3,5) to plot the pixel comes
into the process of scan conversion.
• Points to remember:
• All the objects should be drawn with constant brightness.
• Objects should be independent of length and orientation
Scan Conversion : Points
• A Point is the fundamental element of the picture representation.
• It is a position in a plane defined as either pair or triplets of
numbers depending on whether the data is two or three
dimensional
• Thus (x1,y1) or (x1,y1,z1) would represent a point in either two or
three dimensional space.
Scan Conversion : Points
• Each pixel on graphic display doesn’t represent a mathematical
point, Instead, it means a region which theoretically can contain
infinite no of points.
• Scan converting a point involves illuminating the pixel that
contains the point.
• Example: Display coordinates P (2.25, 1.75) and Q (2.36, 1.25).
Scan Conversion : Points
Scan Conversion : Points
• In general, a point P(x,y) is represented by the integer part of x &
integer part of y, that is pixels (int(x), int(y)).
• In the given figure, P and Q will be represented by (2,1) and (3,1).
Scan Conversion LINES
• A straight line is defined by two end points & an equation. The
points are represented as (x1,y1) & (x2,y2) and the equation of
line is used to determine the x, y coordinates, that lie between the
end points.
• Using equation, y=mx+c where m= (Δy/ Δx) & c is the Y
intercept, we can find the values of y, by incrementing x from
x=x1 to x2.
• By scan converting these calculated x, y values, we represent the
line as a sequence of pixels.
Scan Conversion LINES
• Properties of Good Line Drawing Algorithm:
• Lines should appear straight. We must choose addressable points close to
it.
• Lines should terminate accurately. They should not terminate at wrong
place.
• Lines should have constant density. Line density is proportional to the
no of dots displayed divided by length of line. Dots should be equally
spaced.
• Line density should be independent of line length and angle.
Direct Use of Line Equation
• It is the simplest form of conversion. Firstly, P1 and P2 points are scanned.
P1 has (x1,y1) and P2 has (x2, y2) coordinates.
• Slope is calculated: m= (y2-y1)/(x2-x1)
• Put the value of slope in y=mx+c;
• Now put either of coordinates of P1 or P2 and find out the value of c.
• Use multiple values of X coordinates and put it in y=mx+c, and find the pair
of points lying in the line.
Direct Use of Line Equation
EXAMPLE: A line with starting point as (0, 0) and ending point (6, 18)
is given. Calculate value of intermediate points and slope of line.
DDA (Digital Differential Analyser)
Algorithm
• DDA stands for Digital Differential Analyser algorithm, for scan
conversion of lines.
• It is incremental method of scan conversion of lines. In this method,
calculation is performed at each step but by using results of previous
steps.
• The characteristic of the DDA algorithm is to take unit steps along
one coordinate and compute the corresponding values along the other
coordinate.
DDA (Digital Differential Analyser)
Algorithm
• Step 1: Get the input of two end points (X0, Y0) and (X1, Y1).
• Step 2: Calculate the difference between two end points.
• dx = X1 - X0 ; dy = Y1 - Y0
• Step 3: Based on the calculated difference in step-2, you need to
identify the number of steps to put pixel. If dx > dy, then you
need more steps in x coordinate; otherwise in y coordinate
DDA (Digital Differential Analyser)
Algorithm
Step4: if(absolute(dx) > absolute(dy))
• Steps= absolute(dx); else Steps = absolute(dy);
• Step 5: Put the pixel by successfully incrementing x and y
coordinates accordingly and complete the drawing of the line.
• for(int v=0; v < =Steps; v++)
• { x = x + Xincrement; y = y + Yincrement;
putpixel(Round(x), Round(y));
}
Algorithm (DDA (x1,y1,x2,y2))
{ dx=x2-x1; for(i=1; i<= steps; i++)
dy=y2-y1; { putpixels(xi,yi);
if(abs(dx)> abs(dy)) X1=x1+X Increment
then steps=abs(dx)
Y1= y1+ Y Increment
else: steps = abs(dy)
X Increment= Δx/steps; }
Y Increment = Δy/steps;
}
DDA Algorithm
OR
1- Read the line end points (x1, y1) and (x2, y2)
2- Δ x = | x2 – x1|
Δ y = |y2 – y1|
3. If (Δ x > Δ y ) then
length = Δ x
else
length = Δ y
DDA Algo Contd….
4- select the raster unit i.e.,
Δ X = (x2 – x1)/length
Δ Y = (y2 – y1)/length
5. x = x1 + 0.5 * sign (Δ X)
y = y1 + 0.5 * Sign (Δ Y)
6. Now plot the points
DDA Algo Contd….
i=1
while (i ≤ length)
{
plot (integer(x), integer (y))
x=x+Δx
y=y+Δy
i = i +1
}
7. STOP
Some Important point regarding DDA
Algo.
1- Either ΔX or ΔY will be one because length is either x2 – x1 or
y2 – y1. Thus the incremental value for x or y will be one.
2- Sign function makes the algorithm work in all quadrant. It
returns -1, 0, 1 depending on whether its agreement is <0, =0, >0
respectively.
3- The factor 0.5 makes it possible to round the values in the integer
function rather than truncating them.
Example 1
• Draw a line from (0,0) to (6,6) using DDA algorithm.
Solution
x1 = 0, y1 = 0
x2 = 6, y2 = 6
Now, Δx = dx = x2 – x1
=6–0=6
Δy = d y= y2 – y1
=6–0=6
Here Δx = dx = Δy = dy
Solution Contd….
Hence, steps or length = dx = 6
Now the raster unit = ΔX = Xincrement = Δ x/ steps = (6-0)/6 = 1
ΔY = Yincrement = Δ y/ steps = (6-0)/6 = 1
Hence ,
X= x1 + 0.5 sign(1) = 0 + 0.5 = 0.5
Y= y1 + 0.5 sign (1) = 0 + 0.5 = 0.5
Plot( integer (0.5), integer(0.5)) i.e, plot (1,1)
Solution Contd…
Now , X= x + Δx = 0.5 + 1 = 1.5
& Y = y + Δy = 0.5 + 1 = 1.5
Plot (integer(1.5), integer(1.5)) = plot (2,2)
Similarly we can find next plotting point.
i Plot X Y
0.5 0.5
oAdvantages
o It is the simplest algorithm and doesn’t require special skills for
implementation.
o It is a faster method for calculating pixel position than the
direct use of equation y=mx+c.
DDA Algorithm
Disadvantage
• Floating point arithmetic in DDA algorithm is still
time consuming.
• It is orientation dependent. Hence, endpoint accuracy
is poor.
Bresenham’s Line Algorithm
• This algorithm, like DDA is used for scan converting a line.
• It is an efficient method because it involves only integer addition,
subtraction and multiplication. These operations can be
performed very rapidly so lines can be generated quickly.
• In this method, next pixel selected, is that one which has least
distance from true line
Bresenham’s Line Algorithm
• The basic principle of Bresenham’s line algorithm is to select the
optimum raster location to represent a straight line.
• To accomplish this, the algorithm always increment either x or y
by one unit, depending on the slope of line.
• The increment in the other variable is determined by examining
the distance between the actual line location and nearest pixel.
This distance is called decision variable.
Bresenham’s Line Algorithm
• In mathematical terms, decision variable is defined as
e=DA - DB ;
• If e> 0 then it implies that DB >DA; the pixel above the line is closer to
the true line.
• If e<0 then implies DA < DB, then we can say that pixel below the
line is closer to the true line.
Bresenham’s Line Algorithm
• The initial value of decision variable s set as :
e = 2Δy-Δx; where Δy= y2-y1 & Δx= x2-x1
• Then according to values of e following actions are taken
while(e>=0) {
y=y+1;
• x = x + 1; e1=e0- 2Δx + 2Δy
}
else
• x= x+1; e1= e0+2Δy (If e<0),
• In both cases, x is incremented by 1. But if e<0, y is unchanged, till it becomes
positive.
Δy = |y2 - y1|
0 d0 = 3> 0 (11,6)
2 d2 = -1<0 (13,7)
3 d3 = 7 >0 (14,8)
4 d4 = 5>0 (15,9)
Bresenham’s Line Algorithm
Scan Converting
Circle
By Manoj
Mishra
Antialiasing
• In line drawing algorithms, we have seen that all rasterized locations
do not match with the true line, and we have to select the optimum
raster locations to represent a straight line.
• This problem is severe in low resolution screens, where line appears
like a stair step. This effect is known as aliasing.
• It is dominant in lines having sharp and gentle slopes.
Antialiasing
• The aliasing effect can be reduced by adjusting the
intensities of pixels along the line.
• The process of adjusting intensities of the pixels along the
line to minimize the effect of aliasing is called antialiasing.
• The aliasing effect can be minimised by increasing the
resolution of raster display.
Antialiasing
Antialiasing
• But this improvement comes at the price of quadrupling the cost of
memory, bandwidth of memory and scan-conversion time. Thus
increasing resolution is an expensive method for reducing aliasing
effect.
• With raster system that are capable of displaying more than two
intensity levels (colour and gray scale), we can apply antialiasing
methods to modify pixel intensities. By appropriately varying the
intensities of pixels along the line or object boundaries, we can
smooth the edges to lessen the stair-step or the jagged appearance.
Antialiasing Methods: Supersampling or
Postfiltering
• Supersampling or Postfiltering is the process by which aliasing effects
in graphics are reduced by increasing the frequency of the sampling
grid and then averaging the results down.
• This process means calculating a virtual image at a higher spatial
resolution than the frame store resolution and then averaging down to
the final resolution.
• It is called Postfiltering as the filtering is carried out after sampling.
Antialiasing Methods: Supersampling or
Postfiltering
• Supersampling is basically a three stage process:
• A continuous image I(x , y) is sampled at n times the frame resolution.
This is a virtual image.
• The virtual image is then lowpass filtered.
• The filtered image is then resampled at the final frame resolution.
Antialiasing Methods: Area Sampling or
Prefiltering
• In this antialiasing method pixel intensity is determined
by calculating the area of overlap of each pixel with
objects to be displayed.
• Anti aliasing by computing overlap area is referred to as
area sampling or pre filtering.
Basic Concepts in Circle Drawing
• A circle is a symmetrical figure which has eight way symmetry.
• Any circle generating algorithm can take advantage of the circle symmetry to
plot eight points by calculating the coordinates of any one point.
• For example in given figure, if point A(a,b) is calculated using a circle
algorithm, seven more point could be found just by reflection
Polynomial Method
Polynomial Method
• The first method defines a circle with the second-order polynomial
equation as shown in fig:
• y2=r2-x2 ; where x = the x coordinate
y = the y coordinate
r = the circle radius
• With the method, each x coordinate in the sector, from 90° to 45°, is
found by stepping x from 0 to (r/sqrt(2)) & each y coordinate is found
by evaluating sqrt(r2- x2) for each value of x.
Trignometric or Polar Method
Trignometric or Polar Method
• The second method of defining a circle makes use of polar
coordinates as shown in fig: x=r cos θ y = r sin θ
• Where θ=current angle; r = circle radius ; x = x coordinate; y
= y coordinate
• By this method, θ is stepped from 0 to ∏/4 & each value of
x & y is calculated.
Midpoint circle Algo:
• To apply the mid point method, we define the equation of a circle with (0,0)
as its centre as Fcircle (x,y) = x2+y2-r2
The relative position of any point (x,y) can be determined by
checking the sign of the circle function
Fcircle (x,y) = {<0 if (x,y) is inside the circle boundary
Fcircle (x,y) = { =0 if (x,y) is on circle boundary
Fcircle (x,y) = { >0 if (x,y) is outside the circle boundary
Midpoint circle algo. Contd….
• Thus circle function is the decision parameter in the midpoint algorithm and
we can set up calculations for this function as we did in the line algorithm.
• The initial value of decision parameter can be obtained by evaluating the
circle function at the start position (x0,y0) = (0,r)
p0 = fcircle(1, r-1/2) = 1+ (r-1/2)2 –r2 = 1.25 – r
If radius r is an integer we can simply round p0 = 1-r
Midpoint circle Algo:
1- Input radius r and centre (xc,yc) and obtain the first point on the circumference of a circle centered on the origin as (x0,y0) =
(0,r) i.e.
Initialize starting point as, x = 0, y=r
2- Calculate the initial value of the decision parameter as:
P0 =1-r
3- do
{ plot(x,y)
if (p0<0)
x = x+1
y=y
p1 = p0+2x+1
}
Midpoint Circle algo Contd…
Else
{
x = x+1
y = y-1
p1= p0+2x-2y+1
}
While (x<y)
4. Determine symmetry points in the other seven octants.
5. STOP.
Example
Question: Using mid-point circle algo. plot a circle whose radius is 10 units.
Solution: given r = 10
then initial point (x.y) = (0,r) = (0,10)
X= 0, y = 10
P0 = 1-10 = -9 <0
X = 0+1 = 1
Y = y = 10
P1= -9+2*1+1 = -6 <0
Plot(1,10)
X = 1+1 = 2
Y = 10
P2 = -6+2*2+1 = -1 <0
Plot(2,10)
Solution Contd….
• P = -1+2*3+1 = 6>0
• X = 3+1 = 4
• Y = y-1 = 10-1 = 9
• Plot(4,9)
• P = 6+2*4 - 2*9+1= -3<0
• X = 4+1 = 5
• Y=9
• Plot(5,9)
Solution Contd…
• P = -3+10+1 = 8>0
• Plot(6,8)
• P = 8+12-16+1 = 5>0
• Plot(7,7) x<y
• Stop.
Question:
1. Using mid point circle algo. plot a circle whose radius is 12 unit.
2. Given a circle radius r = 5. using midpoint circle algorithm determine
position along the circle octants in the first quadrant from x = 0 to x = y.
ELLIPSE(Basic Concept)
• The general equation for an ellipse with major axis 2a and minor axis 2b,
centered at the origin is:
(x/a)2 + (x/b)2 = 1 ------------(1)
where, 2a = length of major axis
2b = length of minor axis
Eqn.(1) can be written as,
b2x2 + a2y2 – a2b2 = 0
Ellipse Contd…
• For any given value of x, let xp it will give two values of y such as,
y = ± b√1- x2/a2
And for any given value of y, let yp it will give two values of x such as,
x = ± a√1- y2/b2
Parametric equations for an ellipse
• The parametric form of the equations for the ellipse are,
x = a.cosɵ
y = b. sinɵ
Where ɵ ranges from 0 to 2∏
Now
y/x = b. sinɵ/ a.cosɵ
Or tanα = b/a tanɵ
Ellipse Contd….
From co-ordinate geometry, we get
F(x,y) = b2x2 + a2y2 – a2b2 { <0 implies (x,y) inside the ellipse
{ = 0 implies (x,y) on the ellipse
{ >0 implies (x,y) outside the ellipse
Ellipse Contd…
• An ellipse in standard position is symmetric between quadrants but unlike a
circle, it is not symmetric between the two octants of a quadrant.
• Thus we have to calculate pixel positions along the elliptical arc throughout
one quadrant, then we obtain positions in the remaining 3 quadrants by using
symmetry property .
UNIT-II
Display Technologies
Display Technologies
This includes:
Cathode ray Tube
PLASMA
LCD
Raster Graphics
Construction of Cathode Ray Tube
• The primary components are heated metal cathode and a control
grid.
• The heat is supplied to the cathode, by passing electron through
electron gun, through the filament.
• This way, the electrons get heated up, and start getting ejected out
of cathode filament.
• This stream of negatively charged electron is accelerated towards
the phosphor screen by supplying high positive voltage.
Construction of Cathode Ray Tube Contd..
• This acceleration is produced by means of an accelerating anode.
Next component is Focussing system.
• Focussing system is used to force the electron beam to converge
to small spot on the screen. Without it, electrons will get scattered
because of their own repulsions, due to which we wont get a
sharp image.
• The focussing can be done either by means of electrostatic
means or magnetic fields.
Construction of Cathode Ray Tube Contd..
• In the algorithm, first of all, it is detected whether line lies inside the
screen or it is outside the screen.
• All lines come under any one of the following categories:
• Visible
• Not Visible
• Clipping Case(Partial Visible)
Cohen Sutherland Line Clipping Algorithm
• We will use 4-bits to divide the entire region. These 4 bits represent the Top,
Bottom, Right, and Left of the region as shown in the following figure:
• Here, the TOP and LEFT bit is set to 1 because it is the TOP-LEFT
corner.
Cohen Sutherland Line Clipping Algorithm
Cohen Sutherland Line Clipping Algorithm
• Step 1 − Assign a region code for each endpoints.
• Step 2 − If both endpoints have a region code 0000 then accept this
line.
• Step 3 − Else, perform the logical AND operation for both region
codes.
• Step 3.1 − If the result is not 0000, then reject the line.
• Step 3.2 − Else you need clipping.
•
Cohen Sutherland Line Clipping Algorithm
• Step 3.2.1 − Choose an endpoint of the line that is outside the window.
• Step 3.2.2 − Find the intersection point at the window boundary (base
on region code).
• Step 3.2.3 − Replace endpoint with the intersection point and update
the region code.
• Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially
accepted or trivially rejected.
• Step 4 − Repeat step 1 for other lines.
Assigning a binary code to a point P(x,y)
• Following procedure is used:
(1) Compute:
Bit1- T sign(y – ymax) for top ( since y > ymax)
Bit 2- B sign (ymin – y) for bottom ( since ymin > y)
Bit 3- R sign (x – xmax) for right
Bit 4 - L sign (Xmin – x) for left
(2) Sign value
+ve 1
-ve 0
Example
• Consider the windowport given by (Wxmin, Wymin, Wxmax, Wymax) = (5,
15, 5, 25). Give the binary code for the points.
P1(10,10), P2(20,10), P3(10,30) and P4(20,30).
Solution
For point P1(10,10):
x = 10, y = 10
Now we will find TBRL as,
Sign(y-ymax) = sign(10-25) = -ve → T=0
Sign(ymin – y) = sign (15 – 10) = +ve → B = 1
Sign(x – xmax) = sign (10 – 5) = +ve → R = 1
Sign ( xmin – x) sign (5 – 10) = -ve → L=0
Hence binary code for P1 is 0110.
Solution Contd…
• Similarly we can find binary code for P2, P3 and P4.
P2(20,10) x = 20, y =10
10- 25 = -ve = 0
15 – 10 = +ve = 1
20- 5 = +ve = 1
5-20 = -Ve = 0
P2(20,10) = 0110
Question?
• Using Cohen-Sutherland algorithm to clip line P1(70,20)P2(100,10) against a
clip window whose lower left corner (50,10) and upper right corner is
(80,40).
Solution
Solution Contd…
• According to Cohen-Sutherland Algo,
4-Bit binary code for P1 = 0000
4-Bit binary code for P2 = 0010
Here, Both code are not 0000
Hence we will take AND operation:
Solution Contd…
Solution Contd…
• AND operation gives 0000 i.e this is case of partial visibility,
• Now find the intersection of line P1P2 with right edge of window
• Slope of P1P2, m = (y2-y1)/(x2-x1) = (10-20)/(100-70) = -1/3
• Let intersection point be (x,y)
• Here x = 80, y ?
• P2(x2,y2) = (100,10)
• m = (y – y2)/(x-x2) = (y-10)/(80-100) = -1/3
• i.e → y = 16.66
•
• Hence intersection point P3 = (80,16.66)
• New line will be P1P3.
After clipping
Short cut method for finding Intersection
point
For left window edge, intersection point will be (XL,y)
y = m(XL – x1) + y1 m≠∞
For right window edge, intersection point will be (XR,y)
y = m(XR – x1) + y1 m≠∞
For top window edge, intersection point will be (x,YT)
x = x1 + 1/m(YT – y1) m≠0
For Bottom window edge, intersection point will be (x,YB)
x = x1 + 1/m(YB – y1) m≠0
Question?
• Given a clipping window A(20,20), B(60,20), C(60,40) and D(20,40). Using
Cohen-Sutherland algo find the visible portion of line segment joining the
points P(40,80), Q(120,30).
Solution (Solve yourself)?
• Region code for point P = ?
• Region Code for point Q = ?
Question?
• Let R be the rectangular window whose left-lower hand corner is at L(-3,1) and upper-right
hand corner is at R(2,6).
(i) Find the region code for the endpoints.
(ii) Find the clipping categories for the line segment
(iii) Use Cohen-Sutherland algorithm to clip the line segment
The lines are given as:
Line AB: A(-4,2), B(-1,7)
Line CD: C(-1,5), D(3,8)
Line EF: E(-2,3), F(1,2)
Line GH: G(1,-2), H(3,3)
Solution
• Clip window:
Lower left corner = (-3,1)
Right Upper Corner = (2,6)
Wxmin = -3
Wxmax = 2
Wymin = 1
Wymax = 6
Solution Contd…
(i) The region code(outcode) for point (x,y) is set to
For Top(Bit 1): sign(y-ymax)
For Bottom(Bit 2): sign(ymin – y)
For Right(Bit 3): sign(x – xmax)
For left(Bit 4): sign(xmin – x)
For Line AB:
A = (-4,2) : T = sign( 2 – 6) = -ve = 0
B = sign(1 – 2) = -ve = 0
R = sign(-4 – 2) = -ve = 0
L = sign ( -3 – (-4)) = +ve = 1
A= 0001
B = 1000
C = 0000
D = 1010
Solution
E = 0000
F = 0000
G = 0100
H = 0010
(ii) For line AB:
A = 0001
B = 1000 AND = 0000 -------- Partial Visible
For Line CD:
C = 0000
D = 1010 AND = 0000 ---------- Partial Visible
For line EF :
E = 0000
F = 0000 ----------------------- Visible
Solution Contd…
• For line GH :
G = 0100
H = 0010 AND = 0000 ------------ Partial Visible
Before clipping
Solution Contd…
(iii) The clipping Lines are AB, CD and GH:
For Line AB:
m = (7-2)/(-1+4) = 5/3
5/3 = (y – y2)/ (x – x2)
5/3 = (y – 7) / (-3 + 1) [ since x = -3
y = 11/3
Thus the resulting intersection point is I1 ( -3, 11/3)
Now we clip AI1 segment and work on I1B
Solution Contd…
• The code of I1 is 0000 and category of I1B is partial visible.
Hence B is out side the window its out code = 1000
Hence Taking intersection with top window edge:
5/3 = (y-y2)/(x – x2)
5/3 = (6-11/3)/( x + 3) { since y = 6
x = -8/5
I2(-8/5, 6) = 0000
I1I2. Visivle
Solution Contd…
For line CD:
Ymax = 6
m = (y2-y1)/(X2-x1)
(8-5)/ (3+1) = ¾
¾ = (6-5)/ (x+1)
x = 1/3
I3(1/3, 6) = 0000
Solution Contd…
Foe line GH:
G = 0100
I4(7/3, 1) = 0010
Now we will take I4H.
But segment I4H is not displayed since (0010) AND (0010) = 0010.
Here this is not = 0000.
After Clipping
Mid Point Subdivision Line Clipping
Algorithm
• It is used for clipping line where the line is divided in two parts.
• Mid points of line is obtained by dividing it in two short segments. Again
division is done, by finding midpoint. This process is continued until line of
visible and invisible category is obtained. Let (xm,ym) are midpoint then,
Mid Point Subdivision Line Clipping
Algorithm
Mid Point Subdivision Line Clipping
Algorithm
• Step1: Calculate the position of both endpoints of the line
• Step2: Perform AND operation on both of these endpoints
• Step3:
Perform AND operation on both endpoints.
If AND ≠ 0000
then the line is invisible
else
AND=0000
then the line is clipped case.(Partial Visible)
Mid Point Subdivision Line Clipping
Algorithm
• Step4: For the line to be clipped. Find midpoint
Xm=(x1+x2)/2
Ym=(y1+y2)/2
Xmis midpoint of X coordinate.
Ymis midpoint of Y coordinate.
• Step5: Check each midpoint, whether it nearest to the boundary of a window
or not.
• Step6: If the line is totally visible or totally rejected not found then repeat
step 1 to 5.
• Step7: Stop algorithm.
Example
Find the visible segment to be display in the viewport for the line from
P(60,140) to Q(220,40) in the windowport having range (Wxmin,Wxmax) =
(40,200), (Wymin, Wymax) = (20,120).
P = 1000
Q= 0010 AND = 0000 (partial visible)
Solution
Start Point End Point Mid Point Location of mid point
PEi - P0
P1 - P0
Solution Contd…
Calculate ti :
t1=
Solution Contd…
Here denominator < 0(-10) i.e it is entering point
Solution Contd…
Similarly we can calculate
t2
Solution Contd…
Again D<0(-8) i.e t2 is also entering point.
Solution Contd…
Similarly we get,
t3 = 0/-6 [ Entering point, D<0
t4 = 10/10 [ Leaving point, D>0
t5 = 7/8 [ Leaving point, D >0
t6 = 6/6 [ Leaving point, D>0
Entering Point Leaving Point
-4/-10, -3/-8, 0/-6 10/10, 7/8, 6/6
Solution Contd…
• Now we will take largest value from entering and smallest value from leaving.
Hence; 4/10 and 7/8
Now, at t = 4/10
P(t) = P0 + t(P1 – P0)
= (-2,1) + 4/10[(6,3) – (-2,1)]
= (-2,1) + 4/10(8,2)
= (-2,1) + (16/5, 4/5)
= (-2 +(16/5), 1 + (4/5))
= (6/5, 9/5) Entering Intersection
Solution Contd….
Now at t = 7/8,
P(t) = (-2,1) + 7/8[8,2]
= (5, 11/4) Leaving Intersection
Transformations
Transformation
• Transformation means changing some graphics into something else
by applying rules. All graphics systems allow the programmer to
define picture that include a variety of transformation.
• e.g. the programmer is able to magnify the picture so that it appears
clearly, reduce it, to make it visible or rotate it so that it can be seen in
different angles.
• We can have various types of transformations such as translation,
scaling up or down, rotation, shearing, etc. When a transformation
takes place on a 2D plane, it is called 2D transformation.
2 D Transformation