SlideShare a Scribd company logo
1 of 74
An Efficient Model
for
Line Clipping Operation
Kasun Ranga Wijeweera
(krw19870829@gmail.com)
This Presentation is Based on
Following Research Papers
• S. R. Kodituwakku, K. R. Wijeweera, M. A. P. Chamikara
(2013), An Efficient Algorithm for Line Clipping in Computer
Graphics Programming, Ceylon Journal of Science (Physical
Sciences), Volume 17, pp. 1-7.
• S. R. Kodituwakku, K. R. Wijeweera, M. A. P. Chamikara
(2012), An Efficient Line Clipping Algorithm for 3D Space,
International Journal of Advanced Research in Computer
Science and Software Engineering, Volume 2 (Issue 5), pp.
96-101.
What is Clipping ?
Any procedure which identifies that portion of a scene
which is either inside or outside a region is referred to as
a clipping algorithm or clipping
Line Clipping Algorithms
• In computer graphics, line clipping is the process of
removing lines or portions of lines outside of a region
of interest
• Well known algorithms
– Cohen Sutherland 2D Algorithm
– Cohen Sutherland 3D Algorithm
– Liang Barsky 2D Algorithm
– Liang Barsky 3D Algorithm
Clipping Window : Rectangular
x
y
minx maxx
miny
maxy
Clipping Volume : Cuboidal
x
y
minx maxx
miny
maxy
z
minz
maxz
The Scissoring Method
FOR each point ( x, y ) on the line segment
IF ( x, y ) is inside the region
Save ( x, y )
END IF
END FOR
The Scissoring Method
(Against a Rectangular Window)
Condition:
( x >= minx ) AND ( x <= maxx )
AND
( y >= miny ) AND ( y <= maxy )
The Scissoring Method
(Against a Cuboidal Volume)
Condition:
( x >= minx ) AND ( x <= maxx )
AND
( y >= miny ) AND ( y <= maxy )
AND
( z >= minz ) AND ( z <= maxz )
Problem with the Scissoring Method
Computational cost =
(Cost to evaluate the condition)
*
(Number of points on the line segment)
Problem:
What will happen in high resolution systems?
Proposed Model
• The simplest model ever invented
• Faster than well known clipping algorithms
• Low memory consumption
• Flexible with different shapes of clipping regions
• Easy to extend to higher dimensions
• A single mathematical model
Proposed Model against a Rectangle
• Line segments are divided into four classes
• Let ( x1, y1 ) and ( x2, y2 ) be the end points of the
line segment
x1 = x2 y1 = y2 Nature of the line segment
F F Declined
F T Parallel to x-axis
T F Parallel to y-axis
T T A point
Proposed Model against a Rectangle
(Separation into Classes)
IF { ( x1 != x2 ) AND ( y1 != y2 ) }
// Declined
ELSE IF ( x1 != x2 )
// Parallel to x-axis
ELSE IF ( y1 != y2 )
// Parallel to y-axis
ELSE
// A point
END IF
Proposed Model against a Rectangle
(Separation into Classes)
IF { ( x1 != x2 ) AND ( y1 != y2 ) }
// Declined
ELSE IF ( x1 != x2 )
// Parallel to x-axis
ELSE IF ( y1 != y2 )
// Parallel to y-axis
ELSE
// A point
END IF
Proposed Model against a Rectangle
(Declined)
Equation of the line segment
( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 );
Let’s take
L = x2 – x1;
M = y2 – y1;
Proposed Model against a Rectangle
(Declined)
Using the parameter t,
( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 );
( x – x1) / (x2 – x1 ) = t  t = ( x – x1) / L;
( y – y1 ) / ( y2 – y1 ) = t  t = ( y – y1 ) / M;
Proposed Model against a Rectangle
(Declined)
Using the parameter t,
( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 );
( x – x1) / (x2 – x1 ) = t  x = x1 + L * t;
( y – y1 ) / ( y2 – y1 ) = t  y = y1 + M * t;
Proposed Model against a Rectangle
(Declined)
Intersection with x = p line,
t = ( p –x1) / L;
x = p;
y = y1 + M * t;
Proposed Model against a Rectangle
(Declined)
Intersection with y = q line,
t = ( q – y1) / M;
x = x1 + L * t;
y = q;
Proposed Model against a Rectangle
(Declined)
L = x2 – x1; M = y2 – y1;
FOR each end point ( x, y ) of the line segment
IF ( x < minx )
t = ( minx – x1 ) / L; x = minx; y = y1 + M * t;
ELSE IF ( x > maxx )
t = ( maxx – x1 ) / L; x = maxx; y = y1 + M * t;
IF ( y < miny )
t = ( miny – y1 ) / M; x = x1 + L * t; y = miny;
ELSE IF ( y > maxy )
t = ( maxy – y1 ) / M; x = x1 + L * t; y = maxy;
END IF
END FOR
Proposed Model against a Rectangle
(Declined)
An important observation after code is executed!
IF line segment is completely outside
Both end points become a single point
ELSE
End points are the end points of clipped line segment
END IF
Proposed Model against a Rectangle
(Declined)
Example 1: Line segment is completely inside
B
A
Proposed Model against a Rectangle
(Declined)
Example 2: Line segment is partially inside
B
A
B’
B’’
Proposed Model against a Rectangle
(Declined)
Example 3: Line segment intersects clipping window
B
A
B’
A’
A’’
B’’
Proposed Model against a Rectangle
(Declined)
Example 4: Line segment is completely outside
B
A
A’
A’’
B’
B’’
Proposed Model against a Rectangle
(Declined)
How can we prove this result?
By considering all the possible test cases
1 2 3
4 5 6
7 8 9
Proposed Model against a Rectangle
(Declined)
• One end point can be in 9 regions
• Therefore both the end points can be in 9*9 (= 81)
ways
• Now the problem can be divided into 81 classes
• Each class can be further divided into subclasses
based on dissimilarities
• Since the result is true for all the test cases then the
result is true for all the possible cases
Proposed Model against a Rectangle
(Declined)
Example 1: Both end points are in the region 1
B
A
B’A’
Due to “minx”:
Subclass 1
A’’
B’’
Proposed Model against a Rectangle
(Declined)
Example 1: Both end points are in the region 1
B
A
B’A’
Due to “minx”:
Subclass 2
Proposed Model against a Rectangle
(Declined)
Example 1: Both end points are in the region 1
B
A
B’A’
Due to “minx”:
Subclass 3
A’’
B’’
Proposed Model against a Rectangle
(Declined)
Example 2: End points are in the regions 2 and 4
B
A
Subclass 1
A’
A’’
B’
Proposed Model against a Rectangle
(Declined)
Example 2: End points are in the regions 2 and 4
B
A
Subclass 2 A’
B’
Proposed Model against a Rectangle
(Declined)
An important observation after code is executed!
IF line segment is completely outside
Both end points become a single point
ELSE
End points are the end points of clipped line segment
END IF
Now we have proved the result !
Proposed Model against a Rectangle
(Declined)
IF{ [ abs ( L ) < 1 ] AND [ abs ( M ) < 1 ] }
// Ignore
ELSE
FOR each end point (x, y) of the line segment
x = FLOOR ( x + 0.5 );
y = FLOOR ( y + 0.5 );
END FOR
Line ( x1, y1, x2, y2 );
END IF
Proposed Model against a Rectangle
(Precision Error)
Example 1:
1 / 3 = 0.33333…
• But in computer it is stored as 0.333333
• Therefore checking the exact equality causes a
problem
Proposed Model against a Rectangle
(Precision Error)
Example 2:
• Mathematically; 1 / 3 = 1 - ( 2 / 3 )
• In computer
1 / 3 = 0.333333
2 / 3 = 0.666666
1 - ( 2 / 3 ) = 0.333334 Not equal
Proposed Model against a Rectangle
(Dealing with Precision Error)
• Seek approximate equality instead of exact equality
( x1 = x2 ) AND ( y1 = y2)
is replaced with
[ abs ( L ) < 1 ] AND [ abs ( M ) < 1 ]
Proposed Model against a Rectangle
(Integer Inputs to Line Drawing Algorithms)
• Efficient line drawing algorithms deal only with
integers
– Example: Bresenham line drawing algorithm
• If floating point inputs were provided then they
would be truncated
• Truncation may badly affect the quality of graphics
– Example: ( 3.9, 4.0 )  ( 3, 4 )
• Therefore proper approximation should be done
when converting into integers
Proposed Model against a Rectangle
(Better Approximation)
p = FLOOR ( p + 0.5 )
Example:
10 10.59.5 119
Proposed Model against a Rectangle
(Separation into Classes)
IF { ( x1 != x2 ) AND ( y1 != y2 ) }
// Declined
ELSE IF ( x1 != x2 )
// Parallel to x-axis
ELSE IF ( y1 != y2 )
// Parallel to y-axis
ELSE
// A point
END IF
Proposed Model against a Rectangle
(Parallel to x-axis)
IF { ( y1 >= miny ) AND ( y1 =< maxy ) }
FOR each end point (x, y) of the line segment
IF ( x < minx )
x = minx;
ELSE IF ( x > maxx )
x = maxx;
END IF
END FOR
IF ( x1 != x2 )
Line ( x1, y1, x2, y2 );
END IF
END IF
Proposed Model against a Rectangle
(Parallel to x-axis)
Example 1: Line segment is completely inside
BA
Proposed Model against a Rectangle
(Parallel to x-axis)
Example 2: Line segment is partially inside
BA B’
Proposed Model against a Rectangle
(Parallel to x-axis)
Example 3: Line segment intersects clipping window
BA B’A’
Proposed Model against a Rectangle
(Parallel to x-axis)
Example 4: Line segment is completely outside 1
BA B’
A’
Proposed Model against a Rectangle
(Parallel to x-axis)
Example 5: Line segment is completely outside 2
A B
Proposed Model against a Rectangle
(Separation into Classes)
IF { ( x1 != x2 ) AND ( y1 != y2 ) }
// Declined
ELSE IF ( x1 != x2 )
// Parallel to x-axis
ELSE IF ( y1 != y2 )
// Parallel to y-axis
ELSE
// A point
END IF
Proposed Model against a Rectangle
(Parallel to y-axis)
IF { ( x1 >= minx ) AND ( x1 =< maxx ) }
FOR each end point ( x, y ) of the line segment
IF ( y < miny )
y = miny;
ELSE IF ( y > maxy )
y = maxy;
END IF
END FOR
IF ( y1 != y2 )
Line ( x1, y1, x2, y2 );
END IF
END IF
Proposed Model against a Rectangle
(Parallel to y-axis)
Example 1: Line segment is completely inside
B
A
Proposed Model against a Rectangle
(Parallel to y-axis)
Example 2: Line segment is partially inside
B
A
B’
Proposed Model against a Rectangle
(Parallel to y-axis)
Example 3: Line segment intersects clipping window
B
A
B’
A’
Proposed Model against a Rectangle
(Parallel to y-axis)
Example 4: Line segment is completely outside 1
B
A
B’A’
Proposed Model against a Rectangle
(Parallel to y-axis)
Example 5: Line segment is completely outside 2
B
A
Proposed Model against a Rectangle
(Separation into Classes)
IF { ( x1 != x2 ) AND ( y1 != y2 ) }
// Declined
ELSE IF ( x1 != x2 )
// Parallel to x-axis
ELSE IF ( y1 != y2 )
// Parallel to y-axis
ELSE
// A point
END IF
Proposed Model against a Rectangle
(A Point)
IF <condition>
PutPixel ( x, y );
END IF
Condition:
( x >= minx ) AND ( x <= maxx )
AND
( y >= miny ) AND ( y <= maxy )
Similar to Scissoring Method !
Proposed Model against a Rectangle
(Separation into Classes)
IF { ( x1 != x2 ) AND ( y1 != y2 ) }
// Declined
ELSE IF ( x1 != x2 )
// Parallel to x-axis
ELSE IF ( y1 != y2 )
// Parallel to y-axis
ELSE
// A point
END IF
Proposed Model against a Rectangle
(Experimental Comparison)
• Programming Language:
C++;
• Computer:
Intel(R) Pentium(R) Dual CPU;
E2180 @ 2.00 GHz;
2.00 GHz, 0.98 GB RAM;
• IDE Details:
Turbo C++;
Version 3.0;
Copyright(c) 1990, 1992 by Borland International, Inc;
Proposed Model against a Rectangle
(Experimental Comparison)
Method:
• Clip window with values minx = miny = 100 and maxx =
maxy = 300 was used
• Random points were generated in the range 0 - 399
– randomize() function
• Those random points were used to generate random line
segments
• Number of clock cycles taken by each algorithm to clip
100000000 random line segments were counted
– clock() function
Proposed Model against a Rectangle
(Experimental Results)
Step Cohen-
Sutherland
Liang-
Barsky
Proposed
Algorithm
1 2596 2452 2296
2 2593 2452 2296
3 2594 2452 2296
4 2595 2452 2296
5 2596 2451 2296
6 2593 2451 2296
7 2593 2452 2296
8 2592 2451 2296
9 2593 2452 2296
10 2594 2451 2296
Proposed Model against a Rectangle
(Experimental Comparison)
Average Ratio =
Clock cycles for traditional algorithm
Clock cycles for proposed algorithm
Proposed Model against a Rectangle
(Experimental Comparison)
Average Ratios
Cohen Sutherland: Proposed = 1.1297
Liang Barsky: Proposed = 1.0677
The proposed algorithm is 1.13 times faster than
Cohen Sutherland and 1.07 times faster than
Liang Barsky
Proposed Model against a Cuboid
(Separation into Classes)
• Let ( x1, y1, z1 ) and ( x2, y2, z2 ) be the end points
of the line segment
IF { ( x1 != x2 ) AND ( y1 != y2 ) AND ( z1 != z2 ) }
// Declined
ELSE
// Simply a 2D clipping problem
END IF
Proposed Model against a Cuboid
(Declined)
Equation of the line segment
( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ) = ( z – z1) / ( z2 – z1 );
Let’s take
L = x2 – x1;
M = y2 – y1;
N = z2 – z1;
Proposed Model against a Cuboid
(Declined)
Using the parameter t,
( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ) = ( z – z1) / ( z2 – z1 );
( x – x1) / (x2 – x1 ) = t  t = ( x – x1) / L;
( y – y1 ) / ( y2 – y1 ) = t  t = ( y – y1 ) / M;
( z – z1) / ( z2 – z1 ) = t  t = ( z – z1) / N;
Proposed Model against a Cuboid
(Declined)
Using the parameter t,
( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ) = ( z – z1) / ( z2 – z1 );
( x – x1) / (x2 – x1 ) = t  x = x1 + L * t;
( y – y1 ) / ( y2 – y1 ) = t  y = y1 + M * t;
( z – z1) / ( z2 – z1 ) = t  z = z1 + N * t;
Proposed Model against a Cuboid
(Declined)
Intersection with x = p plane,
t = ( p –x1) / L;
x = p;
y = y1 + M * t;
z = z1 + N * t;
Proposed Model against a Cuboid
(Declined)
Intersection with y = q plane,
t = ( q – y1) / M;
x = x1 + L * t;
y = q;
z = z1 + N * t;
Proposed Model against a Cuboid
(Declined)
Intersection with z = r plane,
t = ( r –z1) / N;
x = x1 + L * t;
y = y1 + M * t;
z = r;
Proposed Model against a Cuboid
(Declined)
L = x1 – x2; M = y1 – y2; N = z1 – z2;
FOR each end point ( x, y ) of the line segment
IF ( x < minx )
t = ( minx –x1) / L; x = minx; y = y1 + M * t; z = z1 + N * t;
ELSE IF ( x > maxx )
t = ( maxx –x1) / L; x = maxx; y = y1 + M * t; z = z1 + N * t;
IF ( y < miny )
t = ( miny – y1) / M; x = x1 + L * t; y = miny; z = z1 + N * t;
ELSE IF ( y > maxy )
t = ( maxy – y1) / M; x = x1 + L * t; y = maxy; z = z1 + N * t;
IF (z < minz )
t = ( minz –z1) / N; x = x1 + L * t; y = y1 + M * t; z = minz;
ELSE IF ( z > maxz )
t = ( maxz –z1) / N; x = x1 + L * t; y = y1 + M * t; z = maxz;
END IF
END FOR
Proposed Model against a Cuboid
(Declined)
IF { [ abs ( L ) < 1 ] AND [ abs ( M ) < 1 ] AND [ abs ( N ) < 1 ] }
// Ignore
ELSE
FOR each end point ( x, y, z ) of the line segment
x = FLOOR ( x + 0.5 );
y = FLOOR ( y + 0.5 );
z = FLOOR ( z + 0.5 );
END FOR
Line ( x1, y1, z1, x2, y2, z2 );
END IF
Proposed Model against a Cuboid
(Proof)
• Consider all the possible test cases
• Proof is done as we did for a rectangular clipping
window
Proposed Model against a Cuboid
(Experimental Comparison)
Average Ratios
Cohen Sutherland: Proposed = 1.1268
Liang Barsky: Proposed = 1.0651
The proposed algorithm is 1.13 times faster than
Cohen Sutherland and 1.07 times faster than
Liang Barsky
Any Questions?
Thank You !

More Related Content

What's hot

Linear Functions
Linear FunctionsLinear Functions
Linear Functionskliegey524
 
Algorithm of some numerical /computational methods
Algorithm of some numerical /computational methodsAlgorithm of some numerical /computational methods
Algorithm of some numerical /computational methodsChandan
 
2.2 linear equations and 2.3 Slope
2.2 linear equations and 2.3 Slope2.2 linear equations and 2.3 Slope
2.2 linear equations and 2.3 SlopeJessica Garcia
 
Graphs of linear equation
Graphs of linear equationGraphs of linear equation
Graphs of linear equationJunila Tejada
 
Math 4 lecture on Graphing Rational Functions
Math 4 lecture on Graphing Rational FunctionsMath 4 lecture on Graphing Rational Functions
Math 4 lecture on Graphing Rational FunctionsLeo Crisologo
 
Open GL T0074 56 sm2
Open GL T0074 56 sm2Open GL T0074 56 sm2
Open GL T0074 56 sm2Roziq Bahtiar
 
Graphing Linear Functions
Graphing Linear FunctionsGraphing Linear Functions
Graphing Linear Functionshisema01
 
Linear functions
Linear functionsLinear functions
Linear functionshalcr1ja
 
6 4 Point Slope Form
6 4 Point Slope Form6 4 Point Slope Form
6 4 Point Slope FormKathy Favazza
 
Even and off functions basic presentation with questions 2
Even and off functions basic presentation with questions 2Even and off functions basic presentation with questions 2
Even and off functions basic presentation with questions 2Jonna Ramsey
 
Module 2 lesson 4 notes
Module 2 lesson 4 notesModule 2 lesson 4 notes
Module 2 lesson 4 notestoni dimella
 
February 16 2016
February 16 2016February 16 2016
February 16 2016khyps13
 
Writing Equations of a Line
Writing Equations of a LineWriting Equations of a Line
Writing Equations of a Lineswartzje
 
4.2 vertex and intercept form
4.2 vertex and intercept form4.2 vertex and intercept form
4.2 vertex and intercept formmorrobea
 
Math Section 2.2 ECC Etudes
Math Section 2.2 ECC EtudesMath Section 2.2 ECC Etudes
Math Section 2.2 ECC EtudesDavidYeeElCamino
 
5.5 parallel perp lines
5.5 parallel perp lines5.5 parallel perp lines
5.5 parallel perp linescageke
 

What's hot (20)

Chapter 5 The Slope Formula
Chapter 5 The Slope FormulaChapter 5 The Slope Formula
Chapter 5 The Slope Formula
 
Linear Functions
Linear FunctionsLinear Functions
Linear Functions
 
2.2 linear equations
2.2 linear equations2.2 linear equations
2.2 linear equations
 
Algorithm of some numerical /computational methods
Algorithm of some numerical /computational methodsAlgorithm of some numerical /computational methods
Algorithm of some numerical /computational methods
 
2.2 linear equations and 2.3 Slope
2.2 linear equations and 2.3 Slope2.2 linear equations and 2.3 Slope
2.2 linear equations and 2.3 Slope
 
Graphs of linear equation
Graphs of linear equationGraphs of linear equation
Graphs of linear equation
 
Math 4 lecture on Graphing Rational Functions
Math 4 lecture on Graphing Rational FunctionsMath 4 lecture on Graphing Rational Functions
Math 4 lecture on Graphing Rational Functions
 
Open GL T0074 56 sm2
Open GL T0074 56 sm2Open GL T0074 56 sm2
Open GL T0074 56 sm2
 
Graphing Linear Functions
Graphing Linear FunctionsGraphing Linear Functions
Graphing Linear Functions
 
Linear functions
Linear functionsLinear functions
Linear functions
 
Graphs
GraphsGraphs
Graphs
 
6 4 Point Slope Form
6 4 Point Slope Form6 4 Point Slope Form
6 4 Point Slope Form
 
Even and off functions basic presentation with questions 2
Even and off functions basic presentation with questions 2Even and off functions basic presentation with questions 2
Even and off functions basic presentation with questions 2
 
Module 2 lesson 4 notes
Module 2 lesson 4 notesModule 2 lesson 4 notes
Module 2 lesson 4 notes
 
February 16 2016
February 16 2016February 16 2016
February 16 2016
 
Writing Equations of a Line
Writing Equations of a LineWriting Equations of a Line
Writing Equations of a Line
 
4.2 vertex and intercept form
4.2 vertex and intercept form4.2 vertex and intercept form
4.2 vertex and intercept form
 
Math Section 2.2 ECC Etudes
Math Section 2.2 ECC EtudesMath Section 2.2 ECC Etudes
Math Section 2.2 ECC Etudes
 
5.5 parallel perp lines
5.5 parallel perp lines5.5 parallel perp lines
5.5 parallel perp lines
 
Calc 3.6b
Calc 3.6bCalc 3.6b
Calc 3.6b
 

Viewers also liked

Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmShilpa Hait
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmMaruf Abdullah (Rion)
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 

Viewers also liked (9)

clipping
clippingclipping
clipping
 
Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )
 
Clipping
ClippingClipping
Clipping
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithm
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
 
Input output
Input outputInput output
Input output
 
Crime file
Crime fileCrime file
Crime file
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Clipping
ClippingClipping
Clipping
 

Similar to An Efficient Model for Line Clipping Operation

CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics PipelineMark Kilgard
 
Straight Lines ( Especially For XI )
Straight Lines ( Especially For XI ) Straight Lines ( Especially For XI )
Straight Lines ( Especially For XI ) Atit Gaonkar
 
Transformations computer graphics
Transformations computer graphics Transformations computer graphics
Transformations computer graphics Vikram Halder
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjtepournima055
 
Edge linking hough transform
Edge linking hough transformEdge linking hough transform
Edge linking hough transformaruna811496
 
Copy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).pptCopy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).pptLeianMartin1
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptchinnurulz
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 

Similar to An Efficient Model for Line Clipping Operation (20)

CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
 
Straight Lines ( Especially For XI )
Straight Lines ( Especially For XI ) Straight Lines ( Especially For XI )
Straight Lines ( Especially For XI )
 
Transformations computer graphics
Transformations computer graphics Transformations computer graphics
Transformations computer graphics
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
ae_722_unstructured_meshes.ppt
ae_722_unstructured_meshes.pptae_722_unstructured_meshes.ppt
ae_722_unstructured_meshes.ppt
 
1519 differentiation-integration-02
1519 differentiation-integration-021519 differentiation-integration-02
1519 differentiation-integration-02
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Teknik Simulasi
Teknik SimulasiTeknik Simulasi
Teknik Simulasi
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Optimisation random graph presentation
Optimisation random graph presentationOptimisation random graph presentation
Optimisation random graph presentation
 
Edge linking hough transform
Edge linking hough transformEdge linking hough transform
Edge linking hough transform
 
3 D Graphics
3 D Graphics3 D Graphics
3 D Graphics
 
MATHS SYMBOLS.pdf
MATHS SYMBOLS.pdfMATHS SYMBOLS.pdf
MATHS SYMBOLS.pdf
 
Copy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).pptCopy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).ppt
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.ppt
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.ppt
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.ppt
 
Drawing Tools
Drawing ToolsDrawing Tools
Drawing Tools
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 

More from Kasun Ranga Wijeweera

Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonKasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingKasun Ranga Wijeweera
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic ProgrammingKasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingKasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Kasun Ranga Wijeweera
 

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 

Recently uploaded

Quarter 4_Grade 8_Digestive System Structure and Functions
Quarter 4_Grade 8_Digestive System Structure and FunctionsQuarter 4_Grade 8_Digestive System Structure and Functions
Quarter 4_Grade 8_Digestive System Structure and FunctionsCharlene Llagas
 
trihybrid cross , test cross chi squares
trihybrid cross , test cross chi squarestrihybrid cross , test cross chi squares
trihybrid cross , test cross chi squaresusmanzain586
 
OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024innovationoecd
 
Topic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxTopic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxJorenAcuavera1
 
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...Universidade Federal de Sergipe - UFS
 
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdfPests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdfPirithiRaju
 
Introduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxIntroduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxMedical College
 
Davis plaque method.pptx recombinant DNA technology
Davis plaque method.pptx recombinant DNA technologyDavis plaque method.pptx recombinant DNA technology
Davis plaque method.pptx recombinant DNA technologycaarthichand2003
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024AyushiRastogi48
 
The dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptxThe dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptxEran Akiva Sinbar
 
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxmaryFF1
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentationtahreemzahra82
 
User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)Columbia Weather Systems
 
Base editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editingBase editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editingNetHelix
 
bonjourmadame.tumblr.com bhaskar's girls
bonjourmadame.tumblr.com bhaskar's girlsbonjourmadame.tumblr.com bhaskar's girls
bonjourmadame.tumblr.com bhaskar's girlshansessene
 
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests GlycosidesGLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests GlycosidesNandakishor Bhaurao Deshmukh
 
Biological classification of plants with detail
Biological classification of plants with detailBiological classification of plants with detail
Biological classification of plants with detailhaiderbaloch3
 
Pests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPirithiRaju
 

Recently uploaded (20)

Quarter 4_Grade 8_Digestive System Structure and Functions
Quarter 4_Grade 8_Digestive System Structure and FunctionsQuarter 4_Grade 8_Digestive System Structure and Functions
Quarter 4_Grade 8_Digestive System Structure and Functions
 
trihybrid cross , test cross chi squares
trihybrid cross , test cross chi squarestrihybrid cross , test cross chi squares
trihybrid cross , test cross chi squares
 
OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024
 
Topic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxTopic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptx
 
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
 
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdfPests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdf
 
Introduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxIntroduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptx
 
Davis plaque method.pptx recombinant DNA technology
Davis plaque method.pptx recombinant DNA technologyDavis plaque method.pptx recombinant DNA technology
Davis plaque method.pptx recombinant DNA technology
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024
 
The dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptxThe dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptx
 
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
 
Let’s Say Someone Did Drop the Bomb. Then What?
Let’s Say Someone Did Drop the Bomb. Then What?Let’s Say Someone Did Drop the Bomb. Then What?
Let’s Say Someone Did Drop the Bomb. Then What?
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentation
 
User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)
 
Base editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editingBase editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editing
 
bonjourmadame.tumblr.com bhaskar's girls
bonjourmadame.tumblr.com bhaskar's girlsbonjourmadame.tumblr.com bhaskar's girls
bonjourmadame.tumblr.com bhaskar's girls
 
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests GlycosidesGLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
 
AZOTOBACTER AS BIOFERILIZER.PPTX
AZOTOBACTER AS BIOFERILIZER.PPTXAZOTOBACTER AS BIOFERILIZER.PPTX
AZOTOBACTER AS BIOFERILIZER.PPTX
 
Biological classification of plants with detail
Biological classification of plants with detailBiological classification of plants with detail
Biological classification of plants with detail
 
Pests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdf
 

An Efficient Model for Line Clipping Operation

  • 1. An Efficient Model for Line Clipping Operation Kasun Ranga Wijeweera (krw19870829@gmail.com)
  • 2. This Presentation is Based on Following Research Papers • S. R. Kodituwakku, K. R. Wijeweera, M. A. P. Chamikara (2013), An Efficient Algorithm for Line Clipping in Computer Graphics Programming, Ceylon Journal of Science (Physical Sciences), Volume 17, pp. 1-7. • S. R. Kodituwakku, K. R. Wijeweera, M. A. P. Chamikara (2012), An Efficient Line Clipping Algorithm for 3D Space, International Journal of Advanced Research in Computer Science and Software Engineering, Volume 2 (Issue 5), pp. 96-101.
  • 3. What is Clipping ? Any procedure which identifies that portion of a scene which is either inside or outside a region is referred to as a clipping algorithm or clipping
  • 4. Line Clipping Algorithms • In computer graphics, line clipping is the process of removing lines or portions of lines outside of a region of interest • Well known algorithms – Cohen Sutherland 2D Algorithm – Cohen Sutherland 3D Algorithm – Liang Barsky 2D Algorithm – Liang Barsky 3D Algorithm
  • 5. Clipping Window : Rectangular x y minx maxx miny maxy
  • 6. Clipping Volume : Cuboidal x y minx maxx miny maxy z minz maxz
  • 7. The Scissoring Method FOR each point ( x, y ) on the line segment IF ( x, y ) is inside the region Save ( x, y ) END IF END FOR
  • 8. The Scissoring Method (Against a Rectangular Window) Condition: ( x >= minx ) AND ( x <= maxx ) AND ( y >= miny ) AND ( y <= maxy )
  • 9. The Scissoring Method (Against a Cuboidal Volume) Condition: ( x >= minx ) AND ( x <= maxx ) AND ( y >= miny ) AND ( y <= maxy ) AND ( z >= minz ) AND ( z <= maxz )
  • 10. Problem with the Scissoring Method Computational cost = (Cost to evaluate the condition) * (Number of points on the line segment) Problem: What will happen in high resolution systems?
  • 11. Proposed Model • The simplest model ever invented • Faster than well known clipping algorithms • Low memory consumption • Flexible with different shapes of clipping regions • Easy to extend to higher dimensions • A single mathematical model
  • 12. Proposed Model against a Rectangle • Line segments are divided into four classes • Let ( x1, y1 ) and ( x2, y2 ) be the end points of the line segment x1 = x2 y1 = y2 Nature of the line segment F F Declined F T Parallel to x-axis T F Parallel to y-axis T T A point
  • 13. Proposed Model against a Rectangle (Separation into Classes) IF { ( x1 != x2 ) AND ( y1 != y2 ) } // Declined ELSE IF ( x1 != x2 ) // Parallel to x-axis ELSE IF ( y1 != y2 ) // Parallel to y-axis ELSE // A point END IF
  • 14. Proposed Model against a Rectangle (Separation into Classes) IF { ( x1 != x2 ) AND ( y1 != y2 ) } // Declined ELSE IF ( x1 != x2 ) // Parallel to x-axis ELSE IF ( y1 != y2 ) // Parallel to y-axis ELSE // A point END IF
  • 15. Proposed Model against a Rectangle (Declined) Equation of the line segment ( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ); Let’s take L = x2 – x1; M = y2 – y1;
  • 16. Proposed Model against a Rectangle (Declined) Using the parameter t, ( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ); ( x – x1) / (x2 – x1 ) = t  t = ( x – x1) / L; ( y – y1 ) / ( y2 – y1 ) = t  t = ( y – y1 ) / M;
  • 17. Proposed Model against a Rectangle (Declined) Using the parameter t, ( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ); ( x – x1) / (x2 – x1 ) = t  x = x1 + L * t; ( y – y1 ) / ( y2 – y1 ) = t  y = y1 + M * t;
  • 18. Proposed Model against a Rectangle (Declined) Intersection with x = p line, t = ( p –x1) / L; x = p; y = y1 + M * t;
  • 19. Proposed Model against a Rectangle (Declined) Intersection with y = q line, t = ( q – y1) / M; x = x1 + L * t; y = q;
  • 20. Proposed Model against a Rectangle (Declined) L = x2 – x1; M = y2 – y1; FOR each end point ( x, y ) of the line segment IF ( x < minx ) t = ( minx – x1 ) / L; x = minx; y = y1 + M * t; ELSE IF ( x > maxx ) t = ( maxx – x1 ) / L; x = maxx; y = y1 + M * t; IF ( y < miny ) t = ( miny – y1 ) / M; x = x1 + L * t; y = miny; ELSE IF ( y > maxy ) t = ( maxy – y1 ) / M; x = x1 + L * t; y = maxy; END IF END FOR
  • 21. Proposed Model against a Rectangle (Declined) An important observation after code is executed! IF line segment is completely outside Both end points become a single point ELSE End points are the end points of clipped line segment END IF
  • 22. Proposed Model against a Rectangle (Declined) Example 1: Line segment is completely inside B A
  • 23. Proposed Model against a Rectangle (Declined) Example 2: Line segment is partially inside B A B’ B’’
  • 24. Proposed Model against a Rectangle (Declined) Example 3: Line segment intersects clipping window B A B’ A’ A’’ B’’
  • 25. Proposed Model against a Rectangle (Declined) Example 4: Line segment is completely outside B A A’ A’’ B’ B’’
  • 26. Proposed Model against a Rectangle (Declined) How can we prove this result? By considering all the possible test cases 1 2 3 4 5 6 7 8 9
  • 27. Proposed Model against a Rectangle (Declined) • One end point can be in 9 regions • Therefore both the end points can be in 9*9 (= 81) ways • Now the problem can be divided into 81 classes • Each class can be further divided into subclasses based on dissimilarities • Since the result is true for all the test cases then the result is true for all the possible cases
  • 28. Proposed Model against a Rectangle (Declined) Example 1: Both end points are in the region 1 B A B’A’ Due to “minx”: Subclass 1 A’’ B’’
  • 29. Proposed Model against a Rectangle (Declined) Example 1: Both end points are in the region 1 B A B’A’ Due to “minx”: Subclass 2
  • 30. Proposed Model against a Rectangle (Declined) Example 1: Both end points are in the region 1 B A B’A’ Due to “minx”: Subclass 3 A’’ B’’
  • 31. Proposed Model against a Rectangle (Declined) Example 2: End points are in the regions 2 and 4 B A Subclass 1 A’ A’’ B’
  • 32. Proposed Model against a Rectangle (Declined) Example 2: End points are in the regions 2 and 4 B A Subclass 2 A’ B’
  • 33. Proposed Model against a Rectangle (Declined) An important observation after code is executed! IF line segment is completely outside Both end points become a single point ELSE End points are the end points of clipped line segment END IF Now we have proved the result !
  • 34. Proposed Model against a Rectangle (Declined) IF{ [ abs ( L ) < 1 ] AND [ abs ( M ) < 1 ] } // Ignore ELSE FOR each end point (x, y) of the line segment x = FLOOR ( x + 0.5 ); y = FLOOR ( y + 0.5 ); END FOR Line ( x1, y1, x2, y2 ); END IF
  • 35. Proposed Model against a Rectangle (Precision Error) Example 1: 1 / 3 = 0.33333… • But in computer it is stored as 0.333333 • Therefore checking the exact equality causes a problem
  • 36. Proposed Model against a Rectangle (Precision Error) Example 2: • Mathematically; 1 / 3 = 1 - ( 2 / 3 ) • In computer 1 / 3 = 0.333333 2 / 3 = 0.666666 1 - ( 2 / 3 ) = 0.333334 Not equal
  • 37. Proposed Model against a Rectangle (Dealing with Precision Error) • Seek approximate equality instead of exact equality ( x1 = x2 ) AND ( y1 = y2) is replaced with [ abs ( L ) < 1 ] AND [ abs ( M ) < 1 ]
  • 38. Proposed Model against a Rectangle (Integer Inputs to Line Drawing Algorithms) • Efficient line drawing algorithms deal only with integers – Example: Bresenham line drawing algorithm • If floating point inputs were provided then they would be truncated • Truncation may badly affect the quality of graphics – Example: ( 3.9, 4.0 )  ( 3, 4 ) • Therefore proper approximation should be done when converting into integers
  • 39. Proposed Model against a Rectangle (Better Approximation) p = FLOOR ( p + 0.5 ) Example: 10 10.59.5 119
  • 40. Proposed Model against a Rectangle (Separation into Classes) IF { ( x1 != x2 ) AND ( y1 != y2 ) } // Declined ELSE IF ( x1 != x2 ) // Parallel to x-axis ELSE IF ( y1 != y2 ) // Parallel to y-axis ELSE // A point END IF
  • 41. Proposed Model against a Rectangle (Parallel to x-axis) IF { ( y1 >= miny ) AND ( y1 =< maxy ) } FOR each end point (x, y) of the line segment IF ( x < minx ) x = minx; ELSE IF ( x > maxx ) x = maxx; END IF END FOR IF ( x1 != x2 ) Line ( x1, y1, x2, y2 ); END IF END IF
  • 42. Proposed Model against a Rectangle (Parallel to x-axis) Example 1: Line segment is completely inside BA
  • 43. Proposed Model against a Rectangle (Parallel to x-axis) Example 2: Line segment is partially inside BA B’
  • 44. Proposed Model against a Rectangle (Parallel to x-axis) Example 3: Line segment intersects clipping window BA B’A’
  • 45. Proposed Model against a Rectangle (Parallel to x-axis) Example 4: Line segment is completely outside 1 BA B’ A’
  • 46. Proposed Model against a Rectangle (Parallel to x-axis) Example 5: Line segment is completely outside 2 A B
  • 47. Proposed Model against a Rectangle (Separation into Classes) IF { ( x1 != x2 ) AND ( y1 != y2 ) } // Declined ELSE IF ( x1 != x2 ) // Parallel to x-axis ELSE IF ( y1 != y2 ) // Parallel to y-axis ELSE // A point END IF
  • 48. Proposed Model against a Rectangle (Parallel to y-axis) IF { ( x1 >= minx ) AND ( x1 =< maxx ) } FOR each end point ( x, y ) of the line segment IF ( y < miny ) y = miny; ELSE IF ( y > maxy ) y = maxy; END IF END FOR IF ( y1 != y2 ) Line ( x1, y1, x2, y2 ); END IF END IF
  • 49. Proposed Model against a Rectangle (Parallel to y-axis) Example 1: Line segment is completely inside B A
  • 50. Proposed Model against a Rectangle (Parallel to y-axis) Example 2: Line segment is partially inside B A B’
  • 51. Proposed Model against a Rectangle (Parallel to y-axis) Example 3: Line segment intersects clipping window B A B’ A’
  • 52. Proposed Model against a Rectangle (Parallel to y-axis) Example 4: Line segment is completely outside 1 B A B’A’
  • 53. Proposed Model against a Rectangle (Parallel to y-axis) Example 5: Line segment is completely outside 2 B A
  • 54. Proposed Model against a Rectangle (Separation into Classes) IF { ( x1 != x2 ) AND ( y1 != y2 ) } // Declined ELSE IF ( x1 != x2 ) // Parallel to x-axis ELSE IF ( y1 != y2 ) // Parallel to y-axis ELSE // A point END IF
  • 55. Proposed Model against a Rectangle (A Point) IF <condition> PutPixel ( x, y ); END IF Condition: ( x >= minx ) AND ( x <= maxx ) AND ( y >= miny ) AND ( y <= maxy ) Similar to Scissoring Method !
  • 56. Proposed Model against a Rectangle (Separation into Classes) IF { ( x1 != x2 ) AND ( y1 != y2 ) } // Declined ELSE IF ( x1 != x2 ) // Parallel to x-axis ELSE IF ( y1 != y2 ) // Parallel to y-axis ELSE // A point END IF
  • 57. Proposed Model against a Rectangle (Experimental Comparison) • Programming Language: C++; • Computer: Intel(R) Pentium(R) Dual CPU; E2180 @ 2.00 GHz; 2.00 GHz, 0.98 GB RAM; • IDE Details: Turbo C++; Version 3.0; Copyright(c) 1990, 1992 by Borland International, Inc;
  • 58. Proposed Model against a Rectangle (Experimental Comparison) Method: • Clip window with values minx = miny = 100 and maxx = maxy = 300 was used • Random points were generated in the range 0 - 399 – randomize() function • Those random points were used to generate random line segments • Number of clock cycles taken by each algorithm to clip 100000000 random line segments were counted – clock() function
  • 59. Proposed Model against a Rectangle (Experimental Results) Step Cohen- Sutherland Liang- Barsky Proposed Algorithm 1 2596 2452 2296 2 2593 2452 2296 3 2594 2452 2296 4 2595 2452 2296 5 2596 2451 2296 6 2593 2451 2296 7 2593 2452 2296 8 2592 2451 2296 9 2593 2452 2296 10 2594 2451 2296
  • 60. Proposed Model against a Rectangle (Experimental Comparison) Average Ratio = Clock cycles for traditional algorithm Clock cycles for proposed algorithm
  • 61. Proposed Model against a Rectangle (Experimental Comparison) Average Ratios Cohen Sutherland: Proposed = 1.1297 Liang Barsky: Proposed = 1.0677 The proposed algorithm is 1.13 times faster than Cohen Sutherland and 1.07 times faster than Liang Barsky
  • 62. Proposed Model against a Cuboid (Separation into Classes) • Let ( x1, y1, z1 ) and ( x2, y2, z2 ) be the end points of the line segment IF { ( x1 != x2 ) AND ( y1 != y2 ) AND ( z1 != z2 ) } // Declined ELSE // Simply a 2D clipping problem END IF
  • 63. Proposed Model against a Cuboid (Declined) Equation of the line segment ( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ) = ( z – z1) / ( z2 – z1 ); Let’s take L = x2 – x1; M = y2 – y1; N = z2 – z1;
  • 64. Proposed Model against a Cuboid (Declined) Using the parameter t, ( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ) = ( z – z1) / ( z2 – z1 ); ( x – x1) / (x2 – x1 ) = t  t = ( x – x1) / L; ( y – y1 ) / ( y2 – y1 ) = t  t = ( y – y1 ) / M; ( z – z1) / ( z2 – z1 ) = t  t = ( z – z1) / N;
  • 65. Proposed Model against a Cuboid (Declined) Using the parameter t, ( x – x1) / (x2 – x1 ) = ( y – y1 ) / ( y2 – y1 ) = ( z – z1) / ( z2 – z1 ); ( x – x1) / (x2 – x1 ) = t  x = x1 + L * t; ( y – y1 ) / ( y2 – y1 ) = t  y = y1 + M * t; ( z – z1) / ( z2 – z1 ) = t  z = z1 + N * t;
  • 66. Proposed Model against a Cuboid (Declined) Intersection with x = p plane, t = ( p –x1) / L; x = p; y = y1 + M * t; z = z1 + N * t;
  • 67. Proposed Model against a Cuboid (Declined) Intersection with y = q plane, t = ( q – y1) / M; x = x1 + L * t; y = q; z = z1 + N * t;
  • 68. Proposed Model against a Cuboid (Declined) Intersection with z = r plane, t = ( r –z1) / N; x = x1 + L * t; y = y1 + M * t; z = r;
  • 69. Proposed Model against a Cuboid (Declined) L = x1 – x2; M = y1 – y2; N = z1 – z2; FOR each end point ( x, y ) of the line segment IF ( x < minx ) t = ( minx –x1) / L; x = minx; y = y1 + M * t; z = z1 + N * t; ELSE IF ( x > maxx ) t = ( maxx –x1) / L; x = maxx; y = y1 + M * t; z = z1 + N * t; IF ( y < miny ) t = ( miny – y1) / M; x = x1 + L * t; y = miny; z = z1 + N * t; ELSE IF ( y > maxy ) t = ( maxy – y1) / M; x = x1 + L * t; y = maxy; z = z1 + N * t; IF (z < minz ) t = ( minz –z1) / N; x = x1 + L * t; y = y1 + M * t; z = minz; ELSE IF ( z > maxz ) t = ( maxz –z1) / N; x = x1 + L * t; y = y1 + M * t; z = maxz; END IF END FOR
  • 70. Proposed Model against a Cuboid (Declined) IF { [ abs ( L ) < 1 ] AND [ abs ( M ) < 1 ] AND [ abs ( N ) < 1 ] } // Ignore ELSE FOR each end point ( x, y, z ) of the line segment x = FLOOR ( x + 0.5 ); y = FLOOR ( y + 0.5 ); z = FLOOR ( z + 0.5 ); END FOR Line ( x1, y1, z1, x2, y2, z2 ); END IF
  • 71. Proposed Model against a Cuboid (Proof) • Consider all the possible test cases • Proof is done as we did for a rectangular clipping window
  • 72. Proposed Model against a Cuboid (Experimental Comparison) Average Ratios Cohen Sutherland: Proposed = 1.1268 Liang Barsky: Proposed = 1.0651 The proposed algorithm is 1.13 times faster than Cohen Sutherland and 1.07 times faster than Liang Barsky