I know the answer is B, but I am unclear as to why it is. If someone could kindly explain the process of finding the answer or possibly show a simulation, it would be awesome.
You can follow the ball path across the table. The point that makes that easy is that the ball starts in a direction of 45°. Thus, all collision angles will be 45°. Therefore, you have to invert only one component of the ball's direction vector.
Here is some C# sample code. The coordinate system's origin is at the bottom left corner of the table. The ball position is measured at its bounding box' bottom left corner:
int ballX = 0;
int ballY = 0;
int ballWidth = 5;
int tableWidth = 230;
int tableHeight = 130;
int directionX = 1;
int directionY = 1;
while(true)
{
//the distances that the ball could travel until it collides with a vertical or horizontal border, respectively
int travelDistanceX, travelDistanceY;
if (directionX > 0)
travelDistanceX = tableWidth - ballWidth - ballX;
else
travelDistanceX = ballX;
if (directionY > 0)
travelDistanceY = tableHeight - ballWidth - ballY;
else
travelDistanceY = ballY;
if(travelDistanceX == travelDistanceY)
{
//we found the target pocket:
Console.WriteLine("Target is located at {0}/{1}.", ballX + travelDistanceX * directionX, ballY + travelDistanceY * directionY);
break;
}
if(travelDistanceX < travelDistanceY)
{
//collision with the vertical borders
ballX += travelDistanceX * directionX;
ballY += travelDistanceX * directionY;
directionX *= -1;
}
else
{
//collision with the horizontal borders
ballX += travelDistanceY * directionX;
ballY += travelDistanceY * directionY;
directionY *= -1;
}
Console.WriteLine("Collision at {0}/{1}.", ballX, ballY);
}
The code results in the following path:
Collision at 125/125.
Collision at 225/25.
Collision at 200/0.
Collision at 75/125.
Collision at 0/50.
Collision at 50/0.
Collision at 175/125.
Collision at 225/75.
Collision at 150/0.
Collision at 25/125.
Collision at 0/100.
Collision at 100/0.
Target is located at 225/125.
And the pocket at (225/125) (add the ball width to get the actual position) is B.
You can follow the ball path across the table. The point that makes that easy is that the ball starts in a direction of 45°. Thus, all collision angles will be 45°. Therefore, you have to invert only one component of the ball's direction vector.
Here is some C# sample code. The coordinate system's origin is at the bottom left corner of the table. The ball position is measured at its bounding box' bottom left corner:
The code results in the following path:
And the pocket at
(225/125)(add the ball width to get the actual position) is B.