Computer graphics--Introduction to linear algorithm of grating graphics

Source: Internet
Author: User

This article is to Zhao Ming teacher "computer graphics" MOOC course part of the Chapter Small Summary.

The straight line is the basis of composing the graph, its algorithm is often called many times, its good or bad directly affects the graph display effect and the speed. Here are some common algorithms for drawing straight lines.

1. DDA algorithm:

This algorithm is based on incremental thinking.

For the oblique truncation of the line: Y=kx+b, consider each x increment 1, there is y[i+1] = Y[i] + K, so that the KX part of the multiplication into a recursive addition.

Since the pixel points are integer coordinates, every y is evaluated to take the whole operation, using the method of adding 0.5 to the integer part: (int) (y[i]+0.5).

However, when |k| > 1 o'clock, as x increments by 1 each time, the grating sampled points are diluted, which may not be enough to approximate the ideal linear line in the mathematical sense.

The efficiency of this algorithm is: floating-point number addition level.

2, Midpoint drawing line method:

This algorithm is still based on incremental thinking.

For the general formula of a straight line: ax+by+c=0, when |k|<1, consider each x increment 1,y[i+1] can only be equal to y[i] or y[i]+1, it depends on the midpoint error item judgment.

  

  

How can I tell if q is above or below m? Put M-point into straight line general type:.

So the basic principle of the midpoint drawing line method is:

  

The next key is to derive the recursion of D to convert the multiplication operation to the addition operation.

When D0<0, that is, to fetch Pu, for the next point:

When D0>0, that is, Pd is taken, for the next point:

  

  

(d you can use 2d amplification to eliminate floating-point arithmetic) by simply judging its symbols.

3, Bresenham algorithm:

  

  

  

  

  

And the algorithm does not depend on the type of linear equation.

  

  

This increases the efficiency to the integer addition level.

  

  

and is not dependent on the form of the linear equation.

Computer graphics--Introduction to linear algorithm of grating graphics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.