Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PointInLineEx(p, p1, p2: TPoint; tol: Integer): Boolean;
- var
- x, y, l, d: Integer;
- t, s, c: Extended;
- begin
- if (tol > 0) then
- d := (Abs(tol) + 1)
- else
- d := 1;
- t := ArcTan2((p2.Y - p1.Y), (p2.X - p1.X));
- s := Sin(t);
- c := Cos(t);
- x := Round((c * (p.X - p1.X)) + (s * (p.Y - p1.Y)));
- y := Round((c * (p.Y - p1.Y)) - (s * (p.X - p1.X)));
- l := Round((c * (p2.X - p1.X)) + (s * (p2.Y - p1.Y)));
- Result:= (((y > -d) and (y < d)) and ((x > -d) and (x < (l + d))));
- end;
- function PointInLine(p, p1, p2: TPoint): Boolean;
- begin
- Result := PointInLineEx(p, p1, p2, 0);
- end;
- var
- a, b, c: TPoint;
- procedure DebugBitmap(bmp: Integer);
- var
- w, h: Integer;
- begin
- GetBitmapSize(bmp, w, h);
- DisplayDebugImgWindow(w, h);
- DrawBitmapDebugImg(bmp);
- end;
- var
- x, y: Integer;
- bmp: Integer;
- begin
- a := Point(175, 269);
- b := Point(259, 344);
- c := Point(216, 298);
- bmp := CreateBitmap(500, 500);
- for x := 0 to 499 do
- for y := 0 to 499 do
- if PointInLineEx(Point(x, y), a, b, 15) then
- FastSetPixel(bmp, x, y, 255);
- for x := 0 to 499 do
- for y := 0 to 499 do
- if PointInLine(Point(x, y), a, b) then
- FastSetPixel(bmp, x, y, 16777215);
- DebugBitmap(bmp);
- FreeBitmap(bmp);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement