Previous | Next --- Slide 52 of 78
Back to Lecture Thumbnails nrauen

Could this create problems where the perceptive thickness of the line varies based on the slope of the line? jzhanson

Yeah, I remember I was writing a bit of code for naive line drawing between two points on a grid and if the slope of the line was greater than 1, then what would happen would be a very steep, very sparse line.

The solution to this would be to calculate the slope first, and if the absolute value of the slope was greater than 1, then you would have the for loop be on y instead of x (or v, instead of u), so for each value of y between the endpoints, you would calculate and round the x-value for that value of y instead of calculating and rounding the y value for each value of x.

and on line drawing in general https://en.wikipedia.org/wiki/Line_drawing_algorithm keenan

@nrauen You'll get to try it and find out for yourself in A1! ;-). What's on this slide is a simplified version of Bresenham's algorithm, which does a pretty good (but not perfect) job of making lines that look about as "thick" for different slopes. A more sophisticated technique is Wu's algorithm. But modern GPUs don't do anything like this: they actually draw lines as very thin rectangles, and have sophisticated machinery for deciding how much of each pixel is covered by this rectangle. (In fact, for reasons we'll discuss, the rectangle gets broken up into two triangles, which then get drawn by a very good general-purpose triangle drawing algorithm...) keenan

@jzhanson Totally; and thanks for the nice links! You can turn these into URLs, by the way, by using Markdown syntax tpan496

What happens if the line never crosses any diamonds? e.g. inside the empty area of four diamonds