Registriert seit: 12. Dez 2004
Ort: Wien, Österriech
893 Beiträge
Delphi 6 Enterprise
|
Re: Einen Winkel errechnen!?
25. Feb 2005, 17:33
Ich hoffe das hilft:
Delphi-Quellcode:
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Label2: TLabel;
Label1: TLabel;
Label3: TLabel;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
center : tpoint;
implementation
uses Math;
{$R *.dfm}
procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.FillRect(ClientRect);
Canvas.MoveTo(0, height div 2);
Canvas.LineTo(width, height div 2);
Canvas.MoveTo(width div 2, 0);
Canvas.LineTo(width div 2, height);
center := point(width div 2,height - height div 2);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Pen.Color := clBlack;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var angle,p : extended;
begin
angle := 0;
p := 1;
FormPaint(self);
Canvas.MoveTo(width div 2, height div 2);
Canvas.LineTo(x,y);
y := Height - y;
Label1.Caption := 'y-center.Y = '+inttostr(y-center.Y);
if (x-center.X <>0) then
begin
Angle := ArcTan((y-center.Y)/(x-center.X)) * 180 / pi;
Label3.Caption := 'x-center.X = '+inttostr(x-center.X);
if (angle<0)and(x-center.X<0) then angle := 180 + angle
else
if (x-center.X<0)and(y-center.Y<0) then angle := 180 + angle
else
if (y-center.y<0) then angle := 360 + angle;
Label2.Caption := 'Current angle: '+Floattostr(angle)+ ' degrees.';
end;
end;
Katura Haris Es (ein gutes Wort) ist wie ein guter Baum, dessen Wurzel fest ist und dessen Zweige in den Himmel reichen.
|
|
Zitat
|