Skip to content

Graham277/Projectile-Motion-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Projectile Motion Simulator by Graham - SPH4U Strand 1 Task

What does it do?

Simulates the movement of a projectile in 2 dimensions with a graph. Takes user input for launch velocity and height, and calculates range.

How does it work?

  1. 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)

  2. Once the user presses submit in the input gui, it sends the info for each projectile to performCalculations.

    (InputGUI.java calls Main.java)

  3. performCalculations creates two calculation objects from the Calculation class, storing the data provided by input in fields.

    (Main.java)

  4. 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)

  5. graphFrame.add(new Graph()) is called to draw the graph and parabolas onto a window called graphFrame.

    (Main.java calls into Graph.java)

  6. 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)

  7. 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)

  8. 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)

  9. The input GUI remains open and every time the user presses submit in it, steps 2 through 8 are repeated

How to run this?

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 Main

Note: Cannot be run headless

What are the requirements for the project?

  • Perform calculations for range given a height and launch velocity
  • Animate the trajectory of the projectile
  • Show calculations

Assessment criteria

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages