Bresenham's circle drawing algorithm
- Set initial values of (xc, yc) and (x, y)
- Set decision parameter d to d = 3 – (2 * r).
- call drawCircle(int xc, int yc, int x, int y) function.
- Repeat steps 5 to 8 until x < = y.
- Increment value of x.
- If d < 0, set d = d + (4*x) + 6.
- Else, set d = d + 4 * (x – y) + 10 and decrement y by 1.
A circle is a geometric figure which is round, and can be divided into 360 degrees. 8-Way symmetry: Any circle follows 8-way symmetry. This means that for every point (x,y) 8 points can be plotted. These (x,y), (y,x), (-y,x), (-x,y), (-x,-y), (-y,-x), (y,-x), (x,-y).
Here is the code for drawing circle with pixels: It uses the formula xend = x + r cos(angle) and yend = y + r sin(angle). One way to do this would be to test, for each point in the rectangle, whether or not the distance from that pixel to the center of the square is less than the intended radius of the circle.
Midpoint ellipse algorithm is a method for drawing ellipses in computer graphics. This method is modified from Bresenham's algorithm. Let us consider one quarter of an ellipse. The curve is divided into two regions. In region I, the slope on the curve is greater than –1 while in region II less than –1.
Circle is an eight-way symmetric figure. The shape of circle is the same in all quadrants. In each quadrant, there are two octants. If the calculation of the point of one octant is done, then the other seven points can be calculated easily by using the concept of eight-way symmetry.
Flood fill, also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array.
Comparison Chart
| Basis for comparison | DDA Algorithm | Bresenham Algorithm |
|---|
| Speed | Comparatively less | More |
| Operations used | Multiplication and division | Additions and subtraction |
| Arithmetic computation values | Floating point | Integer type |
| Precision | Low | High |
Circle drawing using DDA Algorithm. Takes the circle parameters (centre and radius)from the user to plot the desired circle. The program calculates each successive pixel that lies on the circle using DDA Algorithm.
A line drawing algorithm is a graphical algorithm for approximating a line segment on discrete graphical media. On discrete media, such as pixel-based displays and printers, line drawing requires such an approximation (in nontrivial cases). Basic algorithms rasterize lines in one color.
The Cohen–Sutherland algorithm is a computer-graphics algorithm used for line clipping. The algorithm divides a two-dimensional space into 9 regions and then efficiently determines the lines and portions of lines that are visible in the central region of interest (the viewport).
Code to draw a circle without using graphics in c++
- #include <iostream>
- #include <math.h>
- using namespace std;
- int pth (int x,int y) {
- return sqrt (pow(x,2)+pow(y,2));
- }
- int main ( ) {
- int c=0;
Midpoint ellipse drawing algorithm. Mid-point Ellipse algorithm is used to draw an ellipse in computer graphics. Each point(x, y) is then projected into other three quadrants (-x, y), (x, -y), (-x, -y) i.e. it uses 4-way symmetry.
Bresenham's Line Generation
The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates.Boundary-fill Algorithm
This is an area filling algorithm. This is used where we have to do an interactive painting in computer graphics, where interior points are easily selected. If we have a specified boundary in a single color, then the fill algorithm proceeds pixel by pixel until the boundary color is encountered.Clipping, in the context of computer graphics, is a method to selectively enable or disable rendering operations within a defined region of interest. Mathematically, clipping can be described using the terminology of constructive geometry. Clip regions are commonly specified to improve render performance.
Boundary Fill Algorithm. Introduction : Boundary Fill Algorithm starts at a pixel inside the polygon to be filled and paints the interior proceeding outwards towards the boundary. This algorithm works only if the color with which the region has to be filled and the color of the boundary of the region are different.
? The active edge table will now contain ordered edges of those edges that are being filled as such: 62. Filling the Polygon ? Filling the polygon involves deciding whether or not to draw pixels, adding to and removing edges from the active edge table, and updating x values for the next scan-line.
DDA Advantages of DDA algorithm; a) Faster than the direct use of line equation and it does not need any floating point multiplication. Disadvantages of DDA algorithm; a) Floating point Addition is still needed b) Precession loss is possible because of rounding of the points. c) The algorithm is orientation dependent.