Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.447 Beiträge
Delphi 12 Athens
|
Re: Ausfallswinkel berechnen und mit Canvas einzeichnen
15. Okt 2008, 19:00
Delphi-Quellcode:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
cMax = 5;
var
X0, X1: Integer;
Y0, Y1: Integer;
W, H: Integer;
R: TRect;
count: Integer;
procedure MirrorY(Value: Integer); forward;
procedure MirrorX(Value: Integer);
begin
if Count > cMax then Exit;
X := Value;
Y := Round(Y0 + (X - X0)*(Y1 - Y0)/(X1 - X0));
if Y < R.Top then
MirrorY(R.Top)
else if Y > R.Bottom then
MirrorY(R.Bottom)
else begin
Inc(Count);
X1 := 2*X - X1;
Canvas.LineTo(X, Y);
X0 := X;
Y0 := Y;
end;
end;
procedure MirrorY(Value: Integer);
begin
if Count > cMax then Exit;
Y := Value;
X := Round(X0 + (Y - Y0)*(X1 - X0)/(Y1 - Y0));
if X < R.Left then
MirrorX(R.Left)
else if X > R.Right then
MirrorX(R.Right)
else begin
Inc(Count);
Y1 := 2*Y - Y1;
Canvas.LineTo(X, Y);
X0 := X;
Y0 := Y;
end;
end;
begin
Self.Repaint;
W := Shape1.Width div 2;
H := Shape1.Height div 2;
X0 := Shape1.Left + W;
Y0 := Shape1.Top + H;
with Shape2 do
R := Rect(Left + W, Top + H, Left + Width - W, Top + Height - H);
W := Shape2.Width;
if shape2.Height > W then
W := shape2.Height;
Canvas.MoveTo(X0, Y0);
X1 := X0 + 5*W*(X - X0);
Y1 := Y0 + 5*W*(Y - Y0);
Count := 0;
while Count < cMax do begin
if X1 < R.Left then
MirrorX(R.Left)
else if X1 > R.Right then
MirrorX(R.Right)
else if Y1 < R.Top then
MirrorY(R.Top)
else if Y1 > R.Bottom then
MirrorY(R.Bottom)
else
Break;
end;
Canvas.LineTo(X1, Y1);
end;
procedure TForm1.Shape2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
self.Repaint;
Canvas.MoveTo(shape1.Left + (Shape1.Width div 2), Shape1.Top + (Shape1.Height div 2));
Canvas.LineTo(shape2.Left + X, shape2.Top + Y);
end;
Uwe Raabe
|
|
Zitat
|