SlideShare una empresa de Scribd logo
1 de 5
Descargar para leer sin conexión
1
Elementary raster algorithms forElementary raster algorithms for
fast renderingfast rendering
Elementary RenderingElementary Rendering
nn Geometric PrimitivesGeometric Primitives
–– Line processingLine processing
–– Polygon processingPolygon processing
nn Managing OpenGL StateManaging OpenGL State
nn OpenGL BuffersOpenGL Buffers
OpenGL Geometric PrimitivesOpenGL Geometric Primitives
nn All geometric primitives are specified byAll geometric primitives are specified by
verticesvertices
GL_QUAD_STRIPGL_QUAD_STRIP
GL_POLYGONGL_POLYGON
GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN
GL_POINTSGL_POINTS
GL_LINESGL_LINES
GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP
GL_TRIANGLESGL_TRIANGLES
GL_QUADSGL_QUADS
Design of Line AlgorithmsDesign of Line Algorithms
Why Lines?Why Lines?
nn Lines:Lines:
–– Most common 2D primitiveMost common 2D primitive -- done 100s or 1000sdone 100s or 1000s
of times each frame, even 3Dof times each frame, even 3D wireframeswireframes areare
eventually 2D lines!eventually 2D lines!
–– Lines areLines are compatiblecompatible with vector displays butwith vector displays but
nowadays most displays are raster displays. Anynowadays most displays are raster displays. Any
render stage beforerender stage before vizviz might needmight need discretizationdiscretization..
–– Optimized algorithms contain numerousOptimized algorithms contain numerous
tricks/techniques that help in designing moretricks/techniques that help in designing more
advanced algorithms for line processing.advanced algorithms for line processing.
Line Algorithms in the OpenGLLine Algorithms in the OpenGL
ArchitectureArchitecture
Display
List
Polynomial
Evaluator
Per Vertex
Operations &
Primitive
Assembly
Rasterization
Per Fragment
Operations
Frame
Buffer
Texture
Memory
CPU
Pixel
Operations
2
Line RequirementsLine Requirements
nn Must compute integer coordinates of pixels which lie on or nearMust compute integer coordinates of pixels which lie on or near aa
line or circle.line or circle.
nn Pixel level algorithms are invoked hundreds or thousands of timePixel level algorithms are invoked hundreds or thousands of timess
when an image is created or modifiedwhen an image is created or modified –– must be fast!must be fast!
nn Lines must create visually satisfactory images.Lines must create visually satisfactory images.
–– Lines should appear straightLines should appear straight
–– Lines should terminate accuratelyLines should terminate accurately
–– Lines should have constant densityLines should have constant density
nn Line algorithm should always be defined.Line algorithm should always be defined.
Basic Math ReviewBasic Math Review
PointPoint--slope Formula For a Lineslope Formula For a Line
Given two points (XGiven two points (X11,Y,Y11), (X), (X22, Y, Y22))
Consider a third point on the line:Consider a third point on the line:
P = (X,Y)P = (X,Y)
Slope = (YSlope = (Y22 -- YY11)/(X)/(X22 -- XX11))
= (Y= (Y -- YY11)/(X)/(X -- XX11))
Solving For YSolving For Y
Y = [(YY = [(Y22--YY11)/(X)/(X22--XX11)]*(X)]*(X--XX11)+ Y)+ Y11
or, plug in the point (0, b) to getor, plug in the point (0, b) to get
thethe SlopeSlope--intercept form:intercept form:
Y =Y = mxmx + b+ b
Cartesian Coordinate System
2
4
1 2 3 4 5 6
3
5
6
1 P1 = (X1,Y1)
P2 = (X2,Y2)
P = (X,Y)
SLOPE =
RISE
RUN
=
Y2-Y1
X2-X1
Other Helpful FormulasOther Helpful Formulas
nn Length of line segment between PLength of line segment between P11 and Pand P22::
L =L =
nn Midpoint of a line segment between PMidpoint of a line segment between P11 andand
PP33::
PP22 = ( (X= ( (X11+X+X33)/2 , (Y)/2 , (Y 11+Y+Y33)/2 ))/2 )
nn Two lines areTwo lines are perpendicularperpendicular iffiff
1) M1) M11 == --1/M1/M22
2) Cosine of the angle between them is 0.2) Cosine of the angle between them is 0.
2
12
2
12 )()( yyxx −+−
Using this information, whatUsing this information, what
are some possible algorithmsare some possible algorithms
for line drawing?for line drawing?
Parametric FormParametric Form
Given points PGiven points P11 = (X= (X11, Y, Y11) and P) and P22 = (X= (X22, Y, Y22))
X = XX = X11 + t(X+ t(X22--XX11))
Y = YY = Y11 + t(Y+ t(Y22--YY11))
t is called the parameter. Whent is called the parameter. When
t = 0 we get (Xt = 0 we get (X11,Y,Y11))
t = 1 we get (Xt = 1 we get (X22,Y,Y22))
As 0 < t < 1 we get all the other points on the line segmentAs 0 < t < 1 we get all the other points on the line segment
between (Xbetween (X11,Y,Y11) and (X) and (X22,Y,Y22).).
New algorithm ideas based onNew algorithm ideas based on
parametric form?parametric form?
3
Simple DDA* Line AlgorithmSimple DDA* Line Algorithm
voidvoid DDA(intDDA(int X1,Y1,X2,Y2)X1,Y1,X2,Y2)
{{
intint Length, I;Length, I;
floatfloat X,Y,Xinc,YincX,Y,Xinc,Yinc;;
Length = ABS(X2Length = ABS(X2 -- X1);X1);
if (ABS(Y2if (ABS(Y2 -- Y1) > Length)Y1) > Length)
Length = ABS(Y2Length = ABS(Y2--Y1);Y1);
XincXinc = (X2= (X2 -- X1)/Length;X1)/Length;
YincYinc = (Y2= (Y2 -- Y1)/Length;Y1)/Length;
*DDA: Digital Differential Analyzer*DDA: Digital Differential Analyzer
X = X1;
Y = Y1;
while(X<X2){
Plot(Round(X),Round(Y));
X = X + Xinc;
Y = Y + Yinc;
}
}
DDA creates good lines but it is too time consuming due to the rDDA creates good lines but it is too time consuming due to the roundound
function and long operations on real values.function and long operations on real values.
Compute which pixels should be turned on to
represent the line from (6,9) to (11,12).
Length = ?
Xinc = ?
Yinc = ?
DDA ExampleDDA Example
6 7 8 9 10 11 12 13
9
10
11
12
13
DDA ExampleDDA Example
Line from (6,9) to (11,12).Line from (6,9) to (11,12).
Length := Max of (ABS(11Length := Max of (ABS(11--6), ABS(126), ABS(12--9)) = 59)) = 5
XincXinc := 1:= 1
YincYinc := 0.6:= 0.6
Values computed are:Values computed are:
(6,9), (7,9.6),(6,9), (7,9.6),
(8,10.2), (9,10.8),(8,10.2), (9,10.8),
(10,11.4), (11,12)(10,11.4), (11,12)
6 7 8 9 10 11 12 13
9
10
11
12
13
Fast LinesFast Lines –– Midpoint MethodMidpoint Method
nn Simplifying assumptions: AssumeSimplifying assumptions: Assume
we wish to draw a line betweenwe wish to draw a line between
points (0,0) and (a,b) with slope mpoints (0,0) and (a,b) with slope m
between 0 and 1 (i.e. line lies in firstbetween 0 and 1 (i.e. line lies in first
octant).octant).
nn The general formula for a line isThe general formula for a line is yy
== mxmx + B+ B wherewhere mm is the slope ofis the slope of
the line andthe line and BB is the yis the y--intercept.intercept.
From our assumptionsFrom our assumptions mm = b/a and= b/a and
BB = 0.= 0.
nn y = (b/a)x + 0y = (b/a)x + 0 ---->> f(x,y) =f(x,y) = bxbx -- ayay
= 0= 0 is an equation for the line.is an equation for the line.
+x-x
-y
+y
Having turned on pixel P at (xHaving turned on pixel P at (xii,, yyii), the next pixel is NE at (x), the next pixel is NE at (xii+1,+1,
yyii+1) or E at (x+1) or E at (xii+1,+1, yyii). Choose the pixel closer to the line). Choose the pixel closer to the line
f(x, y) =f(x, y) = bxbx -- ay = 0.ay = 0.
Fast Lines (cont.)Fast Lines (cont.)
For lines in the first octant,For lines in the first octant,
given one pixel on thegiven one pixel on the
line, the next pixel is toline, the next pixel is to
the right (E) or to thethe right (E) or to the
right and up (NE).right and up (NE).
P = (xi ,yi ) E = (xi + 1, yi)
NE = (xi + 1, yi + 1)
current pixel possible
next pixels
Fast Lines (cont.)Fast Lines (cont.)
The midpoint between pixels E
and NE is (xi + 1, yi + ½).
Let e be the “upward”
distance between the midpoint
and where the line actually
crosses between E and NE. If
e is positive the line crosses
above the midpoint and is
closer to NE. If e is
negative, the line crosses
below the midpoint and is
closer to E. To pick the
correct point we only need to
know the sign of e.
(xi +1, yi + ½ + e)
e
(xi +1, yi + ½)
P = (xi ,yi ) E = (xi + 1, yi)
NE = (xi + 1, yi + 1)
4
The Decision VariableThe Decision Variable
f(xf(xii+1,+1, yy ii+ ½ + e) = 0 (point on line)+ ½ + e) = 0 (point on line)
== b(xb(xii + 1)+ 1) -- a(ya(y ii+ ½ + e)+ ½ + e)
== b(xb(xii + 1)+ 1) -- a(ya(y ii + ½)+ ½) –– aeae
== f(xf(xii + 1,+ 1, yy ii + ½)+ ½) -- aeae
LetLet ddii == f(xf(xii + 1,+ 1, yy ii + ½) =+ ½) = aeae;; ddii is known as theis known as the decisiondecision
variablevariable..
Since a = 0,Since a = 0, ddii has the same sign as ehas the same sign as e..
Therefore, we only need to know the value ofTherefore, we only need to know the value of ddii to choose betweento choose between
pixels E and NE. Ifpixels E and NE. If ddii = 0 choose NE, else choose E.= 0 choose NE, else choose E.
ButBut, calculating, calculating ddii directly each time requires at least two adds, adirectly each time requires at least two adds, a
subtract, and two multipliessubtract, and two multiplies --> too slow!> too slow!
è f(xi + 1, yi + ½) = ae
Decision VariableDecision Variable
calculationcalculation
Algorithm:Algorithm:
Calculate dCalculate d00 directly, then for each i >= 0:directly, then for each i >= 0:
ifif ddii = 0 Then= 0 Then
Choose NE = (xChoose NE = (xii + 1,+ 1, yy ii + 1) as next point+ 1) as next point
ddi+1i+1 = f(x= f(xi+1i+1 + 1, y+ 1, y i+1i+1 + ½) =+ ½) = f(xf(xii + 1 + 1,+ 1 + 1, yy ii + 1 + ½)+ 1 + ½)
== b(xb(xii + 1 + 1)+ 1 + 1) -- a(ya(y ii + 1 + ½) =+ 1 + ½) = f(xf(xii + 1,+ 1, yy ii + ½) + b+ ½) + b -- aa
== ddii + b+ b -- aa
elseelse
Choose E = (xChoose E = (xii + 1,+ 1, yy ii) as next point) as next point
ddi+1i+1 = f(x= f(xi+1i+1 + 1, y+ 1, y i+1i+1 + ½) =+ ½) = f(xf(xii + 1 + 1,+ 1 + 1, yy ii + ½)+ ½)
== b(xb(xii + 1 + 1)+ 1 + 1) -- a(ya(y ii + ½) =+ ½) = f(xf(xii + 1,+ 1, yy ii + ½) + b+ ½) + b
== ddii + b+ b
èè KnowingKnowing ddii, we need only add a, we need only add a constantconstant term to find dterm to find di+1i+1 !!
else {else {
x = x + 1;x = x + 1;
d = d + bd = d + b
}}
}}
The initial value for the decision variable, d0, may be calculated directly
from the formula at point (0,0).
d0 = f(0 + 1, 0 + 1/2) = b(1) - a(1/2) = b - a/2
Therefore, the algorithm for a line from (0,0) to (a,b) in the first octant is:
x = 0;
y = 0;
d = b - a/2;
for(i = 0; i < a; i++) {
Plot(x,y);
if (d = 0) {
x = x + 1;
y = y + 1;
d = d + b - a;
}
Fast Line AlgorithmFast Line Algorithm
Note that the only non-integer value is a/2. If we then multiply by 2 to get d' = 2d, we
can do all integer arithmetic. The algorithm still works since we only care about the
sign, not the value of d.
Bresenham’sBresenham’s Line AlgorithmLine Algorithm
We can also generalize the algorithm to work for lines beginningWe can also generalize the algorithm to work for lines beginning atat
points other than (0,0) by giving x and y the proper initial valpoints other than (0,0) by giving x and y the proper initial values.ues.
This results inThis results in Bresenham'sBresenham's Line Algorithm.Line Algorithm.
{Bresenham for lines with slope between 0 and 1}
a = ABS(xend - xstart);
b = ABS(yend - ystart);
d = 2*b - a;
Incr1 = 2*(b-a);
Incr2 = 2*b;
if (xstart > xend) {
x = xend;
y = yend
}
else {
x = xstart;
y = ystart
}
for (i = 0; i<a; i++){
Plot(x,y);
x = x + 1;
if (d = 0) {
y = y + 1;
d = d + incr1;
}
else
d = d + incr2;
}
}
OptimizationsOptimizations
nn Speed can be increased even more by detecting cycles in the deciSpeed can be increased even more by detecting cycles in the decisionsion
variable. These cycles correspond to a repeated pattern of pixevariable. These cycles correspond to a repeated pattern of pixel choices.l choices.
nn The pattern is saved and if a cycle is detected it is repeatedThe pattern is saved and if a cycle is detected it is repeated withoutwithout
recalculating.recalculating.
11 12 13 14 15 16 17
9
10
11
12
13
14
15
16
6 7 8 9 10
didi== 22 --6 66 6 --2 102 10 22 --6 66 6 --2 102 10
The aliasing problemThe aliasing problem
nn Aliasing is caused by finite addressability of the display.Aliasing is caused by finite addressability of the display.
nn Approximation of lines and circles with discrete points oftenApproximation of lines and circles with discrete points often
gives a staircase appearance or "gives a staircase appearance or "JaggiesJaggies".".
Desired line
Aliased rendering of the line
5
AntialiasingAntialiasing -- solutionssolutions
nn Aliasing can be smoothed out by using higher addressability.Aliasing can be smoothed out by using higher addressability.
nn If addressability is fixed but intensity is variable, use the inIf addressability is fixed but intensity is variable, use the intensitytensity
to control the address of a "virtual pixel". Two adjacent pixeto control the address of a "virtual pixel". Two adjacent pixelsls
can be be used to give the impression of a point part way betweecan be be used to give the impression of a point part way betweenn
them. The perceived location of the point is dependent upon thethem. The perceived location of the point is dependent upon the
ratio of the intensities used at each. The impression of a pixeratio of the intensities used at each. The impression of a pixell
located halfway between two addressable points can be given bylocated halfway between two addressable points can be given by
having two adjacent pixels at half intensity.having two adjacent pixels at half intensity.
nn AnAn antialiasedantialiased line has a series of virtual pixels each located at theline has a series of virtual pixels each located at the
proper address.proper address.
Aliasing /Aliasing / AntialiasingAntialiasing
ExamplesExamples
AntialiasedAntialiased BresenhamBresenham LinesLines
nn Line drawing algorithms such asLine drawing algorithms such as Bresenham'sBresenham's can easily becan easily be
modified to implement virtual pixels. We use the distance (e =modified to implement virtual pixels. We use the distance (e =
ddii/a) value to determine pixel intensities./a) value to determine pixel intensities.
nn Three possible cases which occur during theThree possible cases which occur during the BresenhamBresenham algorithm:algorithm:
AA
B
C
e
B
C
e
A
B
C
e
A = 0.5 + e
B = 1 - abs(e+0.5)
C = 0
A = 0.5 + e
B = 1 - abs(e+0.5)
C = 0
A = 0
B = 1 - abs(e+0.5)
C = -0.5 - e
e > 0 0 > e > -0.5 e < -0.5
Line Rendering ReferencesLine Rendering References
BresenhamBresenham, J.E., "Ambiguities In Incremental Line, J.E., "Ambiguities In Incremental Line RasteringRastering,"," IEEEIEEE
Computer Graphics And ApplicationsComputer Graphics And Applications, Vol. 7, No. 5, May 1987., Vol. 7, No. 5, May 1987.
EcklandEckland, Eric, "Improved Techniques For, Eric, "Improved Techniques For OptimisingOptimising IterativeIterative
DecisionDecision-- Variable Algorithms, Drawing AntiVariable Algorithms, Drawing Anti--Aliased Lines QuicklyAliased Lines Quickly
And Creating Easy To Use Color Charts," CSC 462 Project Report,And Creating Easy To Use Color Charts," CSC 462 Project Report,
Department of Computer Science, North Carolina State UniversityDepartment of Computer Science, North Carolina State University
(Spring 1987).(Spring 1987).
Foley, J.D. and A. Van Dam,Foley, J.D. and A. Van Dam, Fundamentals of Interactive ComputerFundamentals of Interactive Computer
GraphicsGraphics, Addison, Addison--Wesley 1982.Wesley 1982.
Newman, W.M and R.F.Newman, W.M and R.F. SproullSproull,, Principles Of Interactive ComputerPrinciples Of Interactive Computer
GraphicsGraphics, McGraw, McGraw --Hill, 1979.Hill, 1979.

Más contenido relacionado

La actualidad más candente

Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
 
Image Processing 3
Image Processing 3Image Processing 3
Image Processing 3jainatin
 
Signal Processing Course : Inverse Problems Regularization
Signal Processing Course : Inverse Problems RegularizationSignal Processing Course : Inverse Problems Regularization
Signal Processing Course : Inverse Problems RegularizationGabriel Peyré
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 
Mesh Processing Course : Multiresolution
Mesh Processing Course : MultiresolutionMesh Processing Course : Multiresolution
Mesh Processing Course : MultiresolutionGabriel Peyré
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
A mid point ellipse drawing algorithm on a hexagonal grid
A mid  point ellipse drawing algorithm on a hexagonal gridA mid  point ellipse drawing algorithm on a hexagonal grid
A mid point ellipse drawing algorithm on a hexagonal gridS M K
 
Lecture 2: linear SVM in the Dual
Lecture 2: linear SVM in the DualLecture 2: linear SVM in the Dual
Lecture 2: linear SVM in the DualStéphane Canu
 
IIT JAM MATH 2021 Question Paper | Sourav Sir's Classes
IIT JAM MATH 2021 Question Paper | Sourav Sir's ClassesIIT JAM MATH 2021 Question Paper | Sourav Sir's Classes
IIT JAM MATH 2021 Question Paper | Sourav Sir's ClassesSOURAV DAS
 
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's ClassesIIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's ClassesSOURAV DAS
 
Finite difference method
Finite difference methodFinite difference method
Finite difference methodDivyansh Verma
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algosimpleok
 
IIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's Classes
IIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's ClassesIIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's Classes
IIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's ClassesSOURAV DAS
 

La actualidad más candente (20)

Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
 
Image Processing 3
Image Processing 3Image Processing 3
Image Processing 3
 
Signal Processing Course : Inverse Problems Regularization
Signal Processing Course : Inverse Problems RegularizationSignal Processing Course : Inverse Problems Regularization
Signal Processing Course : Inverse Problems Regularization
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Cs580
Cs580Cs580
Cs580
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
Mesh Processing Course : Multiresolution
Mesh Processing Course : MultiresolutionMesh Processing Course : Multiresolution
Mesh Processing Course : Multiresolution
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
A mid point ellipse drawing algorithm on a hexagonal grid
A mid  point ellipse drawing algorithm on a hexagonal gridA mid  point ellipse drawing algorithm on a hexagonal grid
A mid point ellipse drawing algorithm on a hexagonal grid
 
U unit3 vm
U unit3 vmU unit3 vm
U unit3 vm
 
Lecture 2: linear SVM in the Dual
Lecture 2: linear SVM in the DualLecture 2: linear SVM in the Dual
Lecture 2: linear SVM in the Dual
 
IIT JAM MATH 2021 Question Paper | Sourav Sir's Classes
IIT JAM MATH 2021 Question Paper | Sourav Sir's ClassesIIT JAM MATH 2021 Question Paper | Sourav Sir's Classes
IIT JAM MATH 2021 Question Paper | Sourav Sir's Classes
 
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's ClassesIIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
IIT JAM Mathematical Statistics - MS 2022 | Sourav Sir's Classes
 
Finite difference method
Finite difference methodFinite difference method
Finite difference method
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algo
 
IIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's Classes
IIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's ClassesIIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's Classes
IIT JAM PHYSICS - PH 2022 Question Paper | Sourav Sir's Classes
 

Similar a Open GL 04 linealgos

Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)CrackDSE
 
13 graphs of factorable polynomials x
13 graphs of factorable polynomials x13 graphs of factorable polynomials x
13 graphs of factorable polynomials xmath260
 
ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)CrackDSE
 
FINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docx
FINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docxFINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docx
FINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docxvoversbyobersby
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functionsTarun Gehlot
 
2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomialsmath260
 
Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)Matthew Leingang
 
Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)Mel Anthony Pepito
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 
On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...
On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...
On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...BRNSS Publication Hub
 

Similar a Open GL 04 linealgos (20)

Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)
 
2D_line_circle.ppt
2D_line_circle.ppt2D_line_circle.ppt
2D_line_circle.ppt
 
13 graphs of factorable polynomials x
13 graphs of factorable polynomials x13 graphs of factorable polynomials x
13 graphs of factorable polynomials x
 
ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)
 
FINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docx
FINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docxFINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docx
FINAL PROJECT, MATH 251, FALL 2015[The project is Due Mond.docx
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Linear equation 2 2
Linear equation 2 2Linear equation 2 2
Linear equation 2 2
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functions
 
Linear equations 2-2 a graphing and x-y intercepts
Linear equations   2-2 a graphing and x-y interceptsLinear equations   2-2 a graphing and x-y intercepts
Linear equations 2-2 a graphing and x-y intercepts
 
2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials
 
Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)
 
Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)Lesson 2: A Catalog of Essential Functions (slides)
Lesson 2: A Catalog of Essential Functions (slides)
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...
On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...
On the Seidel’s Method, a Stronger Contraction Fixed Point Iterative Method o...
 
1533 game mathematics
1533 game mathematics1533 game mathematics
1533 game mathematics
 

Más de Roziq Bahtiar

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profileRoziq Bahtiar
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routingRoziq Bahtiar
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemRoziq Bahtiar
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrogramanRoziq Bahtiar
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatRoziq Bahtiar
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajenRoziq Bahtiar
 
7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman strukturRoziq Bahtiar
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointerRoziq Bahtiar
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_stringRoziq Bahtiar
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsiRoziq Bahtiar
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrogramanRoziq Bahtiar
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrogramanRoziq Bahtiar
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_dataRoziq Bahtiar
 

Más de Roziq Bahtiar (20)

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profile
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routing
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating Sistem
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrograman
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulat
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajen
 
Pcd 10
Pcd 10Pcd 10
Pcd 10
 
Pcd 11
Pcd 11Pcd 11
Pcd 11
 
7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman struktur
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointer
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_string
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsi
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data
 
Alpro tutor
Alpro tutorAlpro tutor
Alpro tutor
 
Pcd 7
Pcd 7Pcd 7
Pcd 7
 
Pcd 5
Pcd 5Pcd 5
Pcd 5
 
Pcd 4
Pcd 4Pcd 4
Pcd 4
 
Eigen
EigenEigen
Eigen
 

Último

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Último (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Open GL 04 linealgos

  • 1. 1 Elementary raster algorithms forElementary raster algorithms for fast renderingfast rendering Elementary RenderingElementary Rendering nn Geometric PrimitivesGeometric Primitives –– Line processingLine processing –– Polygon processingPolygon processing nn Managing OpenGL StateManaging OpenGL State nn OpenGL BuffersOpenGL Buffers OpenGL Geometric PrimitivesOpenGL Geometric Primitives nn All geometric primitives are specified byAll geometric primitives are specified by verticesvertices GL_QUAD_STRIPGL_QUAD_STRIP GL_POLYGONGL_POLYGON GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN GL_POINTSGL_POINTS GL_LINESGL_LINES GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP GL_TRIANGLESGL_TRIANGLES GL_QUADSGL_QUADS Design of Line AlgorithmsDesign of Line Algorithms Why Lines?Why Lines? nn Lines:Lines: –– Most common 2D primitiveMost common 2D primitive -- done 100s or 1000sdone 100s or 1000s of times each frame, even 3Dof times each frame, even 3D wireframeswireframes areare eventually 2D lines!eventually 2D lines! –– Lines areLines are compatiblecompatible with vector displays butwith vector displays but nowadays most displays are raster displays. Anynowadays most displays are raster displays. Any render stage beforerender stage before vizviz might needmight need discretizationdiscretization.. –– Optimized algorithms contain numerousOptimized algorithms contain numerous tricks/techniques that help in designing moretricks/techniques that help in designing more advanced algorithms for line processing.advanced algorithms for line processing. Line Algorithms in the OpenGLLine Algorithms in the OpenGL ArchitectureArchitecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture Memory CPU Pixel Operations
  • 2. 2 Line RequirementsLine Requirements nn Must compute integer coordinates of pixels which lie on or nearMust compute integer coordinates of pixels which lie on or near aa line or circle.line or circle. nn Pixel level algorithms are invoked hundreds or thousands of timePixel level algorithms are invoked hundreds or thousands of timess when an image is created or modifiedwhen an image is created or modified –– must be fast!must be fast! nn Lines must create visually satisfactory images.Lines must create visually satisfactory images. –– Lines should appear straightLines should appear straight –– Lines should terminate accuratelyLines should terminate accurately –– Lines should have constant densityLines should have constant density nn Line algorithm should always be defined.Line algorithm should always be defined. Basic Math ReviewBasic Math Review PointPoint--slope Formula For a Lineslope Formula For a Line Given two points (XGiven two points (X11,Y,Y11), (X), (X22, Y, Y22)) Consider a third point on the line:Consider a third point on the line: P = (X,Y)P = (X,Y) Slope = (YSlope = (Y22 -- YY11)/(X)/(X22 -- XX11)) = (Y= (Y -- YY11)/(X)/(X -- XX11)) Solving For YSolving For Y Y = [(YY = [(Y22--YY11)/(X)/(X22--XX11)]*(X)]*(X--XX11)+ Y)+ Y11 or, plug in the point (0, b) to getor, plug in the point (0, b) to get thethe SlopeSlope--intercept form:intercept form: Y =Y = mxmx + b+ b Cartesian Coordinate System 2 4 1 2 3 4 5 6 3 5 6 1 P1 = (X1,Y1) P2 = (X2,Y2) P = (X,Y) SLOPE = RISE RUN = Y2-Y1 X2-X1 Other Helpful FormulasOther Helpful Formulas nn Length of line segment between PLength of line segment between P11 and Pand P22:: L =L = nn Midpoint of a line segment between PMidpoint of a line segment between P11 andand PP33:: PP22 = ( (X= ( (X11+X+X33)/2 , (Y)/2 , (Y 11+Y+Y33)/2 ))/2 ) nn Two lines areTwo lines are perpendicularperpendicular iffiff 1) M1) M11 == --1/M1/M22 2) Cosine of the angle between them is 0.2) Cosine of the angle between them is 0. 2 12 2 12 )()( yyxx −+− Using this information, whatUsing this information, what are some possible algorithmsare some possible algorithms for line drawing?for line drawing? Parametric FormParametric Form Given points PGiven points P11 = (X= (X11, Y, Y11) and P) and P22 = (X= (X22, Y, Y22)) X = XX = X11 + t(X+ t(X22--XX11)) Y = YY = Y11 + t(Y+ t(Y22--YY11)) t is called the parameter. Whent is called the parameter. When t = 0 we get (Xt = 0 we get (X11,Y,Y11)) t = 1 we get (Xt = 1 we get (X22,Y,Y22)) As 0 < t < 1 we get all the other points on the line segmentAs 0 < t < 1 we get all the other points on the line segment between (Xbetween (X11,Y,Y11) and (X) and (X22,Y,Y22).). New algorithm ideas based onNew algorithm ideas based on parametric form?parametric form?
  • 3. 3 Simple DDA* Line AlgorithmSimple DDA* Line Algorithm voidvoid DDA(intDDA(int X1,Y1,X2,Y2)X1,Y1,X2,Y2) {{ intint Length, I;Length, I; floatfloat X,Y,Xinc,YincX,Y,Xinc,Yinc;; Length = ABS(X2Length = ABS(X2 -- X1);X1); if (ABS(Y2if (ABS(Y2 -- Y1) > Length)Y1) > Length) Length = ABS(Y2Length = ABS(Y2--Y1);Y1); XincXinc = (X2= (X2 -- X1)/Length;X1)/Length; YincYinc = (Y2= (Y2 -- Y1)/Length;Y1)/Length; *DDA: Digital Differential Analyzer*DDA: Digital Differential Analyzer X = X1; Y = Y1; while(X<X2){ Plot(Round(X),Round(Y)); X = X + Xinc; Y = Y + Yinc; } } DDA creates good lines but it is too time consuming due to the rDDA creates good lines but it is too time consuming due to the roundound function and long operations on real values.function and long operations on real values. Compute which pixels should be turned on to represent the line from (6,9) to (11,12). Length = ? Xinc = ? Yinc = ? DDA ExampleDDA Example 6 7 8 9 10 11 12 13 9 10 11 12 13 DDA ExampleDDA Example Line from (6,9) to (11,12).Line from (6,9) to (11,12). Length := Max of (ABS(11Length := Max of (ABS(11--6), ABS(126), ABS(12--9)) = 59)) = 5 XincXinc := 1:= 1 YincYinc := 0.6:= 0.6 Values computed are:Values computed are: (6,9), (7,9.6),(6,9), (7,9.6), (8,10.2), (9,10.8),(8,10.2), (9,10.8), (10,11.4), (11,12)(10,11.4), (11,12) 6 7 8 9 10 11 12 13 9 10 11 12 13 Fast LinesFast Lines –– Midpoint MethodMidpoint Method nn Simplifying assumptions: AssumeSimplifying assumptions: Assume we wish to draw a line betweenwe wish to draw a line between points (0,0) and (a,b) with slope mpoints (0,0) and (a,b) with slope m between 0 and 1 (i.e. line lies in firstbetween 0 and 1 (i.e. line lies in first octant).octant). nn The general formula for a line isThe general formula for a line is yy == mxmx + B+ B wherewhere mm is the slope ofis the slope of the line andthe line and BB is the yis the y--intercept.intercept. From our assumptionsFrom our assumptions mm = b/a and= b/a and BB = 0.= 0. nn y = (b/a)x + 0y = (b/a)x + 0 ---->> f(x,y) =f(x,y) = bxbx -- ayay = 0= 0 is an equation for the line.is an equation for the line. +x-x -y +y Having turned on pixel P at (xHaving turned on pixel P at (xii,, yyii), the next pixel is NE at (x), the next pixel is NE at (xii+1,+1, yyii+1) or E at (x+1) or E at (xii+1,+1, yyii). Choose the pixel closer to the line). Choose the pixel closer to the line f(x, y) =f(x, y) = bxbx -- ay = 0.ay = 0. Fast Lines (cont.)Fast Lines (cont.) For lines in the first octant,For lines in the first octant, given one pixel on thegiven one pixel on the line, the next pixel is toline, the next pixel is to the right (E) or to thethe right (E) or to the right and up (NE).right and up (NE). P = (xi ,yi ) E = (xi + 1, yi) NE = (xi + 1, yi + 1) current pixel possible next pixels Fast Lines (cont.)Fast Lines (cont.) The midpoint between pixels E and NE is (xi + 1, yi + ½). Let e be the “upward” distance between the midpoint and where the line actually crosses between E and NE. If e is positive the line crosses above the midpoint and is closer to NE. If e is negative, the line crosses below the midpoint and is closer to E. To pick the correct point we only need to know the sign of e. (xi +1, yi + ½ + e) e (xi +1, yi + ½) P = (xi ,yi ) E = (xi + 1, yi) NE = (xi + 1, yi + 1)
  • 4. 4 The Decision VariableThe Decision Variable f(xf(xii+1,+1, yy ii+ ½ + e) = 0 (point on line)+ ½ + e) = 0 (point on line) == b(xb(xii + 1)+ 1) -- a(ya(y ii+ ½ + e)+ ½ + e) == b(xb(xii + 1)+ 1) -- a(ya(y ii + ½)+ ½) –– aeae == f(xf(xii + 1,+ 1, yy ii + ½)+ ½) -- aeae LetLet ddii == f(xf(xii + 1,+ 1, yy ii + ½) =+ ½) = aeae;; ddii is known as theis known as the decisiondecision variablevariable.. Since a = 0,Since a = 0, ddii has the same sign as ehas the same sign as e.. Therefore, we only need to know the value ofTherefore, we only need to know the value of ddii to choose betweento choose between pixels E and NE. Ifpixels E and NE. If ddii = 0 choose NE, else choose E.= 0 choose NE, else choose E. ButBut, calculating, calculating ddii directly each time requires at least two adds, adirectly each time requires at least two adds, a subtract, and two multipliessubtract, and two multiplies --> too slow!> too slow! è f(xi + 1, yi + ½) = ae Decision VariableDecision Variable calculationcalculation Algorithm:Algorithm: Calculate dCalculate d00 directly, then for each i >= 0:directly, then for each i >= 0: ifif ddii = 0 Then= 0 Then Choose NE = (xChoose NE = (xii + 1,+ 1, yy ii + 1) as next point+ 1) as next point ddi+1i+1 = f(x= f(xi+1i+1 + 1, y+ 1, y i+1i+1 + ½) =+ ½) = f(xf(xii + 1 + 1,+ 1 + 1, yy ii + 1 + ½)+ 1 + ½) == b(xb(xii + 1 + 1)+ 1 + 1) -- a(ya(y ii + 1 + ½) =+ 1 + ½) = f(xf(xii + 1,+ 1, yy ii + ½) + b+ ½) + b -- aa == ddii + b+ b -- aa elseelse Choose E = (xChoose E = (xii + 1,+ 1, yy ii) as next point) as next point ddi+1i+1 = f(x= f(xi+1i+1 + 1, y+ 1, y i+1i+1 + ½) =+ ½) = f(xf(xii + 1 + 1,+ 1 + 1, yy ii + ½)+ ½) == b(xb(xii + 1 + 1)+ 1 + 1) -- a(ya(y ii + ½) =+ ½) = f(xf(xii + 1,+ 1, yy ii + ½) + b+ ½) + b == ddii + b+ b èè KnowingKnowing ddii, we need only add a, we need only add a constantconstant term to find dterm to find di+1i+1 !! else {else { x = x + 1;x = x + 1; d = d + bd = d + b }} }} The initial value for the decision variable, d0, may be calculated directly from the formula at point (0,0). d0 = f(0 + 1, 0 + 1/2) = b(1) - a(1/2) = b - a/2 Therefore, the algorithm for a line from (0,0) to (a,b) in the first octant is: x = 0; y = 0; d = b - a/2; for(i = 0; i < a; i++) { Plot(x,y); if (d = 0) { x = x + 1; y = y + 1; d = d + b - a; } Fast Line AlgorithmFast Line Algorithm Note that the only non-integer value is a/2. If we then multiply by 2 to get d' = 2d, we can do all integer arithmetic. The algorithm still works since we only care about the sign, not the value of d. Bresenham’sBresenham’s Line AlgorithmLine Algorithm We can also generalize the algorithm to work for lines beginningWe can also generalize the algorithm to work for lines beginning atat points other than (0,0) by giving x and y the proper initial valpoints other than (0,0) by giving x and y the proper initial values.ues. This results inThis results in Bresenham'sBresenham's Line Algorithm.Line Algorithm. {Bresenham for lines with slope between 0 and 1} a = ABS(xend - xstart); b = ABS(yend - ystart); d = 2*b - a; Incr1 = 2*(b-a); Incr2 = 2*b; if (xstart > xend) { x = xend; y = yend } else { x = xstart; y = ystart } for (i = 0; i<a; i++){ Plot(x,y); x = x + 1; if (d = 0) { y = y + 1; d = d + incr1; } else d = d + incr2; } } OptimizationsOptimizations nn Speed can be increased even more by detecting cycles in the deciSpeed can be increased even more by detecting cycles in the decisionsion variable. These cycles correspond to a repeated pattern of pixevariable. These cycles correspond to a repeated pattern of pixel choices.l choices. nn The pattern is saved and if a cycle is detected it is repeatedThe pattern is saved and if a cycle is detected it is repeated withoutwithout recalculating.recalculating. 11 12 13 14 15 16 17 9 10 11 12 13 14 15 16 6 7 8 9 10 didi== 22 --6 66 6 --2 102 10 22 --6 66 6 --2 102 10 The aliasing problemThe aliasing problem nn Aliasing is caused by finite addressability of the display.Aliasing is caused by finite addressability of the display. nn Approximation of lines and circles with discrete points oftenApproximation of lines and circles with discrete points often gives a staircase appearance or "gives a staircase appearance or "JaggiesJaggies".". Desired line Aliased rendering of the line
  • 5. 5 AntialiasingAntialiasing -- solutionssolutions nn Aliasing can be smoothed out by using higher addressability.Aliasing can be smoothed out by using higher addressability. nn If addressability is fixed but intensity is variable, use the inIf addressability is fixed but intensity is variable, use the intensitytensity to control the address of a "virtual pixel". Two adjacent pixeto control the address of a "virtual pixel". Two adjacent pixelsls can be be used to give the impression of a point part way betweecan be be used to give the impression of a point part way betweenn them. The perceived location of the point is dependent upon thethem. The perceived location of the point is dependent upon the ratio of the intensities used at each. The impression of a pixeratio of the intensities used at each. The impression of a pixell located halfway between two addressable points can be given bylocated halfway between two addressable points can be given by having two adjacent pixels at half intensity.having two adjacent pixels at half intensity. nn AnAn antialiasedantialiased line has a series of virtual pixels each located at theline has a series of virtual pixels each located at the proper address.proper address. Aliasing /Aliasing / AntialiasingAntialiasing ExamplesExamples AntialiasedAntialiased BresenhamBresenham LinesLines nn Line drawing algorithms such asLine drawing algorithms such as Bresenham'sBresenham's can easily becan easily be modified to implement virtual pixels. We use the distance (e =modified to implement virtual pixels. We use the distance (e = ddii/a) value to determine pixel intensities./a) value to determine pixel intensities. nn Three possible cases which occur during theThree possible cases which occur during the BresenhamBresenham algorithm:algorithm: AA B C e B C e A B C e A = 0.5 + e B = 1 - abs(e+0.5) C = 0 A = 0.5 + e B = 1 - abs(e+0.5) C = 0 A = 0 B = 1 - abs(e+0.5) C = -0.5 - e e > 0 0 > e > -0.5 e < -0.5 Line Rendering ReferencesLine Rendering References BresenhamBresenham, J.E., "Ambiguities In Incremental Line, J.E., "Ambiguities In Incremental Line RasteringRastering,"," IEEEIEEE Computer Graphics And ApplicationsComputer Graphics And Applications, Vol. 7, No. 5, May 1987., Vol. 7, No. 5, May 1987. EcklandEckland, Eric, "Improved Techniques For, Eric, "Improved Techniques For OptimisingOptimising IterativeIterative DecisionDecision-- Variable Algorithms, Drawing AntiVariable Algorithms, Drawing Anti--Aliased Lines QuicklyAliased Lines Quickly And Creating Easy To Use Color Charts," CSC 462 Project Report,And Creating Easy To Use Color Charts," CSC 462 Project Report, Department of Computer Science, North Carolina State UniversityDepartment of Computer Science, North Carolina State University (Spring 1987).(Spring 1987). Foley, J.D. and A. Van Dam,Foley, J.D. and A. Van Dam, Fundamentals of Interactive ComputerFundamentals of Interactive Computer GraphicsGraphics, Addison, Addison--Wesley 1982.Wesley 1982. Newman, W.M and R.F.Newman, W.M and R.F. SproullSproull,, Principles Of Interactive ComputerPrinciples Of Interactive Computer GraphicsGraphics, McGraw, McGraw --Hill, 1979.Hill, 1979.