Qbasicnews.com
April 04, 2020, 11:47:32 PM
 Pages: [1]
 Author Topic: Path-finding algorythm?  (Read 1470 times)
Mech1031
Na_th_an

Posts: 1536

 « on: June 12, 2004, 04:19:08 PM »

I am currently working on a project and just recently got hung up on a problem.  the problem is :

I have x1,y1 and x2,y2.  I need an algorythym that will find a path leading from x1,y1 to x2,y2.  if and when you do submit your code, can you please comment it or give some explanation to it.  thanks.

-Mech

 Logged

the mind is a beautiful thing, use it and make the world a more beautiful place.
whitetiger0990
__/--\__

Posts: 2964

 « Reply #1 on: June 12, 2004, 05:21:12 PM »

 Logged

[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Mech1031
Na_th_an

Posts: 1536

 « Reply #2 on: June 12, 2004, 09:29:14 PM »

i meant like a strait line.  I want to know the points on the line from x1,y1 to x2,y2.  Example:

1,1 to 4,4 would have the points:

1,1
2,2
3,3
4,4
 Logged

the mind is a beautiful thing, use it and make the world a more beautiful place.
Oz
I hold this place together

Posts: 923

 « Reply #3 on: June 12, 2004, 09:43:43 PM »

Find the length

Code:
length! = SQR(((x2-x1)^2) + ((y2-y1)^2)

then do a loop:

Code:
x = startx - ((x2 - x1) / length!)
y = starty - ((y2 - y1) / length!)

FOR i% = 1 to FIX(length!)
'This has to do w/the slope...
x = x + ((x2 - x1) / length!)
y = y + ((y2 - y1) / length!)
NEXT i%

Just add the code to check if the point that is not-under control is equal to one of teh xy coords in the loop

Alex~
 Logged
zshzn
Member

Posts: 89

 « Reply #4 on: June 15, 2004, 03:27:35 AM »

Many ways to do it, depends on exactly what you want. If you want a line, try

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

Simple. If you want a list of all the points on the line, you can change the coordinates into a line equation in the form y = mx + b

m = (y2-y1) - (x2-x1)
b = -mx + y

for x = x1 to x2
for y = y1 to y2
if y = mx + b then (insert code for listing or saving data)
y = y + 1
end if
end if

Sorry if my code is rusty, I haven't coded in qb in many months.  If that is coded right it will produce a list of all the points on the line.
 Logged
 Pages: [1]