SRL Archive - Mathematics

Find points around circle.


ZaSz

2010-04-17 15:45:44

I have this
And lets keep the middle point at 10,10. How would I find all the cords around the circle.

Thanks.

(I'll rep!, then I can rep frement!)

Quickmarch

2010-04-17 15:47:55

Get the radius of the circle, then use trig to work the rest out.

Frement

2010-04-17 15:48:00

Hmmh, get the white points to TPA then use ReturnPointsNotInTPA to get the points not in TPA and then get the closest ones near the middle point :)

EDIT: Oh this was in math :D

ZaSz

2010-04-17 15:58:29

Thanks i guess quick, and I still cant rep frem :(

Naum

2010-04-17 18:39:48

If this was purely for maths, I would use trig ratios.
Make a loop and assign each point to an array of points around the circumference.
EDIT:
Actually Coded it:

program New;
{.Include SRL/SRL.Scar}
{.Include SRL/SRL/Misc/Debug.Scar}
{.Include SRL/SRL/Misc/Users.Scar}

Var X, Y, I: Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
TP : TPoint;
TB : TBox;

Function GenerateCircumferencePoints(MidX, MidY : Integer; SDeg, EDeg, Radius : Integer) : TPointArray;
Var I, II : Integer;
Begin
For I := SDeg To EDeg Do
Begin
Inc(II);
SetLength(Result, II);
Result[II - 1] := Point(Round(Sin(Radians(I)) * Radius + MidX), Round(Cos(Radians(I)) * Radius + MidY));
End;
End;

Begin
SetupSRL;
SRLPlayerForm(False, [], [], [], []);
DebugTPA(GenerateCircumferencePoints(10, 10, 0, 360, 7), '');
End.

marpis

2010-04-18 04:36:43

Now that the circle is so small this should suffice:

for x:= 0 to 19 do
for y := 0 to 19 do
if InCircle(x, y, 10, 10, 10) then
begin
inc(L);
SetLength(Result, L);
Result[L - 1] := Point(x, y);
end;

ZaSz

2010-04-18 10:39:48

Marpis, that gets the same size circle drawn, as there is nothing to use radius and such.

And naum, I was about to scratch the circle part of the project until yours worked! Thank you! Rep!

Naum

2010-04-18 13:08:49

Nice to see it worked. :)
If it was just for that smiley, then a faster way would be to do a 'FindColors' on the white part of his face. Then use GetTPAEdges and store the points ;); instead of using mine which lags by loops.

ZaSz

2010-04-18 14:20:41

I just need the output points once, as the smiley will be moving from the center point around, so the points will be moving with it using offsets.

Wanted

2010-04-18 16:17:36

Would be faster and simpilier (coding and runtime) to use Wizzyplugin.

program Circle;

{.Include SRL\SRL.SCAR}
{.Include SRL\SRL\Misc\DeBug.SCAR}

var
TPA: TPointArray;

begin
{TPA := TPAFromBox(IntToBox(X1, Y1, X2, Y2));
FilterPointsPie(TPA, 0, 360, Radius, Radius + 1, OriginX, OriginY);}

TPA := TPAFromBox(IntToBox(50, 50, 100, 100));
FilterPointsPie(TPA, 0, 360, 25, 26, 75, 75);

DeBugTPA(TPA, '');
end.

And lol… why not just use distance anyways?

program Circle;

{.Include SRL\SRL.SCAR}
{.Include SRL\SRL\Misc\DeBug.SCAR}

var
OldTPA, NewTPA: TPointArray;
I, C: LongInt;

begin
OldTPA := TPAFromBox(IntToBox(50, 50, 100, 100));
for I := 0 to High(OldTPA) do
if (Distance(OldTPA[I].X, OldTPA[I].Y, 75, 75) = 25) then
begin
SetLength(NewTPA, C + 1);
NewTPA[C] := OldTPA[I];
Inc(C);
end;
DeBugTPA(NewTPA, '');
end.