Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello I really need your help with this problem that I am having. I have to make a Windows Form application where an image bounces around in the window. I have the bouncing around part done, but the next part of the assignment is to make it so that the user can adjust the speed and also the angle of the image. I have done the speed, but I cannot figure out a way for the angle to be changed so that the speed remains the same.
Please, I really need help on how to change the angle of the bouncing image
Thanks.
Posted

1 solution

I think that you may be making this problem too hard by worrying excessively about it.

In a bouncing ball problem you only have a couple of factors to worry about. First, you have an initial speed and angle of launch; together they form a velocity, a vector quantity. As your object moves, it's subject only to momentum and the downward force of gravity. When it strikes a solid object, such as a wall or ceiling, it is reflected at an angle equal to the angle of incidence, but with no loss of energy (assuming, as most homework problems do, no frictional losses and perfect elasticity). Because velocity is a vector quantity, but speed is a scalar value, to hold your speed constant, you have to change your vertical and horizontal speeds as the angle of incidence changes in order to keep your speed along the path of travel constant. This is going to require a bit of trigonometry.

Given a speed of S, the horizontal and vertical components of the velocity vector are given by:

Vh = S*cos(Φ)
Vv = S*sin(Φ)

As time passes, the vertical component will diminish because of the effect of gravity, but the horizontal component will not, because there is no force being applied to reduce it. For your application, first convert the speed and angle entered by the user to vector quantities, then calculate the trajectory on the incident surfaces accordingly. It's not a small problem, but it's not too hard to solve, either, given a bit of mathematical preparation. You can do it! And I look forward to your post about the solution in the programming forums.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900