/* * Simple orbit test program using Intgerator */ import uk.ac.ed.ph.integrator.*; import ptolemy.plot.*; import java.awt.Color; // Import awt color definitions. public class OrbitTest { public static void main(String args[]) { // Setup model Orbit equations with // fixed unit mass at 0.0 OrbitEquations eqn = new OrbitEquations(1.0,0.0,0.0); // Make solver with equations Integrator solver = new RungeKutta(eqn); // Integrator solver = new ImprovedEuler(eqn); (alternate call) // Make initial DataPoint with 4 parameters DataPoint initial = new DataPoint(4); initial.setX(0.0); // time initial.setY(0,0.0); // x position initial.setY(1,1.0); // y position initial.setY(2,1.2); // x velocity initial.setY(3,-0.2); // y velocity // Setup start conditions solver.setStartConditions(initial); solver.setStep(0.01); solver.setMaxStep(0.1); solver.setAccuracy(1.0e-8); // solver.setVerbose(true); // Add print monitor to print out position every // 1 unit of time solver.addMonitor(new PrintMonitor(), 1.0); // Solve for 200 time units with fixed timestep solver.solve(200.0,false); // Set up the plot Plot plot = new Plot(); // Read out x/y positions to the graph for(int i = 0; i < solver.size(); i++ ) { DataPoint p = solver.get(i); plot.addPoint(0,p.getY(0), p.getY(1),true); } plot.setTitle("Orbit Plot"); // Set plot title (optional) plot.setXLabel("X position"); // Set x label plot.setYLabel("Y position"); // Set y label // Make a frame to display the plot PlotFrame frame = new PlotFrame("A plot",plot); frame.setSize(600,600); // Set size of frame (in pixels) frame.setVisible(true); // Make frame visible } }