public ReflectionReturnValue TestForCollision(LineSegment path) { var rectangle = new System.Windows.Rect((int)path.EndingPos.GetX(), (int)path.EndingPos.GetY(), 1,0); var intersect = Geometry.FillContainsWithDetail(new System.Windows.Media.RectangleGeometry(rectangle)); if (intersect != System.Windows.Media.IntersectionDetail.Empty) { Angle incomingLineAngle = 180 - path.Angle(); Angle incidentAngle = path.AngleBetweenPoints(CenterPoint); Debug.Print("Angle of incoming line: " +incomingLineAngle.ToString()); Debug.Print("Angle to center line: " + incidentAngle.InDegrees().ToString()); Angle returnAngle = path.Angle() - incidentAngle * 2; Debug.Print("Return Angle: " + returnAngle.ToString()); return new ReflectionReturnValue(returnAngle, new LineSegment(CenterPoint, path.EndingPos)); } return null; }
public ReflectionReturnValue TestForCollision(LineSegment path) { Angle angleToReturnOn = null; if (path.Angle().InRadians() == 0) throw new Exception("This should never happen!"); if (path.EndingPos.GetX() <= BoundingRectangle.Left || path.EndingPos.GetX() >= BoundingRectangle.Right){ angleToReturnOn =new Angle(path.YComponent(), -path.XComponent()); } if (path.EndingPos.GetY() >= BoundingRectangle.Bottom) { angleToReturnOn= new Angle(-path.YComponent(), path.XComponent()); } if (path.EndingPos.GetY() <= BoundingRectangle.Top) { angleToReturnOn = new Angle(path.YComponent(), path.XComponent()).Negate(); } return new ReflectionReturnValue(angleToReturnOn); }