SRL Archive - Help and Support

Math help.


Negaal

2008-03-04 04:12:01

See. I'm stupid.

My questions is how to find all steps from e.g x,y to a, b

Like if
X = 10
Y= 10
And I want to reach to
A = 15
B = 15

the steps would be
11,11
12,12
13,13
14,14
15,15.

I tryed to understand something from Ben's windmouse. I got headache in 15 secs.

So please could someone explain it.


Edit. I know actually how to find these steps. But not really inteligent.It would be too big.

bullzeye95

2008-03-04 07:56:40

program New;

function PointsBetween(sx, sy, ex, ey: Integer): TPointArray;
var
I, D: Integer;
Slope: Extended;
begin
try
Slope:= (sy * 1.0 - ey) / (sx - ex);
except
Slope:= 0;
end;
D:= iAbs(sx - ex);
SetLength(Result, D);
for I:= 1 to D do
Result[I - 1]:= Point(I, Round(I * Slope));
for I:= 0 to D - 1 do
writeln(inttostr(Result[I].x) + ', ' + inttostr(Result[I].y));
end;

begin
PointsBetween(0, 0, 5, 5);
end.
SHOULD work…

n3ss3s

2008-03-04 08:17:16

This quote from me is from the thread JuKKa needed some math help in, - the function I posted might be helpful.

From: n3ss3s

Procedure GetCloser(Var Point: TPoint; Origin: TPoint; HowMuchCloser: Integer);
Var
Angle, Dist: Integer;
Begin
Angle := Round(Degrees(ArcTan2(Origin.y - Point.y, Origin.x - Point.x))) - 90;
If Angle < 0 Then
Angle := Angle + 360;
Dist := Distance(Point.x, Point.y, Origin.x, Origin.y) - HowMuchCloser;
Point.x := Origin.x + Round(Dist * Cos(Radians(Angle - 90)));
Point.y := Origin.y + Round(Dist * Sin(Radians(Angle - 90)));
End;


Stupid leecher :D You've been glancing at the thread for like half an hour without saying thank you :D


@Math people: Don't complain about the "-90", I've thinked, tested and it's worked.

Look - and example:

ArcTan2 would return me a -90 for example. -90 points to west, then we make it -180, and add 360, voila, it's to south as supposed to.



Also this tutorial about the bezier spline might be handy.

Negaal

2008-03-04 09:22:12

Bullzeye, I tested yours, doesn't seem to be working.

program New;

function PointsBetween(ex, ey: Integer): TPointArray;
var
I, D, Sx, Sy: Integer;
Slope: Extended;
begin
GetMousepos(sx, sy);
try
Slope:= (sy * 1.0 - ey) / (sx - ex);
except
Slope:= 0;
end;
D:= iAbs(sx - ex);
SetLength(Result, D);
for I:= 1 to D do
Result[I - 1]:= Point(I, Round(I * Slope));
end;
var
tpa : tpointarray;
i, x, y : integer;

begin
tpa := PointsBetween(5, 500);
for i:= 0 to high(tpa) do
begin
Movemouse(tpa[i].x,tpa[i].y)
wait(10);
end;
end.

It moves mouse somewhere 500,0

Also I tryed with for .. to .. do
It can't count backwards :(

n3ss3s

2008-03-04 11:32:55

For loop, infact, can count back wards - use "For I := Q DownTo W Do" :)

BenLand100

2008-03-04 14:03:36

I haven't got a Scar to test on here, but try something like this:

procedure GetPoints(x1,y1,x2,y2:integer);
var
x,y: integer;
m,b: extended;
begin
if (x1 - x2 = 0) then //Verticle, slope undefined
begin
if y1 > y2 then
for y:= y1 downto y2 do
WriteLn('X:' + IntToStr(x1) + ' Y:' + IntToStr(y))
else
for y:= y1 to y2 do
WriteLn('X:' + IntToStr(x1) + ' Y:' + IntToStr(y));
exit; //Done, exit the procedure
end;
m:= (y1 - y2) div (x1 - x2); //Slope, this needs to not round, div should work
b:= y1 - m*x1; //Y Intercept
if (x1 > x2) then
begin
for x:= x1 downto x2 do
begin
y:= Round(m*x + b);
WriteLn('X:' + IntToStr(x) + ' Y:' + IntToStr(y));
end;
end else
begin
for x:= x1 to x2 do
begin
y:= Round(m*x + b);
WriteLn('X:' + IntToStr(x) + ' Y:' + IntToStr(y));
end;
end;
end;

EDIT: Also, in your sig, are you thinking of the saying: "Where were you when the shit hit the fan?"

@n3ss3s, in case no one else said in the other thread, the reason you have to subtract 90 is because Y is inverted on a computer screen, i.e. positive Y goes the wrong way ;) Also, mathematicly, 0 points east, 180 west, 90 north, -90 south, so… you are just all confused :p

Negaal

2008-03-04 15:14:59

I knew downto, thing is what if I do downto but CurrentMouseX/Y is bigger than DestX/Y.

Ben, I came up with something similar to this, I just though it could be done shorter and l33ter.

I think I got my answer =/