SRL Archive - RS3 Outdated / Broken Scripts

Distance Finder


TViYH

2008-03-05 16:39:35

I need a script that finds distance from two points on a coordinate plane.

ZephyrsFury

2008-03-06 02:49:03


program New;
const
Ax = 0; Ay = 0;
Bx = 3; By = 4;
begin
WriteLn('Distance between the points is ' + IntToStr(Distance(Ax, Ay, Bx, By)));
end.

;)

JuKKa

2008-03-06 09:33:09

Simple:

Distance(x1, y1, x2, y2);

Returns a INTEGER (number)

TViYH

2008-03-06 16:33:57

Oh, thanks….Didn't know that existed…

EDIT: Now how to find slope plox.

ZephyrsFury

2008-03-07 03:54:12

From: Elkins121
Oh, thanks….Didn't know that existed…

EDIT: Now how to find slope plox.


program New;

const
ax = 0; ay = 0;
bx = 4; by = 4;

var
Slope: Extended;

begin
Slope := (ay - by)/(ax - bx);
Writeln('The gradient of the line connecting the two points is: ' + FloatToStr(Slope));
end.

The gradient of the line between two points is equal to the difference of the two y's divided by the difference of the two x's.

Hmm… it automatically rounds the decimal for some reason…

Santa_Clause

2008-03-07 04:25:33

From: ZephyrsFury
program New;

const
ax = 0; ay = 0;
bx = 4; by = 4;

var
Slope: Extended;

begin
Slope := (ay - by)/(ax - bx);
Writeln('The gradient of the line connecting the two points is: ' + FloatToStr(Slope));
end.

The gradient of the line between two points is equal to the difference of the two y's divided by the difference of the two x's.

Hmm… it automatically rounds the decimal for some reason…


This works:

program New;

const
ax = 0; ay = 0;
bx = 4; by = 5;

var
Slope: Extended;
z, r : Extended;
begin
z := ay - by;
r := ax - bx;
Slope := z/r;
Writeln('The gradient of the line connecting the two points is: ' + FloatToStr(Slope));
end.

bullzeye95

2008-03-07 07:48:47

If you try to divide integers, the answer will be floored (or ceiled? Floored I think). So just simply change
Slope := (ay - by)/(ax - bx);
to
Slope := (ay * 1.0 - by)/(ax - bx);
And it should work.