Advertisement
Janilabo

ptil

Jan 3rd, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.27 KB | None | 0 0
  1. function PointInLineEx(p, p1, p2: TPoint; tol: Integer): Boolean;
  2. var
  3.   x, y, l, d: Integer;
  4.   t, s, c: Extended;
  5. begin
  6.   if (tol > 0) then
  7.     d := (Abs(tol) + 1)
  8.   else
  9.     d := 1;
  10.   t := ArcTan2((p2.Y - p1.Y), (p2.X - p1.X));
  11.   s := Sin(t);
  12.   c := Cos(t);
  13.   x := Round((c * (p.X - p1.X)) + (s * (p.Y - p1.Y)));
  14.   y := Round((c * (p.Y - p1.Y)) - (s * (p.X - p1.X)));
  15.   l := Round((c * (p2.X - p1.X)) + (s * (p2.Y - p1.Y)));
  16.   Result:= (((y > -d) and (y < d)) and ((x > -d) and (x < (l + d))));
  17. end;
  18.  
  19. function PointInLine(p, p1, p2: TPoint): Boolean;
  20. begin
  21.   Result := PointInLineEx(p, p1, p2, 0);
  22. end;
  23.  
  24. var
  25.   a, b, c: TPoint;
  26.  
  27. procedure DebugBitmap(bmp: Integer);
  28. var
  29.   w, h: Integer;
  30. begin
  31.   GetBitmapSize(bmp, w, h);
  32.   DisplayDebugImgWindow(w, h);
  33.   DrawBitmapDebugImg(bmp);
  34. end;
  35.  
  36. var
  37.   x, y: Integer;
  38.   bmp: Integer;
  39.  
  40. begin
  41.   a := Point(175, 269);
  42.   b := Point(259, 344);
  43.   c := Point(216, 298);
  44.   bmp := CreateBitmap(500, 500);
  45.   for x := 0 to 499 do
  46.     for y := 0 to 499 do
  47.       if PointInLineEx(Point(x, y), a, b, 15) then
  48.         FastSetPixel(bmp, x, y, 255);
  49.   for x := 0 to 499 do
  50.     for y := 0 to 499 do
  51.       if PointInLine(Point(x, y), a, b) then
  52.         FastSetPixel(bmp, x, y, 16777215);
  53.   DebugBitmap(bmp);
  54.   FreeBitmap(bmp);
  55. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement