Simulates the movement of a projectile in 2 dimensions with a graph. Takes user input for launch velocity and height, and calculates range.
-
The program starts in Main.java and calls the input GUI.
- This launches the gui for the user to enter inputs.
(Main.java calls InputGUI.java)
-
Once the user presses submit in the input gui, it sends the info for each projectile to performCalculations.
(InputGUI.java calls Main.java)
-
performCalculations creates two calculation objects from the Calculation class, storing the data provided by input in fields.
(Main.java)
-
Two parabolas (arraylists of x, y coordinates) are made and given points with the getCurrentXDisplacement and getCurrentYDisplacement methods.
- Points are calculated for every 5 milliseconds of motion.
- These calculations are performed by the calculation objects made in step 3.
(Main.java)
-
graphFrame.add(new Graph()) is called to draw the graph and parabolas onto a window called graphFrame.
(Main.java calls into Graph.java)
-
Creating the graph makes a timer in its constructor, which increments a variable called currentPoint by 1 every 5 milliseconds.
- This happens until all points in both parabolas are accounted for.
(Graph.java)
-
At the same time, plotPoints() and makeGraph() are being repeatedly run.
- makeGraph() draw the axes and labels for the graph to the graphPanel.
- plotPoints() draws every point of the parabola up the currentPoint.
- Every time currentPoint is incremented, plotPoints can draw another point, so a new points appears every 5 milliseconds.
- This makes it appear as if the motion is being animated.
(Graph.java)
-
After all points have been plotted, the timer is stopped, and the gui to show calculations is created.
- The gui is simply a lot of text explaining both how the range calculations were performed, as well the range, time, and max height\n
- Time of flight and height were calculated and displayed for fun, as I thought it'd be cool
(Graph.java calls GUICalculations.java)
-
The input GUI remains open and every time the user presses submit in it, steps 2 through 8 are repeated
This project can be run easily without any additional setup required, all you need is java:
- Install a jdk with javac
- Compile each file in src/
- Run Main
cd src
javac Calculation.java
javac Graph.java
javac GUICalculations.java
javac InputGUI.java
javac Main.java
java MainNote: Cannot be run headless
- Perform calculations for range given a height and launch velocity
- Animate the trajectory of the projectile
- Show calculations
Simulate the motion of a projectile, given an input launch velocity and height. Show calculations to demonstrate that the output range is what you would expect.
- Code is clear with comments and appropriate variable names
- Code uses equations of motion (and not an external physics engine)
- Code can accept different inputs for launch velocity and/or height
- On-screen trajectory animation is clear and correct
- Output range and calculation to verify the range are accurate