The Bresenham algorithm is an incremental scan conversion algorithm.
We can draw various types of lines using Bresenham's Line Algorithm such as:
1. SOLID LINE
2. DOTTED LINE
3. DASHED LINE
4. THICK LINE
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.
For example, from below figure, from position (2, 3) you need to choose between (3, 3) and (3, 4). You would like the point that is closer to the original line.
Image source: Tutorialspoint |
We can draw various types of lines using Bresenham's Line Algorithm such as:
1. SOLID LINE
2. DOTTED LINE
3. DASHED LINE
4. THICK LINE
Below is a code to draw a Solid Line using Bresenham's Line Algorithm.
Code:
If you can't see the code, then Enable JavaScript in you browser
Output:
Solid Line |
Note: Just copy the files "CGA.bgi" & "EGAVGA.bgi" from bgi folder to bin. So, if you have copied these 2 files then you can skip writing "C:\\tc\\bgi" in initgraph with just ""(2 double quotes).
Comments
Post a Comment