# Distance Formula

``` BBS: Inland Empire Archive
Date: 06-22-92 (06:22)             Number: 1212
From: RICHARD VANNOY               Refer#: NONE
To: ROBERT CHURCH                 Recvd: NO
Subj: Distance Formula               Conf: (2) Quik_Bas```
```RC>In short, How can I find all of the points between two points on
RC>a grid?

So the two points are  20, 30, 70, 130
x1  y1  x2  y2

What you're trying to lay out is called the ratio between
the change in x (delta x) and the change in y (delta y).

The ratio is (x2 - x1) / (y2 - y1)
= (70 - 20) / (130 - 30)
= 50 / 100
= 1/2 or .5
in other words for every unit x changes, y changes 2.
(You can do (x1-x2)/(y1-y2) and the minuses and plusses
will work right as long as you are consistant.
So to compute the x,y points between, you do...

ratio = (x2-x1)/(y2-y1)
startx=x1
starty=y1

FOR i = 1 to x2 -x1
x = startx + i
y = INT((starty+i)*ratio+.5)
'.5 rounds y to the nearest whole number
PRINT x,y
NEXT i

That will (if I got my math right), will give you the
closest approximate (because you round off y) location of
all the x,y intersections.

Your "i" increment can also be set to just about any value
you want.
___
> MegaMail 2.1b #0:Real programmers use: COPY CON PROGRAM.EXE

--- Maximus 2.00
* Origin: D.J.M.BBS (1:202/307)
``` Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET