Mega Code Archive

 
Categories / Delphi / Graphic
 

Draw an arrow

Title: draw an arrow? procedure ZeichnePfeil(I: TImage; P1, P2: TPoint); //created by Christof Urbaczek function GetDEG(Winkel: Extended): Extended; // gibt den Winkel im Gradmaß an begin Result := (Winkel * 2 * Pi) / 360; end; function GetRAD(Winkel: Extended): Extended; // gibt den Winkel im Winkelmaß an begin Result := (Winkel * 360) / (2 * Pi); end; const s = 10; // Seitenlänge der Pfeilspitze Beta = 50; // Spannwinkel der Pfeilspitze var Punkte: array [0..2] of TPoint; // Array für die Punkte der Pfeilspitze Alpha, AlphaZ: Extended; // Winkel zur horizontalen Achse durch P1 begin //Linie zeichnen I.Canvas.Brush.Color := clBlack; I.Canvas.Pen.Style := psSolid; I.Canvas.MoveTo(P1.X, P1.Y); I.Canvas.LineTo(P2.X, P2.Y); //Pfeilspitze (1.Punkt) Punkte[0].X := P2.X; Punkte[0].Y := P2.Y; //Winkel ermitteln 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 then Alpha := 0 - AlphaZ else if (P2.X = P1.X) and (P2.Y then Alpha := 90 else if (P2.X and (P2.Y then Alpha := 180 - AlphaZ else if (P2.X and (P2.Y = P1.Y) then Alpha := 180 else if (P2.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; //2.Punkt 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))); //3.Punkt 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))); //Pfeil zeichnen I.Canvas.Brush.Color := clBlack; I.Canvas.Polygon(Punkte); end; // einfacher Aufruf procedure TForm1.Button1Click(Sender: TObject); begin ZeichnePfeil(Image1, Point(20,20), Point(100,150)); end;