Line Drawing Algorithm
a line segment in a scene is defined by the coordinate position of its ends.
to display a first-line segment on a raster monitor, the graphics system
must The
Two ends are projected to the integer screen coordinates, and the nearest pixel position of the straight path from the two ends is determined .
next , the color value The pixel coordinates of the loaded human frame cache . The video controller reads the written color values from the frame cache and draws the screen pixels . This processdigitize a segment as a discrete set of integer positions. In general, these locations are approximate to the actual line path. For example, calculate thethe line position (10.48, 20.51) is converted to the pixel position (10, 21). Coordinate values are rounded to integers, causing all lines except horizontal and verticalThe step effect of the segment (
"Zigzag "), shown in 3.5. The ladder phenomenon peculiar to grating segments is particularly easy to see in low resolution systemsand can be improved in high-resolution systems. The more efficient technique for smoothing raster segments is based on the pixels on the adjustment line pathstrength.
linear equation
The pixel position of a straight path can be determined based on the geometric characteristics of the line. The Cartesian slope intercept equation of a straight line is
The algorithm for displaying the line is based on the linear equation (3.1) and the calculation method given by equation (3.2) and equation (3.3).
for any x increment &x given along a line, the corresponding y-increment &y can be computed from the equation (3.2):
Similarly, you can derive an X increment &x that corresponds to the specified &y:
these equations form the basis for determining the deflection voltage in an analog device, such as a vector scanning system, which may cause minor deflectionvoltage change. For |m| with absolute slope < 1 line, can be set to a smaller horizontal deflection voltage &x, corresponding to the verticalThe direct deflection voltage can be set using the &y calculated by the equation (3.4), and for a line with a slope value of |m|> 1, set aa smaller vertical deflection voltage &y, the corresponding horizontal deflection voltage is set by the &x calculated by the equation (3.5); for Slopem = 1 of the line, &x = &y,
so the horizontal deflection and the vertical deflection voltage are equal . in each case, the specified end can be a smooth line with a slope of M is generated between the points .
in a raster system, the horizontal and vertical steps are limited by the spacing of pixels by drawing lines in pixels . that is, the line must be sampled at discrete locations, and the pixels closest to the line are determined at each sampling location. Figure 3.7 shows the scanning conversion process of a line and the location of a discrete sampling point along the x-axis.
Computer Graphics (ii) output graphic element _3_ line algorithm _1_ linear equation