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
(Please reply as soon as possible)
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
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~
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.