Searching \ for '[OT]: Drawing diagonal lines' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=drawing+diagonal
Search entire site for: 'Drawing diagonal lines'.

Exact match. Not showing close matches.
PICList Thread
'[OT]: Drawing diagonal lines'
2000\06\03@203229 by Andrew Seddon

picon face
Hi.

What I need to do is draw a line from one point on the screen to another.
Chances are it will be diagonal, eg. (10,20) to (100,100). Now this would be
easy if it wasn`t for the fact that the line will have 832 pixels in it that
need plotting along the line.

I am using VB and any help would really be appreciated.

Thanks in advance.

2000\06\03@211304 by Dan Michaels

flavicon
face
At 01:28 PM 4/3/00 +0100, you wrote:
>Hi.
>
>What I need to do is draw a line from one point on the screen to another.
>Chances are it will be diagonal, eg. (10,20) to (100,100). Now this would be
>easy if it wasn`t for the fact that the line will have 832 pixels in it that
>need plotting along the line.
>
>I am using VB and any help would really be appreciated.
>
>Thanks in advance.
>

Bresenham's Algorithm - any book on computer graphics.

2000\06\03@212140 by William Chops Westfield

face picon face
Surely VB already has graphics routines?

BillW

2000\06\03@213213 by James Korman

flavicon
face
William Chops Westfield wrote:
>
> Surely VB already has graphics routines?
>
> BillW
I was going to answer at first but the april date
had me wondering...

  Line(x1,y1)-(x2,y2)

will do the job in VB

Jim Korman

2000\06\04@132347 by Andrew Seddon
picon face
<x-flowed>>I was going to answer at first but the april date
>had me wondering...
>
>    Line(x1,y1)-(x2,y2)
>
>will do the job in VB
>
>Jim Korman

Thanks but unfortunately the line is composed of different black and white
pixels and you can only draw a line in one colour using VB, as far as I am
aware.

BTW to the admins, sorry about the date I have corrected it now.

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

</x-flowed>

2000\06\04@223143 by Damon Hopkins

flavicon
face
Andrew Seddon wrote:
>
> Hi.
>
> What I need to do is draw a line from one point on the screen to another.
> Chances are it will be diagonal, eg. (10,20) to (100,100). Now this would be
> easy if it wasn`t for the fact that the line will have 832 pixels in it that
> need plotting along the line.
>
> I am using VB and any help would really be appreciated.
>
> Thanks in advance.

if the lines are straight you can figure out the slope and calculate
each y for a given x.. of vice versa..
               Damon Hopkins

2000\06\05@023123 by Dr. Imre Bartfai

flavicon
face
Hi,

use the DDA algorithm!

Regards,
Imre


On Mon, 3 Apr 2000, Andrew Seddon wrote:

{Quote hidden}

2000\06\05@055705 by Michael Rigby-Jones

flavicon
face
Why can't you use the "Line" method in VB?  Is there a reason you need to
roll your own line algorithm?

Mike

> {Original Message removed}

2000\06\05@060538 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

You can use the DrawStyle to achieve various different line styles such as
dashes, dots etc.  Could you use that perhaps?

Mike

2000\06\05@080358 by M. Adam Davis

flavicon
face
You can use the line command, with a pattern, to get the alternating black and
white you need.  If you need the line to consist of more colors than that, then
you'll need to write a line algorithm.

I did this a -long- time ago, and the general idea of thi particular method was:

Find which difference was greater, x1-x2 or y1-y2.
(if the same, it doesn't matter which you pick as the lesser or greater)
(We'll say in this example that x1-x2 is greater)
Slope = (y1-y2)/(x1-x2)  (Lesser difference over greater difference)
for count = x1 to x2  (this is the greater distance to travel, by going on
                      it, we won't miss any pixels on the line, nor draw
                      any extra pixels.)
  putxy count, (count * slope)
next count

That should do it.  I didn't test it here (I don't have the original program)
but if you have any problems, email me about it.  Please note that it will be
*very* slow compared to any built in line routines.  If you need faster lines,
consider using C and write a DLL or OCX to do the work for you.

-Adam



Andrew Seddon wrote:
{Quote hidden}

2000\06\05@120935 by Michael Rigby-Jones

flavicon
face
Why can't you use the "Line" method in VB?  Is there a reason you need to
roll your own line algorithm?

Mike

> {Original Message removed}

2000\06\05@184120 by paulb

flavicon
face
M. Adam Davis wrote:

> I did this a -long- time ago, and the general idea of the particular
> method was:

> for count = x1 to x2  (this is the greater distance to travel, by
> going on it, we won't miss any pixels on the line, nor draw any extra
> pixels.)

 Ah, but there's the trick.  If you use only this method, you get a
somewhat scruffy line.  Thus:

        XXX
           XXX
              XXX
                 XXX

 You actually WANT to draw the "extra" pixels.

 As I recall it (it's in a book I have here somewhere, rather old but
the fact of the matter is there is almost nothing new, no grand
discoveries in recent times - like compression techniques, there are NO
new ones being discovered!), the Bresenham (if that is the one)
algorithm determines at each point whether to make an X or a Y step but
not both, resulting in a much more satisfactory line thus:

        XXXX
           XXXX
              XXXX
                 XXXX
--
 Cheers,
       Paul B.

2000\06\07@190929 by Andrew Seddon

picon face
> you'll need to write a line algorithm.
>
> I did this a -long- time ago, and the general idea of thi particular
method was:
{Quote hidden}

program)
> but if you have any problems, email me about it.  Please note that it will
be
> *very* slow compared to any built in line routines.  If you need faster
lines,
> consider using C and write a DLL or OCX to do the work for you.
>
> -Adam

Thanks. I tried it and it worked straight away.

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...