Bresenham Circles More Raster Line Issues Generating Circles

Spring 2013
More Raster Line Issues
• Fat lines with multiple pixel width
Lecture Set 3
Bresenham Circles
• Symmetric lines
• End point geometry – how should it
look?
CS5600 Intro to Computer Graphics
• Generating curves, e.g., circles, etc.
From Rich Riesenfeld
Spring 2013
Spring 2013
CS 5600
• Jaggies, staircase effect, aliasing...
1
Generating Circles
Exploit 8-Point Symmetry
( y , x )
(  x, y )
( x, y )
(  x,  y )
( x,  y )
(  y , x )
Once More: 8-Pt Symmetry
( y , x )
( x, y )
(  x,  y )
( x,  y )
CS5600
( y, x)
( y, x)
Only 1 Octant Needed
We will
generate
2nd Octant
( y, x)
(  x, y )
(  y , x )
( y, x)
Spring 2013
Generating pt (x,y) gives
the following 8 pts by symmetry:
{(x,y), (-x,y), (-x,-y), (x,-y),
(y,x), (-y,x), (-y,-x), (y,-x)}
2nd Octant Is a Good Arc
• It is a function in this domain
– single-valued
– no vertical tangents:
|slope|  1
• Lends itself to Bresenham
– only need consider E or SE
Choose E or SE
Implicit Eq’s for Circle
• Let
F(x,y) = x 2 + y 2 – r
• For (x,y) on the circle,
2
F(x,y) = 0
• So,
F(x,y) > 0  (x,y) Outside
• And,
F(x,y) < 0  (x,y) Inside
F(M)  0
CS5600
• So,
x2 + y 2 – r 2 = 0
F(M)  0
• And, F(M) < 0
 SE
E
ideal
curve
• Function is
 SE
 E
F(M) < 0
ideal
curve
 E
E
M
M
SE
SE
Spring 2013
Decision Variable
Look at Case 1: E
d
Again, we let,
E
ideal
curve
M
d = F(M )
SE
dold < 0  E
d old  F ( x p  1, y p  1 2)
dold < 0  E
d new  F ( x p  2, y p  1 2 )
2
2
 ( x p  1)  ( y p  1 2)  r 2
2
2
 ( x p  2)  ( y p  1 2 )  r 2
dold < 0  E
dold < 0  E
d new  d old  (2 x p  3)
Since,
dnew  dold
where,
( x p  2) 2  ( x p  1) 2  ( x p 2  4 x p  4)  ( x p 2  2 x p  1)
 2xp3
CS5600
d new  d old   E ,
E  2 x p  3
Spring 2013
dold  0  SE
Look at Case 2: SE
d new  F ( x p  2, y p  3 2 )
E
ideal
curve
2
2
 ( x p  2)  ( y p  3 2 )  r 2
d new  d old  (2 x p  2 y p  5)
M
Because,…, straightforward manipulation
SE
dold  0  SE
dold  0  SE
d new  d old 
3
1


( x p  2) 2  ( y p  ) 2  r 2  ( x p  1) 2  ( y p  ) 2  r 2 
2
2


=
(2 x p  3)  y p 2  3 y p 
9  2
1 
 y  y p  
4  p
4 
d new  d old 
3
1


( x p  2) 2  ( y p  ) 2  xr 2  ( x p  1) 2  ( y p  ) 2  xr 2 
2
2


=
(2 x p  3)  y p 2  3 y p 
dold  0  SE
d new  d old 
3
1


( x p  2) 2  ( y p  ) 2  xr 2  ( x p  1) 2  ( y p  ) 2  xr 2 
2
2


=
CS5600
(2 x p  3)  yx p 2  3 y p 
9  2
1 
  yx  y p  
4  p
4 
9  2
1 
 y  y p  
4  p
4 
dold  0  SE
d new  d old 
9
1
(2 x p  3)  (3 y p  )  ( y p  )
4
4

  
From  E
calculation
From new
y-coordinate
From old
y-coordinate
Spring 2013
dold  0  SE
I.e.,
d new  d old  (2 x p  2 y p  5)
 d old   SE
Note: ∆΄s Not Constant
 E and  SE
depend on values of xp and yp
 SE  2 x p  2 y p  5
Summary
• ∆΄s are no longer constant over entire line
• Let r be an integer. Start at (0, r )
• Algorithm structure is exactly the same
• Next midpoint M lies at (1, r  2 )
• Major difference from the line algorithm
– ∆ is re-evaluated at each step
1
• So, F (1, r  1 )  1  (r 2  r  1 )  r 2
2
– Requires real arithmetic
4

Ellipses
• Evaluation is analogous
• Structure is same
• Have to work out the ∆΄s
CS5600
Initial Condition
5
4
r
Getting to Integers
• Note the previous algorithm
involves real arithmetic
• Can we modify the algorithm to use
integer arithmetic?
Spring 2013
Integer Circle Algorithm
• Define a shift decision variable
1
hd
• Now, the initialization is h = 1 - r
• So the initial value becomes
4
• In the code, plug in d  h 
1
1
4
• Since h an integer
1
4

1
2
4
5
1
 (  r) 
4
4
 1 r
Integer Circle Algorithm
h
1
F (1, r  ) 
4
• Then, d  0 becomes h  
Integer Circle Algorithm
Integer Circle Algorithm
• But, h begins as an integer
• And, h gets incremented by integer
• Hence, we have an integer circle
algorithm
h0
End of Bresenham Circles
• Note: Sufficient to test for h < 0
Another Digital Line Issue
• Clipping Bresenham lines
• The integer slope is not the true
slope
• Have to be careful
• More issues to follow
CS5600
Spring 2013
Clipped Line
Line Clipping Problem
x  xmin
y  y max
x  xmax
( x1, y1 )
( x1, y1 )
Clipping
Rectangle
( x0 , y0 )
( x1, y1 )
( x0 , y0 )
Pick Right Slope to Reproduce
Original Line Segment
Zoom of previous situation
CS5600
y  y min
y  ymin
Drawing Clipped Lines
Clipping
Rectangle
( x 0 , y 0 )
x  x min
x  xmax
Clipped Line Has Different Slope !
m  1
2
m3
4
Pick Right Slope to Reproduce
Original Line Segment
Zoom of previous situation
Spring 2013
Clipping Against x = xmin
x  xmin
x  xmin
NE
( xmin , Round (m xmin  B ))

Clipping Against y = ymin
Line getting
clipped
B
M midpoint
A
y  ymin
E

( xmin , (m xmin  B))
Clip Rectangle
y  ymin
y  ymin  1
2
y  ymin  1
Clipping Against y = ymin
Clipping Against y = ymin
• Situation is complicated
• Use Line ∩ y = ymin - ½
• Multiple pixels involved at ( y = ymin )
• Want all of those pixels as “in”
• Analytic ∩ , rounding
x gives A
• We want point B
Jaggies-Manifestation of Aliasing
Added resolution helps, but does not directly
address underlying issue of aliasing
CS5600
• Round up to nearest integer
x
• This yields point B, the desired result
Jaggies and Aliasing
• To represent a line with discrete pixel
values is to sample finitely a continuous
function
• Jaggies are visual manifestation,
artifacts, resulting from information loss
• The term aliasing is a complicated,
unintuitive phenomenon which will be
defined later
Spring 2013
Jaggies and Aliasing
• Doubling resolution in x and y
reduces the effect of the problem,
but does not fix it
• Doubling resolution costs 4 times
memory, memory bandwidth and
scan conversion time!
Anti-aliasing
Pixel
Space
5
4
3
2
1
0
0
1
2
3
4
5
6
7
8
9
10 11
Pixel intensity (darkness, in this case) is
proportional to area covered by line
Anti-aliasing
Anti-aliasing
Pixel
Space
• Set each pixel’s intensity value
proportional to its area of overlap
(i.e. sub-area) covered by primitive
• Not more than 1 pixel/column for
lines with
Pixel intensity (darkness, in this case)
0 < slope < 1
is proportional to area covered by line
Gupta-Sproull Algorithm -1
• Standard Bresenham chooses E or NE
• Incrementally compute distance D from
chosen pixel to center of line
• Vary pixel intensity by value of D
• Do this for line above and below
CS5600
Gupta-Sproull Algorithm -2
• Use coarse (4-bit, say) lookup table for
intensity : Filter (D, t )
• Note, Filter value depends only on D
and t, not the slope of line! (Very clever)
• For line_width t = 1 geometry and
associated calculations greatly simplify
Spring 2013
Cone Filter for Weighted
Area Sampling






D








r 1
•
•
•
•

Unit thickness line intersects no more than 3 pixels
The End
Bresenham Circles
Lecture Set 3
Lines are complicated
Many aspects to consider
We omitted many
What about intensity of
y=x
t 1
CS5600
Observations
vs
y=0 ?