/* From: "COMPUTATIONAL PHYSICS, 2nd Ed" by RH Landau, MJ Paez, and CC Bordeianu Copyright Wiley-VCH 2007. Electronic Materials copyright: R Landau, Oregon State Univ, 2007; MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. Support by National Science Foundation */ // Moon.java: moon orbiting a planet import ptolemy.plot.*; public class Moon { public static void main(String[] argv) { double Radius, wplanet; // Planet's orbit r, ang. velocity double radius, wmoon; // Moon's r, omega wrt planet double time, x, y; // Position(t) of moon Radius = 4. ; // Planet wplanet = 2. ; // Omega of planet radius = 1. ; // Moon's orbit r wmoon = 14. ; // Oemga moon wrt planet Plot myPlot = new Plot(); myPlot.setTitle("Motion of a moon around a planet "); myPlot.setXLabel(" x"); myPlot.setYLabel(" y"); // Orbit for ( time = 0. ; time < 3.2; time = time + 0.02) { x = Radius *Math.cos(wplanet*time)+radius*Math.cos(wmoon*time); y = Radius *Math.sin(wplanet*time)+radius*Math.sin(wmoon*time); myPlot.addPoint(0, x, y, true); } PlotApplication app = new PlotApplication(myPlot); } }