60 views

Uploaded by Bhavini Rajendrakumar Bhatt

Bresenham Line Drawing Algorithm

- Activating FIORI-Apps in S4 HANA
- Math 21-1 Syllabus
- Applications in CADD n4ce Point Coding and Code Table
- EngineeringDrawing_GSV
- Como llamar a números 800 y 877.doc
- XDKÐÞ¸Ä
- Computer Graphics Anna University Local Author
- Graphics & Multimedia
- 2012 Hsc Exam Maths Ext1
- 73RenderMapLayoutsToKML
- Spm 2016 Tips
- 2Line_Algorithms1
- Photoshop Flyer1.5
- Ch02
- Belot - Remarks on the Geometry of Visibles
- 2 More PyGame
- 2007 Anderson AM Prelim Paper 1
- Neural Network and Regression Spline Value Function Approximations for Stochastic Dynamic Programming
- Intro Gp
- Vector Photoshop Tutorial 2

You are on page 1of 28

Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Pixel addressing in raster graphics and how does computer draw line?

Screen made of pixels High-level language specifies line System must color pixels

Pixel address y y+1 y+2 y+3 x x+1 x+2 x+3 x+4

Theoretical length

Pixel

Actual length

symbols & descriptions y = 2x + 5 x0 = 100 y0 = 50 d = 100 thickness = 4 images

m<1

m>1

Line drawn as pixels Graphics system

Projects the endpoints to their pixel locations in the frame buffer (screen coordinates as integers) Finds a path of pixels between the two Loads the color Plots the line on the monitor from frame buffer (video controller) Rounding causes all lines except horizontal or vertical to be displayed as jigsaw appearance (low resolution) Improvement: high resolution, or adjust pixel intensities on the line path.

Line equation

Slope-intercept form y=m.x+ b slope m y-intercept b

Slope y-intercept

b y0 mx0

yend y0 y m xend x0 x

y mx x

y

m

For lines with slope |m|<1, x can be set to a proportional to small deflection value, y can be calculated from the formula For lines with slope |m|<1, y can be set to a proportional to small deflection value, x can be calculated from the formula

DDA (Digital Differential Analyzer)

Scan conversion line algorithm based on calculating either x or y Line sampled at regular intervals of x, then corresponding y is calculated and rounded From left to right

if m 1.0, if m > 1.0,

if m 1.0, if m > 1.0,

y k +1 = y k + m x k +1 = x k 1 + m

1 m

( x = 1) ( y = 1)

( x = -1) ( y = -1)

y k +1 = y k - m x k +1 = x k -

void lineDDA (int x0, int y0, int xEnd, int yEnd) { int dx = xEnd - x0, dy = yEnd - y0, steps, k; float xIncrement, yIncrement, x = x0, y = y0; if (fabs (dx) > fabs (dy)) steps = fabs (dx); else steps = fabs (dy); xIncrement = float (dx) / float (steps); yIncrement = float (dy) / float (steps); setPixel (round (x), round (y)); for (k = 0; k < steps; k++) { x += xIncrement; y += yIncrement; setPixel (round (x), round (y)); } }

Y_inc

X_inc

DDA Algorithm

Start with starting and ending coordinates of the line:

(x0, y0) and (x1, y1)

Color first pixel (round to nearest integer) Suppose x1-x0 > y1-y0 (gentle slope)

There will be x1-x0 steps (# pixels to be colored)

increment x by (x1-x0)/numsteps, and increment y by (y1-y0)/numsteps

For each step, round off x and y to nearest integer, and color pixel

DDA Pseudo-code

// assume that slope is gentle DDA(float x0, float x1, float y0, float y1) { float x, y; float xinc, yinc; int numsteps; numsteps = Round(x1) Round(x0); xinc = (x1 x0) / numsteps; yinc = (y1 y0) / numsteps; x = x0; y = y0; ColorPixel(Round(x),Round(y)); for (int i=0; i<numsteps; i++) { x += xinc; y += yinc; ColorPixel(Round(x),Round(y)); }

Q: For each step, how many floating point operations are there? A: 4 Q: For each step, how many integer operations are there? A: 2

DDA Example

Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). What are the values of the variables x and y at each timestep? What are the pixels colored, according to the DDA algorithm?

numsteps = 12 2 = 10 xinc = 10/10 = 1.0 yinc = 5/10 = 0.5 t 0 1 2 3 4 5 6 7 8 9 10 x 2 3 4 5 6 7 8 9 10 11 12 y 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 R(x) 2 3 4 5 6 7 8 9 10 11 12 R(y) 3 4 4 5 5 6 6 7 7 8 8

DDA Algorithm

Advantage

Does not calculate coordinates based on the complete equation (uses offset method)

Disadvantage

Round-off errors are accumulated, thus line diverges more and more from straight line Round-off operations take time

Perform integer arithmetic by storing float as integers in numerator and denominator and performing integer arithmetic.

Efficient line drawing algorithm using only incremental integer calculations Can be adapted to draw circles and other curves Principle

Vertical axes show scan line positions Horizontal axes show show pixel columns At each step, determine the best next pixel based on the sign of an integer parameter whose value is proportional to the difference between the vertical separations of the two pixel positions from the actual line.

Bresenhams Algorithm

Uses only integer calculations Uses distance between ideal y-coordinate and the upper and lower pixel (assuming gentle slope)

dupper dlower

first consider the scan-conversion process for lines with positive slope less than 1. Pixel positions along a line path are then determined by sampling at unit x intervals. Starting from the left endpoint (xo, yo) of a given line, we step to each successive column (x position) and plot the pixel whose scanline y value is closest to the line path. Figure 3-7 demonstrates the Kth step in this process. Assuming we have determined that the pixel at (xk, yk) is to be displayed, we next need to decide which pixel to plot in column xk+1, Our choices are the pixels at positions (Xk+l, Yk) and (Xk+l, Yk+l).

Section of the screen grid showing a pixel in column xk on scan line yk that is to be plotted along the path of a line segment with slope O<m<l.

Distances between pixel positions and the line y coordinate at sampling position xk+ I.

y = mx + b

y = m(x+1) + b y

d2

d1

x+1

1. Input the two line endpoints and store the left endpoint in (x0, y0). 2. Set the color for the frame-buffer position (x0, y0) i.e. plot the first point. 3. Calculate the constant x, y, 2y and 2y 2x, and set the starting value for the decision parameter as p0 = 2y x 4. At each xk along the line, from k=0, perform the following test:

if pk<0, next point to plot is (xk + 1, yk) and pk+1 = pk + 2y otherwise, next point to plot is (xk + 1, yk + 1 ) and pk+1 = pk + 2y- 2x Repeat step-4 x times.

5.

Q: In each step, how many floating point operations are there? A: 0

Q: In each step, how many integer operations are there? A: 3 or 4

Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). What are the values of p0, dx and dy? What are the values of the variable p at each timestep? What are the pixels colored, according to Bresenhams algorithm?

dx = 12 2 = 10 dy = 8 3 = 5 p0 = 2dy dx = 15 t 0 1 2 3 p 0 -10 0 -10 P(x) 2 3 4 5 2dy = 10 2dy 2dx = -10 P(y) 3 4 4 5

4

5 6 7 8 9 10

0

-10 0 -10 0 -10 0

6

7 8 9 10 11 12

5

6 6 7 7 8 8

DDA works with floating point arithmetic Rounding to integers necessary

Bresenhams algorithm uses integer arithmetic Constants need to be computed only once Bresenhams algorithm generally faster than DDA

- Activating FIORI-Apps in S4 HANAUploaded bypandu M
- Math 21-1 SyllabusUploaded byakladffja
- Applications in CADD n4ce Point Coding and Code TableUploaded bytrimble20
- EngineeringDrawing_GSVUploaded byManindra Smile
- Como llamar a números 800 y 877.docUploaded byyuritabasco
- XDKÐÞ¸ÄUploaded bylesloldu94
- Computer Graphics Anna University Local AuthorUploaded byArunsankar Muralitharan
- Graphics & MultimediaUploaded byKamran Shabbir
- 2012 Hsc Exam Maths Ext1Uploaded byYouieee
- 73RenderMapLayoutsToKMLUploaded bytuyenHTHOme
- Spm 2016 TipsUploaded byAnonymous x0kzb3U
- 2Line_Algorithms1Uploaded byKrishna Ananthi
- Photoshop Flyer1.5Uploaded byroopa_jakkilinki
- Ch02Uploaded byIAGPLS
- Belot - Remarks on the Geometry of VisiblesUploaded byM̨͡i͝g̛̕͢u̶e̢l̸̀ E̡͝d̴̕u͢͠͠à͠͠rdo D̀҉í̢̀a̵z̸̀̕D̀҉í̢̀a̵z̸̀̕
- 2 More PyGameUploaded byTessa_Gray_
- 2007 Anderson AM Prelim Paper 1Uploaded bySaraswathi Somasundaram
- Neural Network and Regression Spline Value Function Approximations for Stochastic Dynamic ProgrammingUploaded bycall2000
- Intro GpUploaded byBudditha Hettige
- Vector Photoshop Tutorial 2Uploaded byIan Platino
- SyllabusUploaded bynickiharrison
- 5) C1 Coordinate Geometry in the (x,y) PlaneUploaded byAhmed Khalil
- XY intro BUploaded byRC Gonzalez
- 06.pdfUploaded bySeanGoonShengTang
- Hex Grid Geometry for Game Developers (1.3)Uploaded byMarcelo Lima Souza
- 01_01_Circles_1Uploaded byrohit kumar
- Mies Van Der Rohe_casa 50x50Uploaded byCarlos Avila Caro
- Updated Production Schedule - Taipei - 1st Biz DayUploaded bydeeush
- Sidebar ConkyUploaded byPetreanu Iulian
- Slides Lecture5Uploaded byBatoul Zargar

- Lammenranta_The+Pyrrhonian+Problematic - CopiaUploaded byortegapolito
- Absolute and Relative VaR of a mutual fund.Uploaded byLello Pacella
- IISc coursesUploaded bysammyeng
- CRM on Demand Web Service LoginUploaded bySankalp Damele
- How O2 Sensor WorksUploaded byAnonymous 60esBJZIj
- Sequence Detector Application ExamplesUploaded byXXX
- S100LA_EUploaded byRisto Zlatkov
- Guys and AnchorsUploaded byVijay Kumar
- U-Net Simulation Principle and Flow 1.0Uploaded byicfaisumit
- CCC Question Paper 2017 With Answer PDF Online Test for Computer _ Current Affairs Recruitment News TodayUploaded byjit19942007
- Boiler Inspection Guidance.pdfUploaded byAnonymous yCpjZF1rF
- Electrical Engineering PortalUploaded byerson1981
- design of aquarium probeUploaded byAbdulwaliyu Usman Yasin
- DS360 DatasheetUploaded byQuinn Rocker
- zamil DY_series.pdfUploaded bygagokapala
- ASTM A 500Uploaded byLuckySingh
- C18_FIRE_PUMP_597_BKW_800_BHP_1750_RPM.pdfUploaded byDenis Jimenez
- Stress–Strain CurveUploaded bycool47guy09
- Basys 2 Reference ManualUploaded byAnonymous lidok7lDi
- IRJET-ECO-FRIENDLY CAR USING SOLAR AND ELECTRICAL ENERGYUploaded byIRJET Journal
- turbulence.docxUploaded byShreyansh Shukla
- Free Radicals &CarbocationsUploaded byOmkar Kumar Jha
- SQLite Transactions With Visual BasicUploaded byKamadhatu Anahata
- 1 IJAERS-DEC-2014-2-Implementation of LC Filter in Torque Ripple Minimization of Sensorless BLDC Motor.pdfUploaded byIJAERS JOURNAL
- Filter Water Tank.xlsUploaded byHemant Sonawadekar
- Small_Volume_Fabrication_Cost_Est_Models.pdfUploaded bypvdang8453
- Steam TurbineUploaded byAbhinav
- Abaqus Soil Examples_2Uploaded byGustavo Nagel
- Dilute-acid Hydrolysis of Cellulose to Glucose from Sugarcane BagasseUploaded byMaxPostvanderBurg
- Supporting Students in Mathematics Through the Use of ManipulativesUploaded byPusti Alaufa