Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$I SimbaExt/SimbaExt.simba}
- {$DEFINE NICEDEBUG}
- type TLine = record A,B:TPoint; end;
- var bmp:Integer;
- function FindIntersection(L1,L2:TLine): TPoint;
- var
- D,dx,dy:Extended;
- ax1,ax2,bx1,bx2,ay1,ay2,by1,by2:Int32;
- begin
- ax1 := L1.a.x; ax2 := L1.b.x;
- bx1 := L2.a.x; bx2 := L2.b.x;
- ay1 := L1.a.y; ay2 := L1.b.y;
- by1 := L2.a.y; by2 := L2.b.y;
- D := (ax1-ax2)*(by1-by2) - (ay1-ay2)*(bx1-bx2);
- if D <> 0 then
- begin
- dx := ((bx1-bx2)*(ax1*ay2-ay1*ax2)-(ax1-ax2)*(bx1*by2-by1*bx2))/d;
- dy := ((by1-by2)*(ax1*ay2-ay1*ax2)-(ay1-ay2)*(bx1*by2-by1*bx2))/d;
- Result.x := Round(Dx);
- Result.y := Round(Dy);
- end else
- RaiseException('No Intersection');
- end;
- function InnerBox(Rect:TPointArray): TBox;
- var
- B:TBox; {$IFDEF NICEDEBUG} l:TPointArray; {$ENDIF}
- upper,lower:TPoint;
- begin
- B := Rect.Bounds();
- {$IFDEF NICEDEBUG}
- se.TPALine(l,B.ToCoords()[2],B.ToCoords()[0]);
- se.TPALine(l,B.ToCoords()[3],B.ToCoords()[1]);
- DrawTPABitmap(bmp, l, $008800);
- DrawTPABitmap(bmp, EdgeFromBox(B), $555555);
- {$ENDIF}
- if (Rect[1].distanceTo(Rect[2]) > Rect[2].distanceTo(Rect[3])) then
- begin
- upper := FindIntersection([Rect[1],Rect[2]], [B.ToCoords()[0],Rect.Mean()]);
- lower := FindIntersection([Rect[3],Rect[0]], [B.ToCoords()[2],Rect.Mean()]);
- Result := [Upper.x+1,Upper.y+1,Lower.x-1,Lower.y-1];
- end else begin
- upper := FindIntersection([Rect[0],Rect[1]], [B.ToCoords()[1],Rect.Mean()]);
- lower := FindIntersection([Rect[2],Rect[3]], [B.ToCoords()[3],Rect.Mean()]);
- Result := [Lower.x+1,Upper.y+1,Upper.x-1,Lower.y-1];
- end;
- {$IFDEF NICEDEBUG}
- DrawTPABitmap(bmp, se.TPACross(upper,4), $FFFF00);
- DrawTPABitmap(bmp, se.TPACross(lower,4), $00FFFF);
- {$ENDIF}
- end;
- var i: Integer;
- tpa: TPointArray;
- B:TBox;
- begin
- bmp := CreateBitmap(600, 600);
- TPA := FindTPAEdges(TPAFromBox([50,50, Random(100,220),Random(100,220)]));
- TPA := TPA.Rotate(Random(360));
- B := InnerBox(TPA.BoundingBox());
- DrawTPABitmap(bmp, tpa, 255);
- DrawTPABitmap(bmp, EdgeFromBox(B), $FFFFFF);
- DisplayDebugImgWindow(300, 300);
- DrawBitmapDebugImg(bmp);
- FreeBitmap(bmp);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement