Einzelnen Beitrag anzeigen

mr_emre_d
(Gast)

n/a Beiträge
 
#7

Re: Berührung 2er bewegter Kreise

  Alt 26. Mai 2009, 01:03
Delphi-Quellcode:
function CircleIntersect( Circle1Center, Circle2Center: TPoint;
  Circle1Radius, Circle2Radius: Cardinal ): Boolean;
begin
  Circle1Center := Point( Circle2Center.X - Circle1Center.X, Circle2Center.Y - Circle1Center.Y );
  Result := SQRT( Circle1Center.X*Circle1Center.X + Circle1Center.Y*Circle1Center.Y ) <= (Circle1Radius div 2 + Circle2Radius div 2);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  M1 := Point( $80, $80 );
  M1R := $80;
  M2 := Point( $100, $80 );
  M2R := $80;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  if CircleIntersect( M1, M2, M1R, M2R ) then
    Canvas.Pen.Color := clRed
  else
    Canvas.Pen.Color := clLime;
  Canvas.Ellipse( M1.X - M1R div 2, M1.Y - M1R div 2, M1.X + M1R div 2, M1.Y + M1R div 2 );
  Canvas.Ellipse( M2.X - M2R div 2, M2.Y - M2R div 2, M2.X + M2R div 2, M2.Y + M2R div 2 );
end;
  Mit Zitat antworten Zitat