Beispiel 1:
procedure ZeichnePfeil(I: TImage; P1, P2: TPoint);
function GetDEG(Winkel: Extended): Extended;
begin
Result := (Winkel * 2 * Pi) / 360;
end;
function GetRAD(Winkel: Extended): Extended;
begin
Result := (Winkel * 360) / (2 * Pi);
end;
const
s = 10;
Beta = 50;
var
Punkte: array [0..2] of TPoint;
Alpha, AlphaZ: Extended;
begin
I.Canvas.Brush.Color := clBlack;
I.Canvas.Pen.Style := psSolid;
I.Canvas.MoveTo(P1.X, P1.Y);
I.Canvas.LineTo(P2.X, P2.Y);
Punkte[0].X := P2.X;
Punkte[0].Y := P2.Y;
Alpha := 0;
if P2.X = P1.X then
AlphaZ := 0
else
AlphaZ := GetRAD(ArcTan((P2.Y - P1.Y) / (P2.X - P1.X)));
if (P2.X > P1.X) and (P2.Y = P1.Y) then Alpha := 0
else if (P2.X > P1.X) and (P2.Y < P1.Y) then Alpha := 0 - AlphaZ
else if (P2.X = P1.X) and (P2.Y < P1.Y) then Alpha := 90
else if (P2.X < P1.X) and (P2.Y < P1.Y) then Alpha := 180 - AlphaZ
else if (P2.X < P1.X) and (P2.Y = P1.Y) then Alpha := 180
else if (P2.X < P1.X) and (P2.Y > P1.Y) then Alpha := 180 - AlphaZ
else if (P2.X = P1.X) and (P2.Y > P1.Y) then Alpha := 270
else if (P2.X > P1.X) and (P2.Y > P1.Y) then Alpha := 360 - AlphaZ;
Punkte[1].X := round(P2.X - s * cos(GetDEG(Alpha - Beta div 2)));
Punkte[1].Y := round(P2.Y + s * sin(GetDEG(Alpha - Beta div 2)));
Punkte[2].X := round(P2.X - s * cos(GetDEG(Alpha + Beta div 2)));
Punkte[2].Y := round(P2.Y + s * sin(GetDEG(Alpha + Beta div 2)));
I.Canvas.Brush.Color := clBlack;
I.Canvas.Polygon(Punkte);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ZeichnePfeil(Image1, Point(20,20), Point(100,150));
end;
Beispiel 2:
uses Math
var
Form1: TForm1;
BeginPoint: TPoint;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
BeginPoint.X := X;
BeginPoint.Y := Y;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
B, deltaX, deltaY: Extended;
begin
Image1.Canvas.PenPos := BeginPoint;
Image1.Canvas.LineTo(X, Y);
if BeginPoint.X <> X then
begin
if (BeginPoint.X > X) then
B := DegToRad(135) - ArcTan((BeginPoint.Y - Y) / (BeginPoint.X - X))
else
B := DegToRad(45) - ArcTan((BeginPoint.Y - Y) / (BeginPoint.X - X));
deltaX := 15 * Cos(B);
deltaY := 15 * Sin(B);
if (BeginPoint.X > X) then
begin
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X - Trunc(deltaX), Y + Trunc(deltaY));
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X + Trunc(deltaY), Y + Trunc(deltaX));
end
else
begin
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X - Trunc(deltaX), Y + Trunc(deltaY));
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X - Trunc(deltaY), Y - Trunc(deltaX));
end;
end
else
begin
if BeginPoint.Y > Y then
begin
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X + 10, Y + 10);
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X - 10, Y + 10);
end
else
begin
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X + 10, Y - 10);
Image1.Canvas.PenPos := Point(X, Y);
Image1.Canvas.LineTo(X - 10, Y - 10);
end;
end;
end;
Keine Kommentare:
Kommentar veröffentlichen