Skip to main content

Bresenham's Line Algorithm (DASHED LINE)

Bresenham's Line Algorithm (DASHED LINE)

The Bresenham algorithm is an 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.

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 Dashed Line using Bresenham's Line Algorithm.


Code:


If you can't see the code, then Enable JavaScript in you browser


Output:


Dashed 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

  1. in loop for(j=0;j<n;j++) what is n from? it is not initialized before...

    ReplyDelete
    Replies
    1. ando also in if(d==1) what is d, it not initialized anywhere

      Delete
  2. Thank You and I have a tremendous present: Who Repairs House Windows Near Me home remodeling contractors

    ReplyDelete

Post a Comment

Popular posts from this blog

Midpoint Ellipse Algorithm

Midpoint Ellipse Algorithm                  Midpoint ellipse algorithm is a method for drawing ellipses in computer graphics. This method is modified from Bresenham’s algorithm so it is sometimes known as Bresenham's circle algorithm.

Bresenham's Line Algorithm (THICK LINE)

Bresenham's Line Algorithm (THICK LINE) Bresenham's Line Algorithm (THICK LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Flood Fill Algorithm

Flood Fill Algorithm Flood Fill is a seed fill algorithm similar to Boundary Fill algorithm but sometimes when it is required to fill in an area that is not defined within a single color boundary we use flood fill instead of boundary fill.



Bestseller's in Electronics only at Amazon Best Selling Products on Amazon