Inspiration

The inspiration for this project came from our collective interest in the area of physics. We thought that simulating projectile motion would make both an interesting project and challenging project for us to do. We found another project that did this and added modifications to improve it. Original Code: https://stackoverflow.com/questions/21783858/how-to-code-the-projectile-of-a-ball-of-different-force-and-angle-in-java-swing

Project explanation

Our project is a Java program that simulates the projectile motion of a ball based on user input. It is a modified and improved version of another project that simulates the motion of a ball with projectile motion. The original project allowed the user to manipulate the starting angle and initial velocity values. Our project added an initial height slider and a starting x slider to provide more options to the user and simulate more situations. Additionally, we calculated some useful values with the given inputs such as air time, max height, and horizontal distance. The program shows a ball being shot through the air to simulate the path that the ball would take.

The main structure of this project includes multiple classes that interact with each other to record values, calculate positions, and draw images at specified intervals To ensure a proper runtime result, the project runs threads using the run() method to make sure everything is run before it creates an output. It also helps improve program performance. This program used the java.awt library and the javax.swing library to create the GUI that would show the motion of the ball and allow the user to use sliders to input information. The swing library allowed us to add more panels and labels with information.

To calculate the position of the ball, the program used objects from the Point2D class and methods from the AffineTransform class. To accurately draw the ball, the program uses the built-in system time to decide when to draw another instance of the ball. The executeShot() method helps pass the position of the ball into other methods to calculate a new position. The paintComponent method was used to draw the ball on the panel on the GUI. Additionally, the project used various methods from the math class to calculate useful values using physics equations.

Overall, although we didn’t create the main functionality of the project, we added additional features to increase its usability for the user.

Challenges we ran into

When testing the different functions of the method, Eclipse crashed due to the heavy usage of memory. This wasn't a large issue, but it was something that we dealt with. In the program specifically, we had some issues with the mathematical representation (through projectile motion formulas) and implementing the initial height. After testing different ideas, we realized that some of the methods accepted parameters that were different from what we originally thought. There was also an issue with variable scope that was fixed by the use of methods.

Accomplishments that we're proud of

We were able to turn a very general idea into something tangible. Our group was unable to come up with a good idea for the lab simulation, but we started to gain momentum after the idea of projectile motion. All of our group members also contributed significantly to the project. We applied our knowledge of what we learned in math (and physics) into a useful program for physics students studying projectile motion. We added some new features that included allowing the user to input initial vertical and horizontal distances. We also calculated the values of air time, max height, and range with values given by the user. Although we didn't create the entire project, we added features that made it into an improved version.

The Future of Projectile Motion Simulator

Looking at this from a gaming perspective, the projectile motion simulator can be implemented in an Angry Birds-like game, with the same projectile motion physics and aspects of code but combined with physics and code which would simulate collision with objects. The user would be able to adjust the angle, velocity, and the position of the projectile, similar to what is displayed in our project, in order to knock down certain targets similar to the Angry Birds games.

Built With

Share this project:

Updates