Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8 Shear and Line Drawing Algorithms

Similar presentations


Presentation on theme: "Lecture 8 Shear and Line Drawing Algorithms"— Presentation transcript:

1 Lecture 8 Shear and Line Drawing Algorithms
Computer Graphics Lecture 8 Shear and Line Drawing Algorithms

2 Shear It is a transformation that distorts the shape of an object.
It means “pulling or elongating” a graphical object to right, left, up or down. It can be done along x-axis or along y-axis. Shear along x-axis x’ shx x y’ = y x’ = x + shx.y y’ = y

3 shx can be assigned any real number.
y y x x Positive values of shx shift the coordinate positions towards right and negative values shift them to left.

4 Example Shear the following object along x-axis, shx = 2
(0,1) (1,1) (2,1) (3,1) (0,0) (1,0) (0,0) (1,0)

5 For point (0,1) x’ = x + shx.y x’ = = 2 (0,1) = (2,1) For point (1,1) x’ = = 3 => (1,1) = (3,1)

6 For shearing in x-direction relative to other reference lines, that is, shifting coordinate positions by an amount equal to its distance from reference line y = yref x’ = x + shx (y – yref) , (0,1) (1,1) (1,1) (2,1) (0,0) (1,0) (1/2, 0) (3/2,0) yref -1

7 Shear in y-direction In this case x’ = x y’ = y + shy (x – xref)

8 Line Drawing Algorithms
In random scan systems, a straight line can be drawn from one endpoint to other by using line drawing commands from frame buffer. In raster scan systems the color intensities for a line are stored in the frame buffer and are read from the frame buffer. In order to draw lines, we use the equation of straight line which is given as y = mx + b m= slope of line (that is, how steep line is) b = y intercept, y= how far up, x = how far along

9 y m b x y (x2,y2) y1 (x1,y1) x x2

10 The slope m of a line is equal to the change in y divided by change in x, that is:
m = change in x = y2 - y1 change in y x2 - x1 m = δy δx => δy = m . δx => δx = δy m

11 Positive Slope : On increasing x if y also increases then slope is positive.
Negative Slope : On increasing x if y decreases then the slope is negative. y y m m positive slope negative slope x x

12 Digital Differential Analyzer (DDA)
It is a scan conversion line drawing algorithm. It is based on calculating either δy or δx using equations δy = m . δx and δx = δy / m In this algorithm, the line is sampled at unit intervals in one coordinate and the integer nearest to the line path for other coordinate are determined. We will consider a line with positive slope.

13 Line with positive slope

14 Case 1: slope is less than or equal to 1 (m<=1)
In this case, the line is sampled at unit x intervals and then the y-values are computed. δy = m . δx δy = m (δx = 1) => yk+1 – yk = m => yk+1 = yk + m [This means the next point in x is +1 and next point in y is +m]

15 Case 2: slope is greater than 1 (m > 1)
In this case the roles of x and y are exchanged. Now number of steps is determined by y (δy = 1) and the line is sampled at unit y intervals and values of x are computed. δx = δy / m δ x = 1 / m (δy = 1) xk+1 – xk = 1 / m xk+1 = xk + 1 / m

16 DDA Algorithm Input x1, y1, x2, y2 dx = x2 – x1 dy = y2 – y1 If dx > dy steps = dx Else steps = dy xincrement = dx / steps yincrement = dy / steps x = x1 y = y1 for (i=0; i< steps; i++) x = x + xincrement y = y + yincrement


Download ppt "Lecture 8 Shear and Line Drawing Algorithms"

Similar presentations


Ads by Google