was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

41 Visitors Online


 
... einen Pfeil zeichnen?
Autor: Christof Urbaczek
[ Tip ausdrucken ]  

Tip Bewertung (22):  
     


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 < 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;

  //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;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners