Download presentation

Presentation is loading. Please wait.

Published bySavannah Goldwyn Modified over 3 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

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

16
Bresenham’s algorithm- Implementation

18
Exercises

Similar presentations

OK

Introduction to Computer Programming in C www.ccsa126.wikispaces.com.

Introduction to Computer Programming in C www.ccsa126.wikispaces.com.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on circles for class 9 free download Ppt on film industry bollywood dance Download ppt on types of operating system Ppt on the art of war Ppt on acid-base titration simulation Ppt on astronomy and astrophysics impact Ppt on united nations organization Ppt on types of birds Ppt on 600 mw generator Ppt on energy cogeneration plant