Title: Physics Simulations
1Physics Simulations
- In this lab class we will be creating Simulations
of Gravitational Systems. This will involve
several steps - Analysis of Problem
- Design of Appropriate Classes
- Member Variables
- Constructors
- Methods
- etc.
- Code should be reusable
- Testing Code
2Previous Work
- Assume understood and completed 281
- Need to be able create classes
- Graphics
- Mathematical Calculations
3Grading
- 100 Course Work
- divided into 5 weekly projects and final report
on project. - Will need to document all code.
- Please back up all of your code onto floppy disks
4Course Outline
- Week 1
- Class Design ThreeVector Class
- Class Design of MassiveObject Class
- Class Design of GravitationalForceField
- Create ThreeVector Class with following
properties - dotProduct
- set
- add
- subtract
- cross product
- print
- get
- magnitude
- scalar multiplication
5Course Outline
- Week 2
- Physics Simulation issues
- Simulate Massive Object on Earths Surface in 2d
- Week 3
- Simulation of 2D orbiting bodies
- Simulation of object in tunnel through center of
earth - Week 4
- Simulate 3 bodies in 3D
- simulate N bodies in 3D
- Week 5 Flashy Graphics..
6Gravitation
- Force on a massive object depends on all the
massive objects in the system. - What properties does a Gravitational Object have?
7Potential and Force
- Given a Potential Field G(x,y,z) the force is
given by the three dimensional vector derivative - Requires mathematical calculation of the
derivatives of a function - We can create a force field class instead.
8Class Design
- Class Design ThreeVector Class
- Class Design of MassiveObject Class
- Class Design of GravitationalForceField
- Work together on what are the properties
required. - Will need to write up your design in your log
book.
9Implementation of Vector Class
- Member Variables should be private
- allows you to change implementation without
changing user code - Access all variables via public methods
- Document your code.
- Write a class to test your code
- What are appropriate tests?
10Example of Documented Code
/ An example of documented code _at_author
Iain Bertram _at_version 1.0 / public class
Sample private double myVariable /
The Default Constructor, set to zero
/ public Sample() this.myVariable
0.0 / Constructor that sets a
value / public Sample(double
setValue) this.myVariable setValue
11Continued
/ Method to obtain the value stored in
the class / public double getVariable()double
argthis.myVariable return arg /
Method to set variable / public void
setVariable(double setValue) this.myVariable
setValue / Method to print Variable
/ public void print() System.out.print("The
variable is "this.myVariable"\n")