Advertisement
WarPie90

ExtractSector

Feb 28th, 2016
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.63 KB | None | 0 0
  1. function ExtractSector(TPA:TPointArray; angle,sector:Double; radLo,radHi:Int32; center:TPoint):TPointArray;
  2. var
  3.   i,j:Int32;
  4.   theta,dist,delta:Double;
  5. begin
  6.   SetLength(Result, Length(TPA));
  7.   angle := Radians(angle);
  8.   for i:=0 to High(TPA) do
  9.   begin
  10.     dist  := Sqrt(Sqr(TPA[i].x-center.x) + Sqr(TPA[i].y-center.y));
  11.     theta := ArcTan2(TPA[i].y-center.y, TPA[i].x-center.x) + (PI / 2);
  12.     delta := Degrees(ArcTan2(Sin(theta-angle), Cos(theta-angle)));
  13.     if (Abs(delta) <= sector) and (dist >= radLo) and (dist <= radHi) then
  14.     begin
  15.       Result[j] := TPA[i];
  16.       Inc(j);
  17.     end;
  18.   end;
  19.   SetLength(Result, j);
  20. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement