[School_ĐHMT – Algorithm] General Principles of drawing straight lines

Read more
1. DDA algorithm to draw the line
2. Algorithm Breshenham draw straight lines
3. Midpoint algorithm to draw the line

draw the line

Give 2 endpoints M1(x1, y1), M2(x2, y2) and paint C.
I already know the equation line through 2 M1 and M2 are points:

\\  \frac{x-x1}{y-y1} = \frac{x2-x1}{y2-y1} \\ \\  \Leftrightarrow y = \frac{y2-y1}{x2-x1}(x-x1) + y1\\ \\  \Leftrightarrow y = \frac{y2-y1}{x2-x1}x + y1 - \frac{y2-y1}{x2-x1}x1

Set m = \frac{y2-y1}{x2-x1}

I have y = mx + b with (b = y1- mx1) (1)

Where m is called the steepness or slope of the line, b sure segment called axis Oy.

From equation (1) we can build M1M2 drawing straight lines when the x variable intervals Δx then calculate the corresponding variable value of Δy = m.Δx. or you can do the reverse when the variable y and x to y. Due to the smallest unit of the screen is 1 pixel should we take Δx = 1 (Δx = -1) or Δy = 1 (Δy = -1). The x or y to change depending on the shape of the line to be able to draw the line close to best practice.

If |dx| > |two| then the variable x and y in terms of x.
If |dx| < |two| then the variable y and x to y.

Because the screen is the pixel to draw the line segment is the material of the coordinates as close to reality from which to draw the corresponding pixel.

So the general principle is to draw straight lines: For an element x and y coordinates of Natural variation in unit values ​​and principles of the remaining components is as close to the geographical coordinates of most.