Line (TP7)
Author Message
Line (TP7)

Hello

I want to find all the X.Y in a line:

if i make a line:
Line(x1,y1,x2,y2)

Then i want to know the X.Y between x1,y1 and x2,y2.

Is there a way to calculate that?

/Mikael

Mon, 07 Nov 2005 19:13:32 GMT
Line (TP7)

Quote:

> > Then i want to know the X.Y between x1,y1 and x2,y2.

> > Is there a way to calculate that?

> Yepp.

> Simple way:
> y = mx + n

> with: m = delta_y / delta_x = abs(y2 - y1) / abs(x2 - x1)
> and:  n = y - m * x = y1 - m * x1

> calculating:

> for x := x1 to x2 do y := m * x + n;

> What do kids learn in school today? It's basic math.

> For a fast way to calculate x,y - for example for a line drawing procedure
> - google for Bresenhams Algorithm.

> HTH Matt

There are a couple problems with this simple answer.

Doesn't work when x1=x2.
(I'll leave it to the reader to transpose the function and do things in
terms of y).

if  | x2 - x1 | < | y2 - y1 |  you will skip some points.

You'll get closer if you iterate over the greater gap and round the result.
Especially if you are trying to grab the individual integer-valued points
along
a rasterized line.

Rufus

Rufus V. Smith
Software/Hardware Design (esp. Automation)
Recently available for full, part-time, or contract work.
Looking for work?  Check my Job Search Links.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

Mon, 07 Nov 2005 20:44:31 GMT
Line (TP7)

Quote:

> I want to find all the X.Y in a line:
>       Line(x1,y1,x2,y2)

All? There in a infinite number of points in a line. But what you
probably are looking for is a parametric presentation of a line
between two points. Why do you need it since there already is a
drawing routine for the very task? Making a dotted line, perhaps?

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa

Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html

Tue, 08 Nov 2005 04:27:21 GMT
Line (TP7)
Hello

I want to be able to klik anywhere on the line and show a name for that
line.
I have saved the start point and, end point with a name.

/Mikael

Quote:

> > I want to find all the X.Y in a line:
> >       Line(x1,y1,x2,y2)

> All? There in a infinite number of points in a line. But what you
> probably are looking for is a parametric presentation of a line
> between two points. Why do you need it since there already is a
> drawing routine for the very task? Making a dotted line, perhaps?

>    All the best, Timo

> --
> Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
> Department of Accounting and Business Finance  ; University of Vaasa

> Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html

Tue, 08 Nov 2005 21:57:37 GMT
Line (TP7)

Quote:
>I want to be able to klik anywhere on the line and show a name for that
>line.
>I have saved the start point and, end point with a name.

As soon as you have multiple lines, you'll have to disambiguate multiple
possible lines. It's also very unlikely that the user exactly hits an point on
a line, and what when multiple lines cross that point?

As long as you have straight lines, you can compute the distance of the clicked
point to every line, and then choose the line with the shortest distance. Timo
certainly will be able to tell you the according formulas :-)

DoDi

Thu, 10 Nov 2005 14:28:01 GMT
Line (TP7)
Hello

Thanks for all the answers. Im going with the bresenham algorithm.
Its true that its not easy to klik the point, but i can maybe solve this
with several lines in parallel.

Regards
Mikael

Sat, 19 Nov 2005 17:42:28 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages