在c#中有没有预定义的方法可以实现碰撞检测?
我是c#的新手,正在尝试检测两个椭圆的碰撞,是否有任何预定义的方法可以实现碰撞检测?
我已经有了绘制椭圆的代码,从哪里开始实现碰撞检测呢?
private void timer1_Tick(object sender, EventArgs e)
{
//Remove the previous ellipse from the paint canvas.
canvas1.Children.Remove(ellipse);
if (--loopCounter == 0)
timer.Stop();
//Add the ellipse to the canvas
ellipse = CreateAnEllipse(20, 20);
canvas1.Children.Add(ellipse);
Canvas.SetLeft(ellipse, rand.Next(0, 500));
Canvas.SetTop(ellipse, rand.Next(0, 310));
}
// Customize your ellipse in this method
public Ellipse CreateAnEllipse(int height, int width)
{
SolidColorBrush fillBrush = new SolidColorBrush() { Color = Colors.Yellow};
SolidColorBrush borderBrush = new SolidColorBrush() { Color = Colors.Black };
return new Ellipse()
{
Height = height,
Width = width,
StrokeThickness = 1,
Stroke = borderBrush,
Fill = fillBrush
};
}
这是绘制椭圆的代码,然后将其移除并出现在另一个位置。
RectangleF.IntersectsWith
。否则,你将不得不计算两个椭圆相遇的角度、该角度处的半径,然后看看添加两个半径的长度是否小于或等于椭圆的两个焦点之间的距离。 - Peter Ritchie