Advertisement
WarPie90

ExpandPoly v

May 6th, 2016
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.84 KB | None | 0 0
  1. //forumla by Garrett
  2. function ExpandPoly(poly:TPointArray; incr:Int32): TPointArray;
  3. var
  4.   i,j,size: Int32;
  5.   x,y,r: Double;
  6.   b,m: array of Double;
  7. begin
  8.   SetLength(B, Length(poly));
  9.   SetLength(M, Length(poly));
  10.  
  11.   size := Length(poly);
  12.   for i:=0 to size-1 do
  13.   begin
  14.     j := (i+1) mod size;
  15.     r := incr / Hypot(poly[i].x-poly[j].x, poly[i].y-poly[j].y);
  16.     x := r * (poly[j].y - poly[i].y);
  17.     y := r * (poly[i].x - poly[j].x);
  18.     m[i] := ((poly[j].y + y) - (poly[i].y + y)) / ((poly[j].x + x) - (poly[i].x + x)); //fix me vertical lines
  19.     b[i] := (poly[i].y + y) - (m[i] * (poly[i].x + x));
  20.   end;
  21.  
  22.   SetLength(Result, Length(poly));
  23.   for i:=0 to size-1 do
  24.   begin
  25.     j := (i+1) mod size;
  26.     x := (b[j] - b[i]) / (m[i] - m[j]);
  27.     Result[i].x := Round(x);
  28.     Result[i].y := Round((x * m[i]) + b[i]);
  29.   end;
  30. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement