Bouncing Inside a Triangle

A right-triangular box is fixed in place in the x y x y plane, with its vertices at ( x , y ) (x,y) values of ( 0 , 0 ) (0,0) , ( 1 , 0 ) (1,0) , and ( 0 , 1 ) (0,1) . A ball is initially at ( 0.3 , 0.5 ) (0.3,0.5) , with a velocity vector ( v x , v y ) (v_x,v_y) of ( 5 , 7 ) (5,-7) . The ball bounces off of the sides of the box.

If x x' and y y' are the coordinates of the ball on its 1000th bounce, give your answer as 1000 ( x + y ) \lfloor 1000 \, (x' + y') \rfloor .

Details and Assumptions:

  • When the ball bounces off of a surface (side), the normal component of the velocity is negated and the tangential portion of the velocity is preserved.
  • There are no forces at play when the ball is traversing the interior of the box
  • \lfloor \cdot \rfloor denotes the floor function


The answer is 485.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Jeremy Galvagni
Sep 21, 2018

The problem does not need to be in Computer Science. I solved it with just a sheet of graph paper.

The triangle is repeatedly reflected over its sides until the full vector is drawn. At this point, we can see 19 walls have been crossed (reflected over). I made these walls thick red. The colors of the triangle are to keep track of the orientation of the triangle. The blue ones are mirror images of the pink ones. Because the vector ends in the blue, the ball hasn't actually reached (0.3,0.5) but rather (0.5,0.3) and is traveling upward relative to the original triangle. This means it would take a further 19 bounces to return the ball to its original position. It's possible but not easy to count these 38 bounces in the original picture.

1000 divided by 38 is 26 with remainder 12. So all we really need now we need the position of the 12th bounce. Again, counting carefully you can see this bounce in the original picture. It's on the x-axis just below 0.5 I've marked it on my picture with a green dot.

The vector is the line with equation y 0.5 = 7 5 ( x 0.3 ) y-0.5=\frac{-7}{5}(x-0.3) and we can see the point we're looking for is on the line y = 4 y=-4

Solving gives x = 123 35 = 3 + 18 35 x=\frac{123}{35}=3+\frac{18}{35} .

Since this point is on a blue reversed triangle, relative to the original (0.0) is the lower right corner and (0,1) is to the left. So we need to reverse 18 35 \frac{18}{35} to 17 35 \frac{17}{35} . The point on the original triangle has coordinates ( 0 , 17 35 ) (0,\frac{17}{35}) and the solution is 1000 ( 0 + 17 35 ) = 485 \lfloor 1000(0+\frac{17}{35})\rfloor = \boxed{485}

Interesting. Turns out there is usually a more clever way of doing it. I just ran the simulation at face value, which yielded the graphic in the problem.

Steven Chase - 2 years, 8 months ago

Log in to reply

An irrational slope would make this harder.

Jeremy Galvagni - 2 years, 8 months ago

Log in to reply

Would you like to post it?

Steven Chase - 2 years, 8 months ago

Log in to reply

@Steven Chase No 'cause I'm not sure I could solve it. I'm all about rational slopes. https://brilliant.org/problems/a-lot-of-reflections/?ref_id=1509291

Jeremy Galvagni - 2 years, 8 months ago
Nicola Mignoni
Oct 30, 2020

An attempt to generalize the 2D problem for a convex hull. The set of boundaries can be defined as:

B = { y 1 = a 1 + b 1 x y 2 = a 2 + b 2 x y n = a n + b n x \displaystyle B = \begin{cases} y_1 = a_1+b_1 x \\ y_2 = a_2+b_2 x \\ \quad \quad \vdots \\ y_n = a_n+b_n x \end{cases}

The initial conditions are:

P 0 = ( p x ( 0 ) , p y ( 0 ) ) \displaystyle P_0 = (p^{(0)}_x, p^{(0)}_y)

V 0 = ( v x ( 0 ) , v y ( 0 ) ) \displaystyle V_0 = (v^{(0)}_x, v^{(0)}_y)

The slope of the line l k l_k passing through P k P_k and parallel to V k V_k is m k = v y ( k ) v x ( k ) \displaystyle m_k = \frac{v^{(k)}_y}{v^{(k)}_x} , hence the line itself is

l k = m k ( x p x ( k ) ) + p y ( k ) l_k = m_k(x - p^{(k)}_x) + p^{(k)}_y

The set C k C_k of possible P k + 1 P_{k+1} candidates is

C k = { ( c x ( k , j ) , c y ( k , j ) ) = ( a j p y ( k ) + m k p x ( k ) m k b j , a j + b j a j p y ( k ) + m k p x ( k ) m k b j ) c x ( k , j ) [ min j ( a j b j ) , max j ( a j b j ) ] , c y ( k , j ) [ min j a j , max j a j ] } \displaystyle C_k = \left\{(c^{(k, j)}_x, c^{(k, j)}_y) = \left(\frac{a_j - p^{(k)}_y+m_k p^{(k)}_x}{m_k-b_j}, a_j + b_j\frac{a_j - p^{(k)}_y+m_k p^{(k)}_x}{m_k-b_j}\right) \bigg| c^{(k, j)}_x \in \left[ \min_{j} \left(-\frac{a_j}{b_j}\right), \max_{j} \left(-\frac{a_j}{b_j}\right) \right], \ c^{(k, j)}_y \in \left[ \min_{j} a_j, \max_{j} a_j \right] \right\}

In other words, each candidate c ( k , j ) c^{(k, j)} results from the intersection of P k P_k with the j j -th line in B B . But the resulting point could end up out of the hull. That is why we need to check whether the components of c ( k , j ) c^{(k, j)} are inside the region, that is delimited by the highest and lowest intersection of the lines in B B with the y y axis and the rightmost and leftmost intersection with the x x axis.

Among all the candidate points in C k C_k , P k + 1 P_{k+1} will be the one pointed by the vector V k V_k . All the points in C k C_k , in fact, lay on l k l_k , but we have to pick the one which is oriented in the sense of V k V_k . So,

P k + 1 = c ( k , j ) C k s. t. sgn ( c x ( k , j ) p x ( k ) ) = sgn ( v x ( k ) ) , sgn ( c y ( k , j ) p y ( k ) ) = sgn ( v y ( k ) ) \displaystyle P_{k+1} = c^{(k,j)} \in C_k \ \text{s. t.} \ \text{sgn}(c^{(k, j)}_x - p^{(k)}_x) = \text{sgn}(v^{(k)}_x), \ \text{sgn}(c^{(k, j)}_y - p^{(k)}_y) = \text{sgn}(v^{(k)}_y)

As for V k + 1 V_{k+1} , we need to find the new vector resulting from the bounce. If the point bounces on the x x axis,

V k + 1 = ( 1 0 0 1 ) ( v x ( k ) v y ( k ) ) = S V k = ( v x ( k ) , v y ( k ) ) \displaystyle V_{k+1} = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \begin{pmatrix} v^{(k)}_x \\ v^{(k)}_y \end{pmatrix} = S \cdot V_k = (v^{(k)}_x, -v^{(k)}_y)

So, we could rotate each line into y = 0 y=0 , change the sign of the y y coordinate of V k V_k and rotate the line again to the initial position. Each line in B B makes an angle θ j \theta_j with the x x axis, that is

θ j = tan 1 ( b j ) \displaystyle \theta_j = \tan^{-1}(b_j)

Given the rotation matrix R ( θ ) R(\theta)

R ( θ ) = ( cos θ sin θ sin θ cos θ ) R(\theta) = \begin{pmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{pmatrix}

the vector V k + 1 V_{k+1} is

V k + 1 = ( R ( θ ) S R ( θ ) ) ( V k ) = ( cos θ sin θ sin θ cos θ ) [ ( 1 0 0 1 ) [ ( cos ( θ ) sin ( θ ) sin ( θ ) cos ( θ ) ) ( v x ( k ) v y ( k ) ) ] ] \displaystyle V_{k+1} = \big(R(-\theta) \circ S \circ R(\theta)\big)(V_k) = \begin{pmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{pmatrix} \left[ \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \left[\begin{pmatrix} \cos{(-\theta)} & -\sin{(-\theta)} \\ \sin{(-\theta)} & \cos{(-\theta)} \end{pmatrix} \begin{pmatrix} v^{(k)}_x \\ v^{(k)}_y \end{pmatrix}\right] \right]

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...