Are there any predefined methods in c# which allow for collision detection?
I am new to c# and am trying to get collision detection of two ellipses are there any predefined ways collision detection can be implemented?
I already have code which draws the ellipses, what would be a good way to start the collision detection?
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
};
}
this is the code to draw an ellipse which then gets removed and appears in another position.

RectangleF.IntersectsWith. Otherwise, you'll have to calculate the angle of approach of the two ellipses, the radius at that angle, then see if adding the length of the two radii is less than or equal to the distance between two foci of the ellipses.