# Bresenham algorithm to draw filled circle and SDL code implementation

Source: Internet
Author: User

Drawing circles is a very important requirement in the operation of computer graphics. The ordinary circle algorithm requires a large number of floating-point numbers to participate in the operation, and it is well known that the operation speed of floating-point numbers is much lower than shaping number. And the final screen of the pixels mapped to the coordinates are shaping, it is not possible to be a continuous line, so the floating-point arithmetic is actually a waste. The Bresenham algorithm described below is designed according to the above principles. The algorithm is applied to the drawing of straight line, but because of the eight symmetry of the circle, the algorithm is also applicable to the drawing of the circle (curve graph).

The algorithm is mainly based on the principle of finding a 1/8 arc, using a fast incremental calculation to find the next point. At the same time, the eight-point symmetry of the circle is used to find 8 points (including the point) for drawing.

Here is an example of the SDL Code implementation drewdemo.zip (Ubuntu 12.04LTS compiled, win users need to add the library Libmingw32 when connected). The following is the time the program runs. The program runs for a period of time (that is, the time to draw Sdl_texture) is 18ms on the E3 v1230+hd6770 pc.

Bresenham is really a fast algorithm, especially on a single-chip microcomputer (MPU) with no hardware multiplication (multiplied by a number of 2 as the base) and a divider, and the efficiency will be an order of magnitude faster than the floating-point simulation drawing method. So this is a very easy algorithm for hardware implementation. However, the algorithm is not omnipotent. As can be seen, the drawing of the circle is more rough, not in line with the human fastidious aesthetic. And in the face of increasingly powerful performance, algorithm optimization seems to have some cumbersome (need more effort to check bugs, think of code), so there is no special needs (dense graphics or embedded drawings mentioned above) No need to write this algorithm.

Bresenham algorithm to draw filled circle and SDL code implementation

Related Keywords:

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.