SRL Archive - Test corner

New RadialWalking?


Wizzup?

2007-10-28 06:23:38

Thanks to lorax for some good ol' mathematical help. :)

This get's all the points of the color you put in, in a area defined by StartD and EndD, it works just like the normal RadialWalk, Starts from StartD. (The SortTPAFrom)
You can do alot with SortTPAFrom, Sort from start, end, middle of the two degrees, or a different degree you put in.

program New;

{.include SRL/SRL.scar}

Function DebugTPA(Points: TPointArray; BmpName: String): Boolean;

Var
Width, Height, ClientBMP, I: Integer;
xs, ys, xe, ye: Integer;

Begin
Try
Begin
xe := xs xor xs;
ye := ys xor ys;
xs := 1 shl 20;
ys := 1 shl 20;

For I := 0 To High(Points) Do
Begin
xs := Min(xs, Points[I].X);
ys := Min(ys, Points[I].Y);

xe := Max(xe, Points[I].X);
ye := Max(ye, Points[I].Y);
End;

Width := xe - xs;
Height := ye - ys;

DisplayDebugImgWindow(0, 0);
DisplayDebugImgWindow(Width, Height);
ClientBMP := BitmapFromString(Width, Height, '');

CopyClientToBitmap(ClientBMP, xs, ys, xe, ye);
For I := 0 To High(Points) Do
FastSetPixel(ClientBMP, Points[I].X - xs, Points[I].Y - ys, 255);

If BmpName <> '' Then
SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
DisplayDebugImgWindow(Width, Height);

FreeBitmap(ClientBMP);
End
Except
FreeBitmap(ClientBMP);
End;
Result := True;
End;

Function InDegreeEx(x, y, mx, my, sd, ed: Integer; minr, maxr: Extended): Boolean;

Var
xDeg, d: Extended;

Begin
sd := sd Mod 360;
ed := ed Mod 360;

xDeg := Degrees(ArcTan2(y - my, x - mx)) + 90;
If xDeg < 0 Then
xDeg := 90 - (xDeg * -1) + 270;
Result := ( (xDeg > sd) And (xDeg < ed) );
If Result Then
Begin
d := Sqrt(Sqr(x - mx) + Sqr(y - my));
Result := ( (d > minr) And (d < maxr) );
End;
End;

Procedure GetRadialPoints(Var Points: TPointArray; Color, Tol, startD, endD, MinRadius, MaxRadius: Integer);

Var
Time, I, C: Integer;
Temp: TPointArray;
S: Boolean;

Begin
Time := GetSystemTime;
FindColorsTolerance(Temp, Color, MMX1, MMY1, MMX2, MMY2, Tol);
startD := startD Mod 360;
endD := endD Mod 360;
SetLength(Points, Length(Temp));
C := 0;
If StartD > EndD Then
Begin;
S := True;
Swap(startD, endD);
End;
For I := 0 To High(Temp) Do
If InDegreeEx(Temp[I].X, Temp[I].Y, MMCX, MMCY, startD, endD, MinRadius, MaxRadius) Then
Begin
Points[C] := Temp[I];
C := C + 1;
End;
SetLength(Points, C);
SetLength(Temp, 0);
If S Then
Swap(startD, endD);
DebugTPA(Points, '');
End;

Var
P: TpointArray;

begin
SetupSRL;
GetRadialPoints(P, 6386555, 0, 250, 0, 0, 30);
end.

~ Wizzup?

EDIT2:
New code.

The Claw

2007-10-28 07:05:13

cool, cool
could you explain how it works more, please? :) like the StartD and the cos and sin stuff. I'm guessing its to do with the unit circle but i cant figure it out lol. Also, InDegree? and whats the point of Swap? sorry for the noob questions :D

Wizzup?

2007-10-28 07:39:50

From: The Claw
cool, cool
could you explain how it works more, please? :) like the StartD and the cos and sin stuff. I'm guessing its to do with the unit circle but i cant figure it out lol. Also, InDegree? and whats the point of Swap? sorry for the noob questions :D


First I find all colors of the color people input on the MM.
Next, I filter out those that are not in the area defined by StartD and EndD.
This leaves us with all the colors The normal radialwalk would find.

InDegree, checks if the point is in the area defined by StartD and EndD.
The Swap is nessecary to make it work like the normal RW.
StartD > EndD means That you go counter clockwise, instead of clockwise.
I have to swap them for my InDegree to work properly, but only if StartD > EndD.
After the sorting I swap them again, which brings both back to their old values.

Next, a SortTPAFrom, to start at StartDegree.
'Start at', as in, Index 0 is closest and Index High(Points) = point most far away.

So it get's all colors in an area.
Next you tell it where to start from.

Ruroken

2007-10-28 09:03:51

nice, I cant claim to understand all the math but from what I can understand it looks great :)

Good work.

Wizzup?

2007-10-28 09:25:35

Alright, very quickly the ArcTan:

Tan x = Sin x / Cos x.
Slope = x / y.

You know that ArcSin(Sin(x)) = x.
ArcTan(Tan(x)) = x, aswell.

NOTE: x is not a coord, but just a var. :)

ArcTan(Slope) = Degrees.

Well thats it.. In degrees then checks if the returned degree if bigger than the StartD and Smaller than the EndD. :)

n3ss3s

2007-10-28 11:55:05

So you can think of X in your example as any number?

Like ArcTab(Tan(5)) = 5?

Good job with the walking, btw one thing I noticed:

If StartD > EndD Then
Begin;
S := True;
Swap(StartD, EndD);
End;

Lets have 5 as our StartD and 10 as our EndD -

So, now it would go from 5 to 10 degrees the circle on mm, BUT
if the user has 10 as StartD and 5 as EndD, your function swaps them,
and "For I := 5 To 10 Do" is not same as "For I := 10 To 5 Do" and now if the user purposely wants to search from 90 To 1, you need the DownTo there instead of the swapping, like the ol rrw does..

ShowerThoughts

2007-10-28 11:57:26

Wizzup? explain more tut me :)(dutch msn?)

nielsie95

2007-10-28 12:01:23

From: n3ss3s
So you can think of X in your example as any number?

Like ArcTab(Tan(5)) = 5?

Good job with the walking, btw one thing I noticed:

If StartD > EndD Then
Begin;
S := True;
Swap(StartD, EndD);
End;

Lets have 5 as our StartD and 10 as our EndD -

So, now it would go from 5 to 10 degrees the circle on mm, BUT
if the user has 10 as StartD and 5 as EndD, your function swaps them,
and "For I := 5 To 10 Do" is not same as "For I := 10 To 5 Do" and now if the user purposely wants to search from 90 To 1, you need the DownTo there instead of the swapping, like the ol rrw does..


He swaps them back later..
Wizzup and I managed to get the time down to an avarage of 0ms with the help of WizzyPlugin :)

Wizzup?

2007-10-28 12:02:41

From: n3ss3s
So you can think of X in your example as any number?

Like ArcTab(Tan(5)) = 5?

Good job with the walking, btw one thing I noticed:

If StartD > EndD Then
Begin;
S := True;
Swap(StartD, EndD);
End;

Lets have 5 as our StartD and 10 as our EndD -

So, now it would go from 5 to 10 degrees the circle on mm, BUT
if the user has 10 as StartD and 5 as EndD, your function swaps them,
and "For I := 5 To 10 Do" is not same as "For I := 10 To 5 Do" and now if the user purposely wants to search from 90 To 1, you need the DownTo there instead of the swapping, like the ol rrw does..


I have no:
for i := startd to endd do

It works, actually that Swap is only in so it works exactly like RadialWalk. :)

JuKKa

2007-10-28 13:24:27

Genius!

legendaryhero90

2007-10-28 13:26:08

From: Wizzup?
Alright, very quickly the ArcTan:

Tan x = Sin x / Cos x.
Slope = x / y.

You know that ArcSin(Sin(x)) = x.
ArcTan(Tan(x)) = x, aswell.

NOTE: x is not a coord, but just a var. :)

ArcTan(Slope) = Degrees.

Well thats it.. In degrees then checks if the returned degree if bigger than the StartD and Smaller than the EndD. :)


so is this putting radial walk into trigonometry?

im a little confused on the function whatnot but not the math part :D

(yeah im weird like that :duh: )

bullzeye95

2007-10-28 13:43:23

Making a number equal 0 is faster than making it xor itself in SCAR.
program New;
var
I, T, X: Integer;
begin
T:= GetSystemTime;
for I:= 1 to 100000 do
x:= x xor x;
writeln(inttostr(GetSystemTime - T));
wait(1000);
T:= GetSystemTime;
for I:= 1 to 100000 do
x:= 0;
writeln(inttostr(GetSystemTime - T));
end.

n3ss3s

2007-10-28 13:56:15

It works, actually that Swap is only in so it works exactly like RadialWalk.
Yeah, thanks, I missed it when I read through first time.

EDIT: Seems like I missed your second post also -.-

I tend to post before reading the thread sometimes :p

Harry

2007-10-28 14:19:39

I don't understand a thing any of you guys said :p

But it looks nice. xD

Lorax

2007-10-28 14:33:16

I think you posted the wrong version it needs,
90 - (-xDeg) + 270;

Wizzup?

2007-10-28 16:54:17

From: Lorax
I think you posted the wrong version it needs,
90 - (-xDeg) + 270;


This one works as far as I know. :)
That other one was for the compass..

EDIT: I added your way again, and left the old one in commented.

The Claw

2007-10-28 16:54:42

From: Wizzup?
Alright, very quickly the ArcTan:

Tan x = Sin x / Cos x.
Slope = x / y.

You know that ArcSin(Sin(x)) = x.
ArcTan(Tan(x)) = x, aswell.

NOTE: x is not a coord, but just a var. :)

ArcTan(Slope) = Degrees.

Well thats it.. In degrees then checks if the returned degree if bigger than the StartD and Smaller than the EndD. :)


OK sweet, thats what I wanted to know. I didnt see InDegree when scrolling through, my mistake lol

pwnaz0r

2007-10-28 23:18:30

nice Wizzy, what I want to know is what was wrong with the old one? This one just faster? (I feel all cool now because many people don't understand what he did XD)

Wizzup?

2007-10-29 07:13:15

The old radialwalk uses alot of CPU and was, indeed, quite slow.
Nielsie got it down to 0-16ms.. :)

Bobarkinator

2007-10-29 08:11:15

Is this in rev 6 or we need to manually put it in?

Wizzup?

2007-10-29 09:33:30

Well I this is still in 'testing phase', but I'm hoping to finish it soon.
I have updated my first post with new code, this seems the best way to use it, at least to me…

mat_de_b

2007-10-30 12:04:47

This one also returns a Tpoint array instead of just the furthest out point…

Wizzup?

2007-10-30 13:42:32

From: mat_de_b
This one also returns a Tpoint array instead of just the furthest out point…


Yes, that is the idea.
This should be the core that you use to get the TPA, and then you can sort the TPA from a certain point. :)

Hugolord

2007-10-30 13:47:53

pretty nice thanks :D

The Claw

2007-11-05 06:29:22

(01:03:22) Error with RadialRoadWalk
(01:03:22) Should be fixed though, so lets debug.
(01:03:22) xs = 649 ys = 3 xe = 689 ye = 43
(01:03:22) and client area is 0, 0, 766, 504

Then one of those "scar has encountered a problem" windows popped up, and scar closed
using the latest dev rev#

Wizzup?

2007-11-05 11:43:36

From: The Claw
(01:03:22) Error with RadialRoadWalk
(01:03:22) Should be fixed though, so lets debug.
(01:03:22) xs = 649 ys = 3 xe = 689 ye = 43
(01:03:22) and client area is 0, 0, 766, 504

Then one of those "scar has encountered a problem" windows popped up, and scar closed
using the latest dev rev#


I didn't add it yet.. ;)

Wizzup?

2007-11-30 12:49:36

Function InDegree(sd, ed, d: extended): Boolean;

Begin
While (sd > 360) Or (ed > 360) Do
begin
sd := sd - 360;
ed := ed - 360;
end;
sd := ArcCos(Cos(Radians(sd / 2))) * 2;
ed := ArcCos(Cos(Radians(ed / 2))) * 2;
d := ArcCos(Cos(Radians(d / 2))) * 2;
Result := ((sd <= d) And (ed >= d));
End;


This should work nicely.
The new RW is nearly done now.. I guess, I totally rewrote it.

Wanted

2007-11-30 22:40:18

From: Wizzup?
Function InDegree(sd, ed, d: extended): Boolean;

Begin
While (sd > 360) Or (ed > 360) Do
begin
sd := sd - 360;
ed := ed - 360;
end;
sd := ArcCos(Cos(Radians(sd / 2))) * 2;
ed := ArcCos(Cos(Radians(ed / 2))) * 2;
d := ArcCos(Cos(Radians(d / 2))) * 2;
Result := ((sd <= d) And (ed >= d));
End;


This should work nicely.
The new RW is nearly done now.. I guess, I totally rewrote it.


Looking forward to it, definitely after all those renovations :redface: