Download presentation

Presentation is loading. Please wait.

Published bySavannah Goldwyn Modified over 2 years ago

1
Lecture 4 Graphic Primitives, Line

2
Features of a simple graphic program

3
Introduction How does that program relate to the concepts of pixels and memory mapping that were introduced in Chapter 2? How were the lines drawn? What exactly did the line: g.drawLine(50,50,50,150) do;

4
Drawing straight lines there are two ways of doing it: the brute force approach and the elegant way. We’ll tackle the brute force way first to introduce some ideas and then looks at how it can be refined to produce an efficient (i.e. quick) solution known as Bresenham’s algorithm.

5
Brute Force The equation of a straight line:

6
Brute Force

7

8
Brute Force Implementation

9
Brute Force - Disadvantages Gaps start to appear in the line. Why has this happened? Looking at some values for x and y soon reveals that when m>1, the values for y increase by an amount greater than the increments of x that we are using (i.e. >1). It requires floating point arithmetic which is slow when compared with using integer only arithmetic. An approach which used integers would result in a much quicker algorithm.

10
Brute Force - Disadvantages

11
How to solve the Gap Problem. use the most rapidly changing variable (x or y) as the index to the loop. i.e. When the gradient (m) >1 - use y as the control variable in the loop and make x the subject of the equation: X= (y-c) / m

12
Bresenham’s algorithm

13

14

15

16
Bresenham’s algorithm- Implementation

17

18
Exercises

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google