forked from CSE2102Fall2015/2015JAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creation of ThreeBodyAPL and ThreeBodyExample main class. Most of the
ThreeBodyExample class is the same as the TwoBodyExample class, and will be further elaborated later on after a model of the Three Body Gravitational problem is defined.
- Loading branch information
John Costa III
authored and
John Costa III
committed
Nov 28, 2015
1 parent
2a58e74
commit 36c17cd
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package jat.examples.ThreeBodyExample; | ||
|
||
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; | ||
|
||
import jat.coreNOSA.cm.ThreeBody; | ||
|
||
public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEquations{ | ||
|
||
public ThreeBodyAPL(double G, double m1, double m2, double m3) { | ||
super(G, m1, m2, m3); | ||
} | ||
|
||
@Override | ||
public void computeDerivatives(double arg0, double[] arg1, double[] arg2) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public int getDimension() { | ||
// TODO Auto-generated method stub | ||
return 6; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package jat.examples.ThreeBodyExample; | ||
|
||
import jat.core.cm.TwoBodyAPL; | ||
import jat.core.plot.plot.FrameView; | ||
import jat.core.plot.plot.Plot2DPanel; | ||
import jat.core.plot.plot.PlotPanel; | ||
import jat.core.plot.plot.plots.ScatterPlot; | ||
import jat.examples.TwoBodyExample.TwoBodyExample; | ||
|
||
import java.awt.Color; | ||
import java.text.DecimalFormat; | ||
|
||
import javax.swing.JFrame; | ||
|
||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.apache.commons.math3.linear.ArrayRealVector; | ||
import org.apache.commons.math3.linear.RealVectorFormat; | ||
import org.apache.commons.math3.ode.FirstOrderIntegrator; | ||
import org.apache.commons.math3.ode.nonstiff.DormandPrince853Integrator; | ||
|
||
public class ThreeBodyExample { | ||
public ThreeBodyExample() { | ||
} | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
ThreeBodyExample x = new ThreeBodyExample(); | ||
|
||
// create a TwoBody orbit using orbit elements | ||
ThreeBodyAPL sat = new ThreeBodyAPL(10, 0.3, 1.0, 2.0); | ||
|
||
double[] y = sat.randv(); | ||
|
||
ArrayRealVector v = new ArrayRealVector(y); | ||
|
||
DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00"); | ||
RealVectorFormat format = new RealVectorFormat(df2); | ||
System.out.println(format.format(v)); | ||
|
||
// find out the period of the orbit | ||
double period = sat.period(); | ||
|
||
// set the final time = one orbit period | ||
double tf = period; | ||
|
||
// set the initial time to zero | ||
double t0 = 0.0; | ||
|
||
// propagate the orbit | ||
FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10); | ||
dp853.addStepHandler(sat.stepHandler); | ||
// double[] y = new double[] { 7000.0, 0, 0, .0, 8, 0 }; // initial | ||
// state | ||
|
||
dp853.integrate(sat, 0.0, y, 8000, y); // now y contains final state at | ||
// tf | ||
|
||
Double[] objArray = sat.time.toArray(new Double[sat.time.size()]); | ||
double[] timeArray = ArrayUtils.toPrimitive(objArray); | ||
double[] xsolArray = ArrayUtils.toPrimitive(sat.xsol.toArray(new Double[sat.time.size()])); | ||
double[] ysolArray = ArrayUtils.toPrimitive(sat.ysol.toArray(new Double[sat.time.size()])); | ||
|
||
double[][] XY = new double[timeArray.length][2]; | ||
|
||
// int a=0; | ||
// System.arraycopy(timeArray,0,XY[a],0,timeArray.length); | ||
// System.arraycopy(ysolArray,0,XY[1],0,ysolArray.length); | ||
|
||
for (int i = 0; i < timeArray.length; i++) { | ||
XY[i][0] = xsolArray[i]; | ||
XY[i][1] = ysolArray[i]; | ||
} | ||
|
||
Plot2DPanel p = new Plot2DPanel(); | ||
|
||
// Plot2DPanel p = new Plot2DPanel(min, max, axesScales, axesLabels); | ||
|
||
ScatterPlot s = new ScatterPlot("orbit", Color.RED, XY); | ||
// LinePlot l = new LinePlot("sin", Color.RED, XY); | ||
// l.closed_curve = false; | ||
// l.draw_dot = true; | ||
p.addPlot(s); | ||
p.setLegendOrientation(PlotPanel.SOUTH); | ||
double plotSize = 10000.; | ||
double[] min = { -plotSize, -plotSize }; | ||
double[] max = { plotSize, plotSize }; | ||
p.setFixedBounds(min, max); | ||
|
||
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
|
||
System.out.println("end"); | ||
|
||
} | ||
|
||
} |