SlideShare a Scribd company logo
1 of 22
MODULE 1 1
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
COURSE CODE: 22CS401
COURSE TITLE : COMPUTER GRAPHICS AND MULTIMEDIA
OUTPUT PRIMITIVES
Graphics programming packages provide functions to describe a scene in terms of
basic geometric structures referred to as output primitives.
• Points
• Straight lines
• Circles
• Splines curves and surfaces
• Polygon color areas
• Character strings
• Etc.
A picture can be described in several ways. In raster display, a picture is completely
specified by the set of intensities for the pixel positions in the display. At the other
extreme, we can describe a picture as a set of complex objects, such as trees and
terrain or furniture and walls
MODULE 1 2
POINTS
The electron beam is turned on to illuminate the phosphor at the selected
location (x, y) where
0 ≤ x ≤ maxx
0 ≤ y ≤ maxy
• setpixel(x, y, intensity) – loads an intensity value into the frame-buffer at
(x, y).
• getpixel(x, y) – retrieves the current frame-buffer intensity setting at
position (x, y).
MODULE 1 3
(0,0)
(maxx,maxy)
LINE
A line connects two points. It is a basic element in graphics. To draw a
line, you need two points between which you can draw a line. We refer
the one point of line as X0,Y0 and the second point of line as X1,Y1
LINE ATTRIBUTES
Line type
Solid lines, dashed lines, and dotted lines
Line Width
It is assigned a positive number to indicate the relative width of the line to be
displayed..
Line Color
Color by setting this color value in the framebuffer at pixel locations along
the line path
MODULE 1 4
Line Drawing Algorithms
The process of ‘turning on’ the pixels for a line segment is called vector
generation or line generation, and the algorithms for them are known as
vector generation algorithms or line drawing algorithms.
MODULE 1 5
Cartesian equation:
y = mx + c
where
m – slope
c – y-intercept
x1
y1
x2
y2
x
y
x
x
y
y
m






1
2
1
2
6
if |m| = 1
 = 45°
45°
45°
+ve -ve
°
°
°
°
if |m|  1
-45° <  < 45°
if |m|  1
45° <  < 90° or
-90° <  < -45°
Line drawing is accomplished by calculating intermediate positions along the line path between specified end
points.
MODULE 1
MODULE 1 7
>
DDA Algorithm
The Digital differential analyzer (DDA) algorithm is an
incremental scan-conversion method.
Such an approach is characterized by performing calculations at
each step using results from the preceding step
Algorithm:
(x1,y1) (x2,y2) are the end points and dx, dy are the float variables.
Where dx= abs(x2-x1) and dy= abs(y2-y1)
(i) If dx >=dy then
length = dx
else
length = dy
endif
MODULE 1 8
(ii) dx = (x2-x1)/length
dy = (y2-y1)/length
(iii) x = x1 + 0.5
y = y1 + 0.5
(iv) i = 0
(v) While(i<=length)
(vi) x = x + dx
y = y + dy
(v) Plot ((x), (y))
(vii) i = i + 1
Limitations of DDA:
(1) The rounding operation & floating point arithmetic are time consuming
procedures.
(2) Round-off error can cause the calculated pixel position to drift away from the
true line path for long line segment.
MODULE 1 9
• Example 1: consider the line from (0,0) to (4,6). Use the simple DDA
algorithm to rasterize this line
Solution:
• x1=0 y1=0 x2=4 y2=6
• Length = 𝑦2− 𝑦1 =6
• Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡ℎ= 4/6
• and Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡ℎ=6/6 = 1
• Initial value for
MODULE 1 10
Sl.no Plot X Y
1 (0,0) 0 0
2 (1,1) 0.66 1
3 (1,2) 1.32 2
4 (2,3) 1.98 3
5 (3,4) 2.64 4
6 (3,5) 3.3 5
7 (4,6) 3.96 6
MODULE 1 11
The Bresenham Line Algorithm
•The Bresenham algorithm is another incremental scan conversion algorithm
•The big advantage of this algorithm is that it uses only integer calculations
•Move across the x axis in unit intervals and at each step choose
between two different y coordinates
MODULE 1 12
2 3 4 5
2
4
3
5
(xk, yk)
(xk+1, yk)
(xk+1, yk+1)
For example, from
position (2, 3) we have
to choose between (3,
3) and (3, 4)
We would like the
point that is closer to
the original line
Steps :
1. Find the Coordinates of North point and South point.
2. Write the Cartesian equation of line : y=mx+b
3. Find dlower and dupper.
4. Substitute the value of y in dlower and dupper.
5. Subtract dlower and dupper in this equation we have the term “m”
6. Substitute the value of “m” by
Δ𝑦
Δ𝑥
7. Multiply “Δx“ on both side and name the equation as pk
8. Find decision parameter for next point so k is changes to k+1
9. Subtract pk+1-pk
10.If pk<0 choose lower pixel and substitute the coordinates in final equ
11.If pk>0 choose higher pixel and substitute the coordinates in final equ
MODULE 1 13
Deriving The Bresenham Line Algorithm
At sample position xk+1 the vertical separations from the mathematical line
are labelled dupper and dlower
MODULE 1 14
y
yk
yk+1
xk+1
dlower
dupper
b
x
m
y k 

 )
1
(
• So, dupper and dlower are given as follows:
dlower = y – yk= m(xk + 1) + b – yk -----------------------------------1
dupper = yk + 1 – y = yk+ 1– m(xk + 1) – b-------------- 2
Subtract dlower - dupper
dlower-dupper = m(xk + 1) + b – yk- yk-1+ m(xk + 1) + b
• The difference between these two separations is
• dlower – dupper = 2m(xk + 1)–2yk + 2b – 1
MODULE 1 15
MODULE 1 16
dlower – dupper = 2m(xk + 1)–2yk + 2b – 1
Let’s substitute m with ∆y/∆x where ∆x and ∆y are the differences
between the end-points:
dlower – dupper = [2(∆y/∆x)(xk + 1) ]– 2yk + 2b – 1
Multiplying both side by (∆x)
= [ 2∆y xk+ 2∆y – 2∆x yk + 2∆x b – ∆x]
= [ 2∆y xk – 2∆x yk + 2∆x b – ∆x + 2∆y]
= [ 2∆y xk – 2∆x yk + c]
Where c = 2∆x b – ∆x + 2∆y
∆x (dlower – dupper) = 2∆y xk – 2∆x yk + c
∆x (dlower – dupper) = 2∆y xk – 2∆x yk + c
• This equation is used as a simple decision about which pixel is closer to
the mathematical line.
• So, a decision parameter pk for the kth step along a line is given by:
pk = ∆x (dlower – dupper) = 2∆y xk – 2∆x yk + c
• The sign of the decision parameter pk is the same the sign of dlower–dupper,
• if the pixel at yk is closer to the line path than the pixel at yk+1 (that is
dlower<dupper), then decision parameter pk is negative. In this case we plot
the lower pixel, otherwise we plot the upper pixel.
MODULE 1 17
Coordinate changes along the line occur in unit steps in either the x or y directions.
Therefore, we can obtain the values of successive decision parameters using
incremental integer calculations.
At step k+1 the decision parameter is given as:
pk+1 = 2∆y xk+1 – 2∆x yk+1 + c
Subtracting pk from this we get:
pk+1 – pk = 2∆y( xk+1– xk ) – 2∆x( yk+1 – yk )
If pk < 0, the next point to plot is (xk+1, yk) and
pk+1 = pk + 2∆y
Otherwise, the next point to plot is (xk+1, yk+1) and
pk+1 = pk + 2∆y – 2∆x
MODULE 1 18
Bresenham ’s Line Drawing Algorithm
The recursive calculation of decision parameters is performed at
each integer x position, starting at the left coordinate endpoint of
the line.
The first decision parameter p0 is evaluated at the starting pixel
position (x0, y0) and with m evaluated as (∆y/∆x):
P0 = 2∆y – ∆x
The following steps summarize Bresenham’s Line Drawing
Algorithm for a line with positive slope less than 1 (|m|<1)
MODULE 1 19
Bresenham ’s Line Drawing Algorithm
1.Input the two line end-points, storing the left end-point in (x0,y0)
2.Plot the point (x0, y0)
3.Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and get the first value for
the decision parameter as:
P0 = 2∆y – ∆x
4.At each xk along the line, starting at k=0, perform the following test:
If pk < 0, the next point to plot is (xk+1, yk) and
pk+1 = pk + 2∆y
Otherwise, the next point to plot is (xk+1, yk+1) and
pk+1 = pk + 2∆y – 2∆x
5.Repeat step 4 (Δx ) times
MODULE 1 20
Bresenham ’s Line Drawing Algorithm
Bresenham’s Line Drawing Example
To illustrate the algorithm, we digitize the line with endpoints(20,10) and (30,
18). This line has a slope of 0.8, with
Δx =10, Δy = 8
The initial decision parameter has the value P0 = 2∆y – ∆x = 6
And the increments for calculation successive decision parameters are:
2Δy = 16,
2Δy – 2Δx= – 4
We plot the initial point (20, 10) , and determine successive pixel positions along
the line path from the decision parameters as:
MODULE 1 21
MODULE 1 22
k pk (xk+1, yk+1)
0 6 (21, 11)
1 2 (22, 12)
2 -2 (23, 12)
3 14 (24, 13)
4 10 (25, 14)
5 6 (26, 15)
6 2 (27, 16)
7 -2 (28, 16)
8 14 (29, 17)
9 10 (30, 18)
• If pk < 0, (xk+1, yk)
pk+1 = pk + 2∆y
If pk >0 , (xk+1, yk+1)
pk+1 = pk + 2∆y – 2∆x
2Δy = 16,
2Δy – 2Δx= – 4
Bresenham ’ Line Drawing Algorithm
Bresenham’s Line Drawing Example

More Related Content

Similar to Output Primitive and Brenshamas Line.pptx

CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfRajJain516913
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptAliZaib71
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenhamsimpleok
 
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
 
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
 
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
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithmnehrurevathy
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Lect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsLect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsBCET
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptKhondokarMdMehediHas
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationMuhammad Fiaz
 

Similar to Output Primitive and Brenshamas Line.pptx (20)

2.circle
2.circle2.circle
2.circle
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
 
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
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
10994479.ppt
10994479.ppt10994479.ppt
10994479.ppt
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
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
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Lect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsLect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygons
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 

Recently uploaded

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Recently uploaded (20)

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

Output Primitive and Brenshamas Line.pptx

  • 1. MODULE 1 1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING COURSE CODE: 22CS401 COURSE TITLE : COMPUTER GRAPHICS AND MULTIMEDIA
  • 2. OUTPUT PRIMITIVES Graphics programming packages provide functions to describe a scene in terms of basic geometric structures referred to as output primitives. • Points • Straight lines • Circles • Splines curves and surfaces • Polygon color areas • Character strings • Etc. A picture can be described in several ways. In raster display, a picture is completely specified by the set of intensities for the pixel positions in the display. At the other extreme, we can describe a picture as a set of complex objects, such as trees and terrain or furniture and walls MODULE 1 2
  • 3. POINTS The electron beam is turned on to illuminate the phosphor at the selected location (x, y) where 0 ≤ x ≤ maxx 0 ≤ y ≤ maxy • setpixel(x, y, intensity) – loads an intensity value into the frame-buffer at (x, y). • getpixel(x, y) – retrieves the current frame-buffer intensity setting at position (x, y). MODULE 1 3 (0,0) (maxx,maxy)
  • 4. LINE A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line. We refer the one point of line as X0,Y0 and the second point of line as X1,Y1 LINE ATTRIBUTES Line type Solid lines, dashed lines, and dotted lines Line Width It is assigned a positive number to indicate the relative width of the line to be displayed.. Line Color Color by setting this color value in the framebuffer at pixel locations along the line path MODULE 1 4
  • 5. Line Drawing Algorithms The process of ‘turning on’ the pixels for a line segment is called vector generation or line generation, and the algorithms for them are known as vector generation algorithms or line drawing algorithms. MODULE 1 5 Cartesian equation: y = mx + c where m – slope c – y-intercept x1 y1 x2 y2 x y x x y y m       1 2 1 2
  • 6. 6 if |m| = 1  = 45° 45° 45° +ve -ve ° ° ° ° if |m|  1 -45° <  < 45° if |m|  1 45° <  < 90° or -90° <  < -45° Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. MODULE 1
  • 8. DDA Algorithm The Digital differential analyzer (DDA) algorithm is an incremental scan-conversion method. Such an approach is characterized by performing calculations at each step using results from the preceding step Algorithm: (x1,y1) (x2,y2) are the end points and dx, dy are the float variables. Where dx= abs(x2-x1) and dy= abs(y2-y1) (i) If dx >=dy then length = dx else length = dy endif MODULE 1 8
  • 9. (ii) dx = (x2-x1)/length dy = (y2-y1)/length (iii) x = x1 + 0.5 y = y1 + 0.5 (iv) i = 0 (v) While(i<=length) (vi) x = x + dx y = y + dy (v) Plot ((x), (y)) (vii) i = i + 1 Limitations of DDA: (1) The rounding operation & floating point arithmetic are time consuming procedures. (2) Round-off error can cause the calculated pixel position to drift away from the true line path for long line segment. MODULE 1 9
  • 10. • Example 1: consider the line from (0,0) to (4,6). Use the simple DDA algorithm to rasterize this line Solution: • x1=0 y1=0 x2=4 y2=6 • Length = 𝑦2− 𝑦1 =6 • Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡ℎ= 4/6 • and Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡ℎ=6/6 = 1 • Initial value for MODULE 1 10
  • 11. Sl.no Plot X Y 1 (0,0) 0 0 2 (1,1) 0.66 1 3 (1,2) 1.32 2 4 (2,3) 1.98 3 5 (3,4) 2.64 4 6 (3,5) 3.3 5 7 (4,6) 3.96 6 MODULE 1 11
  • 12. The Bresenham Line Algorithm •The Bresenham algorithm is another incremental scan conversion algorithm •The big advantage of this algorithm is that it uses only integer calculations •Move across the x axis in unit intervals and at each step choose between two different y coordinates MODULE 1 12 2 3 4 5 2 4 3 5 (xk, yk) (xk+1, yk) (xk+1, yk+1) For example, from position (2, 3) we have to choose between (3, 3) and (3, 4) We would like the point that is closer to the original line
  • 13. Steps : 1. Find the Coordinates of North point and South point. 2. Write the Cartesian equation of line : y=mx+b 3. Find dlower and dupper. 4. Substitute the value of y in dlower and dupper. 5. Subtract dlower and dupper in this equation we have the term “m” 6. Substitute the value of “m” by Δ𝑦 Δ𝑥 7. Multiply “Δx“ on both side and name the equation as pk 8. Find decision parameter for next point so k is changes to k+1 9. Subtract pk+1-pk 10.If pk<0 choose lower pixel and substitute the coordinates in final equ 11.If pk>0 choose higher pixel and substitute the coordinates in final equ MODULE 1 13
  • 14. Deriving The Bresenham Line Algorithm At sample position xk+1 the vertical separations from the mathematical line are labelled dupper and dlower MODULE 1 14 y yk yk+1 xk+1 dlower dupper b x m y k    ) 1 (
  • 15. • So, dupper and dlower are given as follows: dlower = y – yk= m(xk + 1) + b – yk -----------------------------------1 dupper = yk + 1 – y = yk+ 1– m(xk + 1) – b-------------- 2 Subtract dlower - dupper dlower-dupper = m(xk + 1) + b – yk- yk-1+ m(xk + 1) + b • The difference between these two separations is • dlower – dupper = 2m(xk + 1)–2yk + 2b – 1 MODULE 1 15
  • 16. MODULE 1 16 dlower – dupper = 2m(xk + 1)–2yk + 2b – 1 Let’s substitute m with ∆y/∆x where ∆x and ∆y are the differences between the end-points: dlower – dupper = [2(∆y/∆x)(xk + 1) ]– 2yk + 2b – 1 Multiplying both side by (∆x) = [ 2∆y xk+ 2∆y – 2∆x yk + 2∆x b – ∆x] = [ 2∆y xk – 2∆x yk + 2∆x b – ∆x + 2∆y] = [ 2∆y xk – 2∆x yk + c] Where c = 2∆x b – ∆x + 2∆y ∆x (dlower – dupper) = 2∆y xk – 2∆x yk + c
  • 17. ∆x (dlower – dupper) = 2∆y xk – 2∆x yk + c • This equation is used as a simple decision about which pixel is closer to the mathematical line. • So, a decision parameter pk for the kth step along a line is given by: pk = ∆x (dlower – dupper) = 2∆y xk – 2∆x yk + c • The sign of the decision parameter pk is the same the sign of dlower–dupper, • if the pixel at yk is closer to the line path than the pixel at yk+1 (that is dlower<dupper), then decision parameter pk is negative. In this case we plot the lower pixel, otherwise we plot the upper pixel. MODULE 1 17
  • 18. Coordinate changes along the line occur in unit steps in either the x or y directions. Therefore, we can obtain the values of successive decision parameters using incremental integer calculations. At step k+1 the decision parameter is given as: pk+1 = 2∆y xk+1 – 2∆x yk+1 + c Subtracting pk from this we get: pk+1 – pk = 2∆y( xk+1– xk ) – 2∆x( yk+1 – yk ) If pk < 0, the next point to plot is (xk+1, yk) and pk+1 = pk + 2∆y Otherwise, the next point to plot is (xk+1, yk+1) and pk+1 = pk + 2∆y – 2∆x MODULE 1 18
  • 19. Bresenham ’s Line Drawing Algorithm The recursive calculation of decision parameters is performed at each integer x position, starting at the left coordinate endpoint of the line. The first decision parameter p0 is evaluated at the starting pixel position (x0, y0) and with m evaluated as (∆y/∆x): P0 = 2∆y – ∆x The following steps summarize Bresenham’s Line Drawing Algorithm for a line with positive slope less than 1 (|m|<1) MODULE 1 19
  • 20. Bresenham ’s Line Drawing Algorithm 1.Input the two line end-points, storing the left end-point in (x0,y0) 2.Plot the point (x0, y0) 3.Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and get the first value for the decision parameter as: P0 = 2∆y – ∆x 4.At each xk along the line, starting at k=0, perform the following test: If pk < 0, the next point to plot is (xk+1, yk) and pk+1 = pk + 2∆y Otherwise, the next point to plot is (xk+1, yk+1) and pk+1 = pk + 2∆y – 2∆x 5.Repeat step 4 (Δx ) times MODULE 1 20
  • 21. Bresenham ’s Line Drawing Algorithm Bresenham’s Line Drawing Example To illustrate the algorithm, we digitize the line with endpoints(20,10) and (30, 18). This line has a slope of 0.8, with Δx =10, Δy = 8 The initial decision parameter has the value P0 = 2∆y – ∆x = 6 And the increments for calculation successive decision parameters are: 2Δy = 16, 2Δy – 2Δx= – 4 We plot the initial point (20, 10) , and determine successive pixel positions along the line path from the decision parameters as: MODULE 1 21
  • 22. MODULE 1 22 k pk (xk+1, yk+1) 0 6 (21, 11) 1 2 (22, 12) 2 -2 (23, 12) 3 14 (24, 13) 4 10 (25, 14) 5 6 (26, 15) 6 2 (27, 16) 7 -2 (28, 16) 8 14 (29, 17) 9 10 (30, 18) • If pk < 0, (xk+1, yk) pk+1 = pk + 2∆y If pk >0 , (xk+1, yk+1) pk+1 = pk + 2∆y – 2∆x 2Δy = 16, 2Δy – 2Δx= – 4 Bresenham ’ Line Drawing Algorithm Bresenham’s Line Drawing Example