Line drawing routine

Line drawing routine

Post by Gary Kabitz » Fri, 28 Jul 1995 04:00:00



Could someone provide me with  the algorithm for drawing lines.
I have a LCD screen that is 128 x 56 and I wrote a put_pixel()
routine, but I need a line drawing routine. The version of C that I
have doesn't support floating point math, only integer math.

Thanks Gary

 
 
 

Line drawing routine

Post by Paul Vermette [NiD/Bi » Sat, 29 Jul 1995 04:00:00


: Could someone provide me with  the algorithm for drawing lines.
: I have a LCD screen that is 128 x 56 and I wrote a put_pixel()
: routine, but I need a line drawing routine. The version of C that I
: have doesn't support floating point math, only integer math.

You could use a simulated floating point substitute like Fixedpoint Math
so you could emulate floating point math.

I used Fixed point math because it is much faster then using Floating point.

: Thanks Gary

--
                   '''
                  (o o)
  .---------oOOO---(_)------------------.
  |       Paul Vermette [NiD/BiM]       |

  |    B O D i E S  i N  M o T i O N    |
  `----------------------oOOO-----------'
                 |__|__|
                  || ||
                 ooO Ooo

 
 
 

Line drawing routine

Post by 6502 (Andrea Griffi » Sat, 29 Jul 1995 04:00:00



says...

Quote:

>Could someone provide me with  the algorithm for drawing lines.
>I have a LCD screen that is 128 x 56 and I wrote a put_pixel()
>routine, but I need a line drawing routine. The version of C that I
>have doesn't support floating point math, only integer math.

>Thanks Gary

Check out this...

void Line(int x0,int y0,int x1,int y1,int c)
{ int i,dx,ix,dy,iy,m,cx,cy;
  if (x0<x1) { dx=x1-x0; ix=1; }
        else { dx=x0-x1; ix=-1; }
  if (y0<y1) { dy=y1-y0; iy=1; }
        else { dy=y0-y1; iy=-1; }
  if (dx>dy) m=dx; else m=dy;
  cx=cy=m>>1;
  for (i=0; i<m; i++)
    { PutPixel(x0,y0,c);
      if ((cx+=dx)>=m) { cx-=m; x0+=ix; }
      if ((cy+=dy)>=m) { cy-=m; y0+=iy; }
    }

Quote:}

This is my personal version of an integer arithmetic DDA (as you should
see there is only a shift and additions ... :-) )
Warning: this algo don't draw the last point because I like that; if you
         are wrong (i.e. don't agree with me) change the for with a "<=m" ;)

I hope this helps


 
 
 

Line drawing routine

Post by Tom Cond » Sat, 29 Jul 1995 04:00:00


: Could someone provide me with  the algorithm for drawing lines.
: I have a LCD screen that is 128 x 56 and I wrote a put_pixel()
: routine, but I need a line drawing routine. The version of C that I
: have doesn't support floating point math, only integer math.

Check out Breshenham's Line Algorithm. It uses only integer math. Any
graphics book worth its salt should discuss this. Best of luck!

--
Tom Conder

 
 
 

Line drawing routine

Post by Jeff Huyl » Sat, 29 Jul 1995 04:00:00


: Could someone provide me with  the algorithm for drawing lines.
: I have a LCD screen that is 128 x 56 and I wrote a put_pixel()
: routine, but I need a line drawing routine. The version of C that I
: have doesn't support floating point math, only integer math.

: Thanks Gary

Hi!
  Gary, Bresenham's line algorithm is designed to use integers for
speed... Get the Graphics FAQ and have a look...

Good Luck & Cheers
Jeff H

 
 
 

Line drawing routine

Post by Noah L. Gibb » Fri, 04 Aug 1995 04:00:00


Excerpts from netnews.comp.graphics.algorithms: 3-Aug-95 Re: Line

Quote:> But I have some more question about Bresenhams's algorithm.
> If line width is not 1 pixel, what is the best way to drawing
> line?( minimum arithmatic operation )

> Do I draw same line twice or more to change x, y value?
> Or any other good Method?

    Foley, Van Dam, et al, have a good discussion on this.  Basically, it
depends on what you mean by a 'thicker' line.  You can do horizontal or
vertical pixel duplication (in columns or rows) or one of several other
tricks.  For 'actual' thick lines, you have to decide things like what you
want the ends to look like.

                                Noah Gibbs

Still the Earth spins upon its axis.  Long live the revolution!

      My comments and those of my closest friend(s)
or pet(s) do not necessarily represent the opinions of
anyone other than an electronic monk or a random
Markov-chain-based text-processing utility (Babble).

 
 
 

Line drawing routine

Post by Donggyu Pa » Fri, 04 Aug 1995 04:00:00


: Check out Breshenham's Line Algorithm. It uses only integer math. Any
: graphics book worth its salt should discuss this. Best of luck!

I think Bresenham's Line Algorithm is the best way to draw
line in digital computer.

But I have some more question about Bresenhams's algorithm.
If line width is not 1 pixel, what is the best way to drawing
line?( minimum arithmatic operation )

Do I draw same line twice or more to change x, y value?
Or any other good Method?

Best of luck!

--
On my Information :::

 http://pearl.cs.pusan.ac.kr/~dongupak/dgpark.html
---------------------------------------------------------------