Computer Graphics - linear scan conversion

First, the basic idea of ​​generating linear

The image of the light spot pattern is different brightness of different colors on the screen (pixels). Generating an object on the screen of the raster display, a frame corresponding substantially to fill the buffer register unit data.

So: When the pair of linear rasterization, only a set of pixels to determine the best approximation to the straight line in the lattice given a finite number of pixels in the display, the straight line represented by these pixels.

So: The main line is generated: quickly identify the closest grid points from a straight line, with the pixels corresponding to grid points of the straight line represented.

If we use the slope-intercept equation to represent a straight line, will use one multiplication and one addition, multiplication in the bottom of the computer is time-consuming, so what can be improved?

Multiplication becomes addition to!

Is a linear set of pixels, the ultimate goal of generating algorithm is to find a more accurate approximation of the pixel point of the line.
Therefore, to determine for each point on the line, so as: m <1, from the starting point xs, xs + 1, xs + 2, xs + 3 ...... to each point xe of (xi, yi), the need determining the value of the corresponding pixel.
Therefore, each of (xi, yi) i.e. exact value, must find the corresponding pixel value thereof (xi, yi, r), i.e., it is closest to the exact value of the integer value, the easiest - rounding.
Suppose (xi, yi) has determined its corresponding integer pixel points, then the following rules will find i.e., determining the next point (xi + 1, yi + 1 ) of the corresponding pixel dots.
Corresponds to the case where m <case 1, xi + 1 = xi + 1 , i.e., yi + 1 is determined, i.e. determined criteria above said, that given a determination formula to determine the selection yi + 1 by determining the formula.
In order to facilitate the calculation formula is determined to be a more convenient way to calculate. It is determined that the formula may also be determined by the recursive formula.

Second, the basic incremental algorithm (DDA)

The basic algorithm is also called digital differential incremental algorithm (Digital Differential Analyzer)

1, the basic idea:    

Rounding method for solving the best approximation; use of differential on the idea that the coordinates of each point can change a gain results from the previous coordinates.

2, the line represents:   

Provided line starting coordinates (xs, ys), end point coordinates (xe, ye),

So that [Delta] x = xe XS, YS-YE = Ay , then the parameters of the linear equation

The parameters of the interval [0,1] is divided into n aliquots, i.e. each increment of t  Δt = 1 / n

3, a method to improve the speed

The coordinates of each point can be obtained by a previous incremental change of the coordinate.
Set (xi, yi) is a point on the straight line obtained in step i, the first straight line is a point i + 1 (+ XI. 1, Yi +. 1) , wherein


 When Δx> Δy> 0, i.e., the slope is less than 1, the x-direction should be incremented by 1, up to an increase in Y direction, the time zone [Delta] t = 1 / [Delta] x ;
Similarly, if Δy> Δx> 0, the slope is greater than 1 , take [Delta] t =. 1 / Ay , the

4, linear DDA algorithm program

void DDA (G Graphics, int X1, int X2, int Y1, int Y2) 
{ int K; // should take steps 
  a float X, Y, DX, Dy; // increment of change 
  k = Math.abs (x2 - X1);
   IF (the Math.abs (Y2-Y1)> K) 
  K = the Math.abs (Y2 - Y1); 
  DX = ( a float ) (X1-X2) / K; 
  Dy = ( a float ) (Y1-Y2 ) / K; X = ( a float ) X1; 
  Y = ( a float ) Y1; 
   for ( int i = 0; i <k ; i++ )
  {  
     g.drawLine((int)(x+.5f), (int)(y+.5f), (int)(x+.5f),   (int)(y+.5f));
     x = x+dx;
     y = y+dy;
  }
}

 

Guess you like

Origin www.cnblogs.com/wkfvawl/p/11621653.html