SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
LESSON 4: Drawing Line Segments 1
Drawing a line segment
Line segments are basic graphics primitives. Drawing good-quality line
segments efficiently is a fundamental task in real-time computer graphics.
Three methods for drawing a line segment will be discussed in this lesson,
leading to Bresenham’s algorithm which uses on average one integer addition
per pixel to rasterize a line segment.
Input: starting point (xs, ys) and ending point (xe, ye), where xs, ys, xe, ye
are integers.
Assumptions:
• ye ≥ ys, xe > xs, and |ye − ys| ≤ |xe − xs|. So 0 ≤ k = (ye − ys)/(xe −
xs) ≤ 1, k the slope. Note that any other line segment can be transformed
to such a position by properly choosing the starting point or swapping x and
y coordinates, if necessary.
• One pixel is to be found on each vertical line intersecting the given line
segment.
• A sequence of pixels will be determined to approximate the line segment.
Method 1:
For each unit increment in x-direction, y is increased by k, the slope. If
the intersection between the vertical line x = i and the given line segment is
(i, yi), the intersection between the next vertical line x = i + 1 and the given
LESSON 4: Drawing Line Segments 2
k
x=i
(i,Yi)
(i+1,Yi+k)
e
Raster Line Drawing
line is (i + 1, yi + k). See the figure.
Note that, since pixel positions are needed, we must round (i, yi), xs ≤ i ≤
xe, to the nearest integer point (i, yi + 0.5 ). The pseudo code is as follows.
Line Drawing 1:
long x, y;
float k, yy;
k = (ye - ys)/(xe - xs);
yy = ys;
for(x=xs; x<=xe; x++)
LESSON 4: Drawing Line Segments 3
{
y = ftrunc(yy + 0.5);
write_pixel(x,y);
yy = yy + k;
}
Remarks: Floating-point operations are used in this solution. Floating
point operations are slower than integer operations.
Method 2:
Idea: Suppose that the distance e of (i, yi) to the horizontal grid line right
below it is recorded. Then the lower pixel should be chosen if and only if
e < 0.5. To facilitate this test, we denote e − 0.5 by e instead. Thus, the
lower pixel is chosen if and only if e < 0. Pay attention to how e is updated
in each step.
long x, y;
float k, e;
k = (ye - ys)/(xe - xs);
x = xs; y = ys;
e = -0.5;
for(x=xs; x<=xe; x++)
{
if(e < 0)
write_pixel(x,y);
LESSON 4: Drawing Line Segments 4
else
{
y = y + 1;
write_pixel(x,y);
e = e - 1;
}
e = e + k;
}
Remark: Floating-point operations are still used in method 2.
Method 3:
Idea: We use program transformation to translate method 2 into a new
algorithm. The key observation is: it is the sign of e, not its value, that
determines the next pixel to be selected.
Let a = xe−xs, b = ye−ys. Then k = b/a. All the statements in method
2 that affect the value of e are
e = −0.5; e = e − 1; e = e +
b
a
.
Multiplying 2a to both sides of these three expressions, we obtain
2a ∗ e = −a; 2a ∗ e = 2a ∗ e − 2a; 2a ∗ e = 2a ∗ e + 2b;
Naming 2a ∗ e by d yields
d = −a; d = d − 2a; d = d + 2b.
LESSON 4: Drawing Line Segments 5
Using these three expressions to replace the original statements that are used
to generate e in method 2 yields the following pseudo code.
long x, y, dx, dy, d;
x = xs; y = ys;
dx = 2*(xe - xs); /* dx = 2a */
dy = 2*(ye - ys); /* dy = 2b */
d = -(xe - xs); /* d = -a */
for(x=xs; x<=xe; x++)
{
if(d < 0)
write_pixel(x, y);
else
{
y = y + 1;
write_pixel(x,y);
d = d - dx;
}
d = d + dy;
}
Remarks: This algorithm uses integer operations only. It can be further
simplified by re-arranging some statements.
LESSON 4: Drawing Line Segments 6
Bresenham’s algorithm
By combining the statement d = d - dx; and d = d + dy; in the case
of moving up diagonally, we have the final algorithm, which on average uses
one integer addition and one sign testing per pixel.
long x, y, dx, dy, dy_x, d;
x = xs; y = ys;
dx = 2*(xe - xs); /* dx = 2a */
dy = 2*(ye - ys); /* dy = 2b */
dy_x = dy - dx;
d = -(xe - xs); /* d = -a */
for(x=xs; x<=xe; x++)
{
if(d < 0)
d = d + dy;
else
{
y = y + 1;
d = d + dy_x;
}
write_pixel(x,y);
}
LESSON 4: Drawing Line Segments 7
Question:
Can you come up with a line drawing algorithm that is faster than Bresen-
ham’s algorithm?

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Es272 ch6
Es272 ch6Es272 ch6
Es272 ch6
 
Chapter 5 Point Slope Form
Chapter 5 Point Slope FormChapter 5 Point Slope Form
Chapter 5 Point Slope Form
 
Presentation on application of numerical method in our life
Presentation on application of numerical method in our lifePresentation on application of numerical method in our life
Presentation on application of numerical method in our life
 
Es272 ch4b
Es272 ch4bEs272 ch4b
Es272 ch4b
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
 
Presentation on Numerical Method (Trapezoidal Method)
Presentation on Numerical Method (Trapezoidal Method)Presentation on Numerical Method (Trapezoidal Method)
Presentation on Numerical Method (Trapezoidal Method)
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
Secant Method
Secant MethodSecant Method
Secant Method
 
Chapter 5 Identifying Linear Functions
Chapter 5 Identifying Linear FunctionsChapter 5 Identifying Linear Functions
Chapter 5 Identifying Linear Functions
 
Es272 ch2
Es272 ch2Es272 ch2
Es272 ch2
 
1552 limits graphically and nume
1552 limits graphically and nume1552 limits graphically and nume
1552 limits graphically and nume
 
Chapter 5 The Slope Formula
Chapter 5 The Slope FormulaChapter 5 The Slope Formula
Chapter 5 The Slope Formula
 
Least square method
Least square methodLeast square method
Least square method
 
numerical methods
numerical methodsnumerical methods
numerical methods
 
False Point Method / Regula falsi method
False Point Method / Regula falsi methodFalse Point Method / Regula falsi method
False Point Method / Regula falsi method
 
Numerical method
Numerical methodNumerical method
Numerical method
 
Es272 ch4a
Es272 ch4aEs272 ch4a
Es272 ch4a
 
Lecture 8 power & exp rules
Lecture 8   power & exp rulesLecture 8   power & exp rules
Lecture 8 power & exp rules
 
Lecture 6 limits with infinity
Lecture 6   limits with infinityLecture 6   limits with infinity
Lecture 6 limits with infinity
 

Destacado

7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman strukturRoziq Bahtiar
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatRoziq Bahtiar
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrogramanRoziq Bahtiar
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajenRoziq 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
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routingRoziq Bahtiar
 

Destacado (9)

7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman struktur
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulat
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrograman
 
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
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating Sistem
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routing
 
OpenGL Basics
OpenGL BasicsOpenGL Basics
OpenGL Basics
 

Similar a Open GL T0074 56 sm2

cgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdfcgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdfmeenasp
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptxssuser255bf1
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxR S Anu Prabha
 
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
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmKALAIRANJANI21
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmKALAIRANJANI21
 
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridgealproelearning
 
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarComputer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarVishal Butkar
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Philip Schwarz
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
February 18 2016
February 18 2016February 18 2016
February 18 2016khyps13
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
How to graph Functions
How to graph FunctionsHow to graph Functions
How to graph Functionscoolhanddav
 

Similar a Open GL T0074 56 sm2 (20)

cgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdfcgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdf
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
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
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithm
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithm
 
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
 
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarComputer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
February 18 2016
February 18 2016February 18 2016
February 18 2016
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
How to graph Functions
How to graph FunctionsHow to graph Functions
How to graph Functions
 

Más de Roziq Bahtiar

Más de Roziq Bahtiar (20)

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profile
 
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
 
3 piksel_dan_histogram
 3 piksel_dan_histogram 3 piksel_dan_histogram
3 piksel_dan_histogram
 
Pcd 8
Pcd 8Pcd 8
Pcd 8
 
2 pengolahan_citra
 2 pengolahan_citra 2 pengolahan_citra
2 pengolahan_citra
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Open GL T0074 56 sm1
Open GL T0074 56 sm1Open GL T0074 56 sm1
Open GL T0074 56 sm1
 
Open GL 09 scan conversion
Open GL 09 scan conversionOpen GL 09 scan conversion
Open GL 09 scan conversion
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgos
 

Último

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 

Último (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

Open GL T0074 56 sm2

  • 1. LESSON 4: Drawing Line Segments 1 Drawing a line segment Line segments are basic graphics primitives. Drawing good-quality line segments efficiently is a fundamental task in real-time computer graphics. Three methods for drawing a line segment will be discussed in this lesson, leading to Bresenham’s algorithm which uses on average one integer addition per pixel to rasterize a line segment. Input: starting point (xs, ys) and ending point (xe, ye), where xs, ys, xe, ye are integers. Assumptions: • ye ≥ ys, xe > xs, and |ye − ys| ≤ |xe − xs|. So 0 ≤ k = (ye − ys)/(xe − xs) ≤ 1, k the slope. Note that any other line segment can be transformed to such a position by properly choosing the starting point or swapping x and y coordinates, if necessary. • One pixel is to be found on each vertical line intersecting the given line segment. • A sequence of pixels will be determined to approximate the line segment. Method 1: For each unit increment in x-direction, y is increased by k, the slope. If the intersection between the vertical line x = i and the given line segment is (i, yi), the intersection between the next vertical line x = i + 1 and the given
  • 2. LESSON 4: Drawing Line Segments 2 k x=i (i,Yi) (i+1,Yi+k) e Raster Line Drawing line is (i + 1, yi + k). See the figure. Note that, since pixel positions are needed, we must round (i, yi), xs ≤ i ≤ xe, to the nearest integer point (i, yi + 0.5 ). The pseudo code is as follows. Line Drawing 1: long x, y; float k, yy; k = (ye - ys)/(xe - xs); yy = ys; for(x=xs; x<=xe; x++)
  • 3. LESSON 4: Drawing Line Segments 3 { y = ftrunc(yy + 0.5); write_pixel(x,y); yy = yy + k; } Remarks: Floating-point operations are used in this solution. Floating point operations are slower than integer operations. Method 2: Idea: Suppose that the distance e of (i, yi) to the horizontal grid line right below it is recorded. Then the lower pixel should be chosen if and only if e < 0.5. To facilitate this test, we denote e − 0.5 by e instead. Thus, the lower pixel is chosen if and only if e < 0. Pay attention to how e is updated in each step. long x, y; float k, e; k = (ye - ys)/(xe - xs); x = xs; y = ys; e = -0.5; for(x=xs; x<=xe; x++) { if(e < 0) write_pixel(x,y);
  • 4. LESSON 4: Drawing Line Segments 4 else { y = y + 1; write_pixel(x,y); e = e - 1; } e = e + k; } Remark: Floating-point operations are still used in method 2. Method 3: Idea: We use program transformation to translate method 2 into a new algorithm. The key observation is: it is the sign of e, not its value, that determines the next pixel to be selected. Let a = xe−xs, b = ye−ys. Then k = b/a. All the statements in method 2 that affect the value of e are e = −0.5; e = e − 1; e = e + b a . Multiplying 2a to both sides of these three expressions, we obtain 2a ∗ e = −a; 2a ∗ e = 2a ∗ e − 2a; 2a ∗ e = 2a ∗ e + 2b; Naming 2a ∗ e by d yields d = −a; d = d − 2a; d = d + 2b.
  • 5. LESSON 4: Drawing Line Segments 5 Using these three expressions to replace the original statements that are used to generate e in method 2 yields the following pseudo code. long x, y, dx, dy, d; x = xs; y = ys; dx = 2*(xe - xs); /* dx = 2a */ dy = 2*(ye - ys); /* dy = 2b */ d = -(xe - xs); /* d = -a */ for(x=xs; x<=xe; x++) { if(d < 0) write_pixel(x, y); else { y = y + 1; write_pixel(x,y); d = d - dx; } d = d + dy; } Remarks: This algorithm uses integer operations only. It can be further simplified by re-arranging some statements.
  • 6. LESSON 4: Drawing Line Segments 6 Bresenham’s algorithm By combining the statement d = d - dx; and d = d + dy; in the case of moving up diagonally, we have the final algorithm, which on average uses one integer addition and one sign testing per pixel. long x, y, dx, dy, dy_x, d; x = xs; y = ys; dx = 2*(xe - xs); /* dx = 2a */ dy = 2*(ye - ys); /* dy = 2b */ dy_x = dy - dx; d = -(xe - xs); /* d = -a */ for(x=xs; x<=xe; x++) { if(d < 0) d = d + dy; else { y = y + 1; d = d + dy_x; } write_pixel(x,y); }
  • 7. LESSON 4: Drawing Line Segments 7 Question: Can you come up with a line drawing algorithm that is faster than Bresen- ham’s algorithm?