With thanks to - University of...

55

Transcript of With thanks to - University of...

Page 1: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.
Page 2: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 2

With thanks to

Prof. Rich Riesenfeld (University of Utah)for some slides

Dr. Jack Bresenhamfor some interesting discussions

Page 3: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 3

Implicit Vs. Parametric

Parametric Definition

x = r sin(α)y = r cos(α)0 c α c 2π

Implicit Definition

f(x,y) = x2 + y2 - r2 = 0e.g. r = 1f(0,0) = 0 + 0 - 1 < 0 insidef(0,0) = 1 + 1 - 1 > 0 outside

implies search space to find x,y to satisfy: f(x,y) = 0

iso-surface: f(x,y) - c = 0

Page 4: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 4

Line Characterisations

Explicit:

Implicit:

Constant slope:

Constant derivative:

Bmxy +=

0),( =++= cbyaxyxF

kxy

=ΔΔ

kxf =′ )(

Page 5: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 5

Parametric:

where,

Intersection of 2 planes

Shortest path between 2 points

Convex hull of 2 discrete points

PtPttP 10)()( 1 +−=

PPPP 10 )(;)0( 1 ==

Line Characterisations

Page 6: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 6

Lines vs. Line SegmentsWhat is a discrete line segment?– This is a relatively recent problem

– How to generate a discrete line?

Discrete Line

Page 7: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 7

No gaps in adjacent pixelsPixels close to ideal lineConsistent choices; same pixels in same situations

A Good Line

Page 8: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 8

Smooth lookingEven brightness in all orientationsSame line for as for Double pixels stacked up?

PP 10 PP 01

A Good Line

Page 9: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 9

“Good” Discrete Line - 2

Smooth lookingEven brightness in all orientationsSame line for as for Double pixels stacked up?

PP 10 PP 01

Page 10: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 10

Incremental Fn Eval

RecallCharacteristics– Fast

– Cumulative Error

Need to define

)()()1( ixixfixf Δ+=+

)( oxf

Page 11: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 11

Line segment in first octant with

0 < m < 1

Let us proceed

Restricted Form

Page 12: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 12

Two Line Equations

Explicit:Implicit:

Define:

Hence,

Bmxy +=0),( =++= cbyaxyxF

01

01

xxdxyydy

−=−=

Bxdxdyy +⎟

⎠⎞

⎜⎝⎛=

Page 13: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 13

Relating Explicit to Implicit Eq’s

Recall,

Or,

where,

0=+− Byxdxdy

0)()()( =+−+ Bdxydxxdy

0)()()(),( =+−+=∴ BdxydxxdyyxF

)();();( dxBcdxbdya =−==

Page 14: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 14

Investigate Sign of F

Verify that

Look at extreme values of y

⎪⎩

⎪⎨

+=

0

),( yxFabove line

below line

on line

Page 15: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 15

F(x,y) = ax + by + c = 0a=dy b = -dx and c=B(dx)dx=5 dy=3 B=0

E.g. line (0,0) to (5,3)f(3,3) = 3*3 – 5*3 = -6 <0f(4,2) = 3*4 – 5*2 = 2 >0

Implicit Line Equation

5

3 (3,3)(4,2)

Page 16: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 16

Key to Bresenham Algorithm

“Reasonable assumptions” have reduced the problem to making a binary choice at each pixel:

(Previous)

NE (next)

E (next)

Page 17: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 17

Decision Variable d (logical)

Define a logical decision variable d– linear in form– incrementally updated (with addition)– tells us whether to go E or NE

Page 18: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 18

The Picture

ideal linemidpoint

E

NE

previous

Q

1+= pxx

pxx =

pyy =

1+= pyy

M

Page 19: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 19

Pittaway

Page 20: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 20

The Picture (again)

ideal line

E

NE

previous

Q

),( pp yx

),(211 ++ pp yx

)1,1( ++ pp yx

),( 1 pp yx +

midpointM

Page 21: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 21

Observe the relationships

Suppose Q is above M, as before.Then , M is below the line

So, means line is above M,Need to move NE, increase y value

0)( >MF

0)( >MF

Page 22: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 22

Observe the relationshipsSuppose Q is below M.Then F(M) < 0 , implies M is above the line

So, F(M) < 0 , means line is below M,

Need to move to E; don’t increase y

E

NE

previous

Q

M

Page 23: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 23

Page 24: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 24

Page 25: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 25

Page 26: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 26

Example

Line end points:

Deltas:

)11,9(),;)8,5(), 1100 (( == yxyx

3;4 == dydx

Page 27: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 27

0 0( , ) (0,0) translatex y• ≠ ⇒

Meeting Bresenham Criteria

0; 1 trivial casesm m• = = ⇒

0 1 flip about -axism x• > > − ⇒

1 flip about m x y• > ⇒ =

Page 28: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 28

Case 1: Translate to Origin

x

y ), 11( yx

), 00( yx

), 00( yx ′′

), 11( yx ′′

Page 29: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 29

Case 0: Trivial Situations

Do not need Bresenham

line horizontal0 ⇒=• m

xym =⇒=• line1

Page 30: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 30

Case 1: Translate to Origin

Need only consider lines emanating from the origin.

0 0, ) ( yx• Move to the origin

),),

0,0(),

010111

00

((

);(

yyy

y

xxx

x

−−=′

=′

Page 31: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 31

Case 2: m > -1 Flip about x-axis

), 00( yx

x

y

), 11( yx

), 11( yx ′′), 00( yx ′′

Page 32: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 32

Case 2: Flip about x-axis

Flip about -axis ( ) :x y y• ′ = −

0 0 0 0

1 11 1

, ) ( ,

, ) , )

( );( (x y x y

x y x y

−′ ′ =

′ ′ = −

1Suppose, 0 ,m• > > −

Page 33: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 33

How do slopes relate?

0

1 0

0

1 0

1

1

; by definition

y y

y y

mx x

mx x

−′ ′

⎫= ⎪

⎪⎬⎪′ =⎪⎭

)0

1 0

(1i iSince ,

y ymyy

x x−

− −−− ′′ = =

Page 34: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 34

How do slopes relate?

)0

1 0

1( y ym

x xm m

−′ = −

′=−

1010 <′<⇒−>>∴ mm

i.e.,

Page 35: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 35

Case 3: m > 1: Flip about line y = x

), 11( yx ′′

), 00( yx ′′

y

x

xy =), 11( yx

), 00( yx

Page 36: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 36

Case 3: Flip about line y=x

, swap and prime them ,

,

y mx Bx yx my B

my x B

= +↔′ ′= +′ ′= −

Page 37: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 37

Case 3: m′ = ?

1 ,

1 and,

1 0 1

y x Bm

mm

m m

⎛ ⎞′ ′= −⎜ ⎟⎝ ⎠⎛ ⎞′∴ = ⎜ ⎟⎝ ⎠

′> ⇒ < <

Page 38: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 38

Example

Line end points:

Deltas:

After translation: (0,0) (4,3)

)11,9(),;)8,5(), 1100 (( == yxyx

3;4 == dydx

Page 39: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 39

Graph

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 40: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 40

Example ( dx = 4; dy = 3 )

Initial value of 3;4 == dydx

d = 2dy – dxd = 2*3 – 4 = 2 > 0

incrE = 2*dy = 6incrNE = 2*(-1) = -2

so NE is first move

Page 41: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 41

Graph

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 42: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 42

Example ( dx = 4; dy = 3 )

Last move was NE Update value of d

d = 2 + incrNE = 2 – 2 = 0

So move East

Page 43: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 43

Graph

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 44: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 44

Example ( dx = 4; dy = 3)

Last move was E Update value of d

d = 0 + incrE = 6

So move NE

Page 45: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 45

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 46: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 46

Example ( dx = 4; dy = 3 )

Last move was NE Update value of d

d = 6 + incrNE = 4

So move NE

Page 47: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 47

Graph

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 48: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 48

Graph

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 49: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 49

Graph

1312 11 10 9 8 7 6

4 5 6 7 8 9 10 11

Page 50: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 50

More Raster Line Issues

Fat lines with multiple pixel widthSymmetric linesHow should end pt geometry look?Generating curves, e.g., circles, etc.Jaggies, staircase effect, aliasing...

Page 51: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 51

Pixel Space

1211109876

4 5 6 7 8 9 10

Page 52: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 52

Example

Page 53: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 53

Example

Page 54: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 54

Page 55: With thanks to - University of Victoriawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/linebres.pdf · With thanks to Prof. Rich Riesenfeld (University of Utah) for some slides Dr.

University of Victoria Graphics Lab. CSC 305 2007 page 55