# Line drawing algorithm Tan Xianzhe 2017152038 Line drawing

• Slides: 24

Line drawing algorithm • 1. What is line drawing algorithm? • 2. Classic line drawing algorithm. • 3. Others. 2

What is line drawing algorithm 3

What is line drawing algorithm • Computer display precision is limited, in general, it is impossible to really show a continuous line, so we use a series of discrete points(pixels) to perform the line approximately. 4

What is line drawing algorithm • • • dx = x 2 - x 1 dy = y 2 - y 1 for x from x 1 to x 2 { y = y 1 + dy * (x - x 1) / dx plot(x, y)} • if dx<dy (i. e. , slope greater than 1), the line becomes quite sparse with lots of gaps, and in the limiting case of dx=0, only a single point is plotted. 5

What is line drawing algorithm • Simple line drawing algorithms are inefficient and therefore slow on digital computers. Its inefficiencies stem from the number of operations and the use of floating point calculations. 6

What is line drawing algorithm 7

Bresenham's line algorithm • Bresenham's line algorithm is a line drawing algorithm that determines the points of an n-dimensional raster that should be selected in order to form a close approximation to a straight line between two points. • It is commonly used to draw line primitives in a bitmap image (e. g. on a computer screen), as it uses only integer addition, subtraction and bit shifting, all of which are very cheap operations in standard computer architectures. 8

Bresenham's line algorithm • The algorithm is really just looking at a line with a slope between 0 and 1, which is an Angle between 0 and 45 degrees. As long as the drawing method of this kind of line is solved, the drawing of other Angle lines can all be realized through simple coordinate transformation. 9

Bresenham's line algorithm The Bresenham straight line algorithm is used to describe the straight line determined by two points. It will work out the closest point of a line segment on an n-dimensional raster. This algorithm only use relatively fast integer addition, subtraction and shift of bits. 10

Bresenham's line algorithm • Bresenham's core idea: given the current point coordinates (x, y), since the slope of the line is already specified to be less than or equal to 1, the next point coordinates can only be (x+1, y) or (x+1, y+1). So we just have to figure out which one is closer to the line. 11

Bresenham's line algorithm If the midpoint is below or on the line, then the next point is（x+1，y） If the midpoint is above the line, then the next point is（x+1，y+1） 12

Bresenham's line algorithm 13

Bresenham's line algorithm 14

Others • Xiaolin Wu's line algorithm • Digital differential analyzer (graphics algorithm) • Run-Length 15

Bresenham's circle drawing algorithm • The Bresenham's circle drawing algorithm, also known as the midpoint circle drawing algorithm, is the same as the Bresenham's line algorithm. • Its basic method is to use discriminant variables to judge and select the nearest pixel points, and the numerical value of the discriminant variables can be calculated only by some addition, subtraction and shift operations. 16

Bresenham's circle drawing algorithm All we need to know is the coordinates of one point (x, y) on the circle , and using octuple symmetry, we immediately have the coordinates of the other seven symmetric points. 17

Bresenham's circle drawing algorithm 18

Bresenham's circle drawing algorithm 19

Bresenham's line algorithm 20

Bresenham's line algorithm 21

Bresenham's line algorithm 22

Reference • CSDN • wikipedia • "The Bresenham Line-Drawing Algorithm", by Colin Flanagan https: //www. cs. helsinki. fi/group/goa/mallinnus/lines/brese nh. html 23