
Dhea H.
asked 06/04/20What is the Formula of getting the x,y of a point when a ball is colliding inside the rectangle
Simulation Scenario:
I have 900x600 size of a rectangle
The first angle of the ball when bouncing the edge of the rectangle is 40degrees.
Starting position of the ball is:
Px = 500
Py = 450 (edited)
Assuming there is no friction or gravity as I just want to simulate the path of the ball.
What are the points when the ball reaches to the wall as it bounces 5x of the rectangle?
How to get the reflection points that are located at the sides of the table?
Thank you.
3 Answers By Expert Tutors
Tom K. answered 06/04/20
Knowledgeable and Friendly Math and Statistics Tutor
Each reflection switches the slope from tan 40° to - tan 40° and back, where we may be moving in either direction along the line. We just have to calculate the y coordinate where we would hit the sides; if the y-value is between 0 and 600, that is where we hit the side; if not, then we will be hitting the bottom/top. When you hit the side, you switch the x-target; when you hit the bottom/top, you switch the y-target.
All calculation are carried out "exactly", not just the numbers shown.
I calculated if you hit the side using if y + slope * (x-target - x) between 0 and 600, you reach x-target; otherwise, you reach y-target.
The table has 6 columns, x, y, slope, x target, y target, target reached (x or y); using the x, y, slope, and target reached, we can determine the x and y on the next row. A picture of the table has too many digits. I will give the (x,y) coordinates.
(500,450), (679,600), (900,414), (406,0), (0,341)
Dhea H.
Hi Tom, Can you explain more on how did you come up these coordinates (500,450), (679,600), (900,414), (406,0), (0,341)? Thank You06/04/20
Tom K.
The first point is the starting point. You go until you either reach the top or the right. In this case, to reach the right, you would have to be far above 600, so you reach 600 first (at 679, 600; remember slope is .8391), then you reflect and are moving at slope -.8391 to the right and reach (900,414); you then have slope .8391 until you reach (406, 0), ...I can provide an Excel sheet with formulas.06/07/20

William W. answered 06/04/20
Top Pre-Calc Tutor
If there is no loss due to friction (or other type losses), then the angle of incidence equals the angle of reflection.
tan(40°) = 150/x
x = 150/tan(40°)
x = 125.865
Dhea H.
Hi William, How do I get the next 4-5 bounding points based on the angle of reflection when it bounces back to the side, bottom etc.? And what if this 40 degrees angle will position at the bottom right and it bounces first at the right side of the table going to the top? In calculating the next bounding points, what is the best technique in getting the reflected angle? Thanks in advance.06/04/20

Logan B. answered 06/04/20
Intuitive Mathematics Instructor Focused on Advanced Mathematics
Here's a brief (not-to-scale) illustration of the problem, along with a bit of the initial trajectory. Keep in mind that the angle of incidence, that is, the angle at which the ball strikes the edge, will equal the angle of reflection: https://imgur.com/l42E6s3
I've isolated the right triangle there so we can see how far to the right our ball travels for the amount the ball goes up. To find the points at which the ball strikes the edges, we can actually use a nifty construction that makes the problem a whole lot easier. Instead of confining ourselves to the box, we can reflect the whole system up and to the right, over and over, to get an infinite grid of boxes. Then we can just extend the initial trajectory. Each time this line crosses a vertical line corresponds to a reflection off of one of the right or left edges. Likewise, each time the line crosses a horizontal line corresponds to a reflection off of the top or bottom of the original box. I've circled the matching intersection/reflection pairs in the following image: https://imgur.com/QCONvt8
Note also that I put in a parametric equation for the extended trajectory line, based on the initial position and the constructed right triangle.
There's some important notes. Since every vertical line corresponds to a reflection off of one of the vertical edges of the box, the relative horizontal positioning of the trajectory in the initial box will flip every time the extended trajectory line crosses a vertical line. Likewise, since every horizontal line corresponds to a reflection off of one of the horizontal edges of the box, the relative vertical positioning of the trajectory in the initial box will flip every time the extended trajectory crosses a horizontal line.
We can use this now to create some equations that will tell us where the ball is and how many times the ball has reflected off of an edge. First, we get the number of times v that the extended trajectory line crosses a vertical line, which are all spaced out by 900 units. This is accomplished by looking at the x coordinate of the extended trajectory line, dividing it by 900, and taking the floor (i.e., the largest integer which is less than the quotient):
- v = floor((500 + 150cot(40 deg)*t)/900)
Similarly, the number of times h that the extended trajectory line crosses a horizontal line, which are all spaced out by 600 units, is obtained by dividing the y coordinate of the extended trajectory line, dividing it by 600, and taking the floor:
- h = floor((450 + 150*t)/600)
This means that the total number of reflections is v + h. However, we also need to get the coordinates of the ball within the initial box. We start with v = h = 0, so when v is even, the relative horizontal position of the ball is unchanged, while when v is odd, the relative horizontal position of the ball is flipped. The same behavior exists for h and the relative vertical position. The relative position is conveyed by the decimal part (denoted by curly brackets, {x}) of the quotients used to compute v and h. So we have the following rules:
- When v is odd, the x coordinate of the ball is 900 - 900*{(500 + 150cot(40 deg)*t)/900}
- When v is even, the x coordinate of the ball is 900*{(500 + 150cot(40 deg)*t)/900}
- When h is odd, the y coordinate of the ball is 600 - 600*{(450 + 150*t)/600}
- When h is even, the y coordinate of the ball is 600*{(450 + 150*t)/600}
These can be combined into a single formula, but it isn't all too pretty. So we'll leave it there.
We can use algebra (or WolframAlpha) to compute when v + h = floor((500 + 150cot(40 deg)*t)/900) + floor((450 + 150*t)/600) reaches values 1, 2, 3, 4, 5; and then follow the above rules to find the reflection points. It's possible to program this, but there are special considerations for other possible arrangements of the rectangle and ball which make a general program more tricky to write.
Here are the values for the collisions:
- t = 1, first collision, (678.763, 600)
- t = 8*tan(40 deg)/3, second collision, (900, 414.4)
- t = 5, third collision, (406.2, 0)
- t = 26*tan(40 deg)/3, fourth collision, (0, 340.8)
- t = 9, fifth collision, (308.9, 600)
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Logan B.
Is the 900 x 600 in the format height x width? If not, then you may have the initial position of the ball mis-typed.06/04/20