0% found this document useful (0 votes)
147 views29 pages

Csse 351 Computer Graphics: Ddas and Line Drawing

This document discusses techniques for rendering lines in computer graphics, including digital difference analyzers (DDAs) and midpoint line drawing algorithms. It begins with an overview of the rendering pipeline and rasterization process. It then covers DDA line drawing, which uses floating point operations to incrementally calculate pixel locations along a line. The document introduces midpoint line drawing as a simpler alternative that uses only integer calculations by tracking whether the line is above or below the midpoint between pixel centers. Optimization techniques for midpoint line drawing include precomputing values to avoid full line equation evaluations and removing floating point numbers.

Uploaded by

nooti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views29 pages

Csse 351 Computer Graphics: Ddas and Line Drawing

This document discusses techniques for rendering lines in computer graphics, including digital difference analyzers (DDAs) and midpoint line drawing algorithms. It begins with an overview of the rendering pipeline and rasterization process. It then covers DDA line drawing, which uses floating point operations to incrementally calculate pixel locations along a line. The document introduces midpoint line drawing as a simpler alternative that uses only integer calculations by tracking whether the line is above or below the midpoint between pixel centers. Optimization techniques for midpoint line drawing include precomputing values to avoid full line equation evaluations and removing floating point numbers.

Uploaded by

nooti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

CSSE 351

Computer Graphics
DDAs and line drawing

1
Session schedule

• Rasterization
• DDAs
• Line drawing

2
Render pipeline

• All geometry is in NDC


• No geometry out of view volume (NDC)

• Convert to fragments (pixels)

3
Render pipeline
• Render pipeline changes coordinate/vector
spaces
• Ready for
• Fragment conversion
• Interpolation
• Depth sorting
4
Rasterization
• Compute fragment locations in window
coordinates
• Interpolate vertex attributes
• Compute fragment color

• Sort fragments by depth


5
On screen display
• Write some data to frame buffer
• Starting from geometric data

6
Draw points

• Simplest data is to show points


• Transform vertices
• Convert to NDC, then viewport
• Clamp/round to pixel value, show on
screen!

7
Draw points

8
Drawing lines

• Transform vertices
• Convert to NDC, clip, convert to viewport
• Now have sets of lines in 2D space
• Need to convert 2D geometry into
pixels

9
Drawing lines
• Convert endpoints to pixel values
x1, y1
x2, y2
• Draw line between pixel values

• Use DDA (Digital Difference Analyzer)


10
DDA
• Compute line differential
y y
2 1 y
m= =
x2 x1 x
• Restrict slope to
0m1

• Vertical change is then


y=m x

11
DDA
• Using vertical change, make unit steps in x
y=m x
x=1

• Vertical change is then


y=m

• Algorithm to draw line is...


12
DDA line drawing

m = (y2-y1)/(x2-x1)

for x = x1 to x2
y+=m
color_pixel(x, round(y))

13
DDA line drawing

14
DDA

• Requires floating point operations

• Possible to draw lines with only integers


• Bresenham’s line drawing algorithm
• We will cover simpler midpoint version
15
Midpoint line drawing
• Make some assumptions
• x1 < x2 (swap if needed)
• Slope is (0,1]
• Lines have no gaps, diagonal pixels
connect
• How does this help?
16
Midpoint line drawing
• Lines must go right or right+up!
• Just draw increasing x, and move up sometimes

17
Midpoint line drawing
• Resulting code:

y = y0
for x = x0 to x1
draw(x, y)
if(some condition)
y = y + 1

18
Midpoint condition

19
Midpoint condition
• Closest pixel is ‘on the line’
• Orange dots are pixel centers

20
Midpoint condition
• Check if line is above or below midpoint

21
Midpoint condition
• Check if line is above or below test point
• Use implicit line equation
• 0 when on the line
• < 0 when below line
• > 0 when above line

22
Midpoint condition
• Compute implicit line equation for 2D line
• Test next pixel midpoint
• If line above midpoint, move up+right
• If line below midpoint, move right

23
Midpoint line drawing

• Condition checks if line above midpoint


• By seeing if midpoint is below line

• If so, move right and move up

24
Midpoint line drawing
• Code becomes (with line equation f):
y = y0
for x = x0 to x1
draw(x, y)
if( f(x+1, y+0.5) < 0 )
y = y + 1

25
Optimize
• Avoid evaluating full line equation
• Precompute midpoint and increment
• Line:

• Move right:

• Move up+right:

26
Incremental midpoint
• Code:
y = y0
d = f(x0 + 1, y0 + 0.5)
for x = x0 to x1
draw(x, y)
if(d < 0)
y = y + 1
d = d + (x1-x0) + (y0-y1)
else
d = d + (y0-y1)
27
Optimize

• Last optimization is to remove floating


point...

• Might discuss much later

28
Using midpoint &
DDAs
• But, but, but!
• Other slopes?
• Swap order of line endpoints
• Symmetric around origin
• Swap x and y, minor adjustment to
calculations (plus vs. minus)

29

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy