• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1225
  • Last Modified:

Fastest Bresenham algorithm

Hi Experts,

I've read one in a book, there is the most fastest line algorithm founded by two university guys, I don't remember the name but their algorithm is based on improved Bresenham.

So please can someone create a line function which I can simply use based on that fastest improved Bresenham ?

for example a function like this :

function Line(x1, y1, x2, y2: integer)

So I can simply use that on my program thanks alot experts... you are all always great on helping student like me :)
0
comicboy
Asked:
comicboy
  • 2
1 Solution
 
robert_marquardtCommented:
I searched on Google with "improved Bresenham2 and found this http://www.cs.unc.edu/~davemc/Class/136/Lecture9/Lines.html
The source is in C, but conversion should be easy.
0
 
RabsterCommented:
A guy called G. Hoffman has adapted a routine from C based on an algorithm from a Kenny Hoff. This is an improved version of Bresenham's algorithm:

Procedure MakeBLine(p0,q0,p1,q1, pal,col : Byte);
var
  x,y,dx,dy,
  adx,ady,
  ix,iy,du,
  dr,pp,cp,
  i : Integer;
Begin
  dx := p1-p0;
  dy := q1-q0;
  adx := Abs(dx);
  ady := Abs(dy);
  x := p0;
  y := q0;
  cp := 0;
  If dx > 0 then
  ix:= 1
  else
  begin
    ix := -1;
    cp := -1;
  end;
  if dy > 0 then
  iy := 1
  else
  iy := -1;
  If adx >= ady then
  begin
    dr := 2 * ady;
    du := dr-2*adx;
    pp := dr-adx;
    For i := 0 to adx do
    begin
      {SpcSixel(x,y,pal,col);  }
      x:= x + ix;
      If pp > cp then
      begin
        y := y + iy;
        pp := pp + du;
      end
      else
      pp := pp + dr;
    end;
  end
  else
  begin
    dr := 2*adx;
    du := dr -2* ady;
    pp := dr-ady;
    For i := 0 to ady do
    begin
      {SpcSixel(x,y,pal,col); }
      y := y + iy;
      If pp > cp then
      begin
        x := x + ix;
        pp := pp + du;
      end
      else
      pp := pp + dr;
    end;
  end;
end;
0
 
comicboyAuthor Commented:
Well thanks, Robert and Rabster, now my turn to try your code...
0
 
comicboyAuthor Commented:
Sorry for long delay, my Delphi disc broken but now it's up again, I've tried your code...

Excellent!!! it's working as best and as fast as I need

Thanks :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now