cs61b Project0:NBody Simulation

1.Planet.java代码

public class Planet{ public double xxPos; public double yyPos; public double xxVel; public double yyVel; public double mass; public String imgFileName; private static final double G = 6.67e-11; public Planet(double xP,double yP,double xV,double yV,double m,String img){ xxPos = xP; yyPos = yP; xxVel = xV; yyVel = yV; mass = m; imgFileName = img; } public Planet(Planet p){ this(p.xxPos,p.yyPos,p.xxVel,p.yyVel,p.mass,p.imgFileName); }public double calcDistance(Planet p){ return Math.pow((Math.pow((this.xxPos-p.xxPos),2)+Math.pow((this.yyPos-p.yyPos),2)),1.0/2); }public double calcForceExertedBy(Planet p){ return (this.mass*p.mass*G)/Math.pow(this.calcDistance(p),2); }public double calcForceExertedByX(Planet p){ return this.calcForceExertedBy(p)*(p.xxPos-this.xxPos)/this.calcDistance(p); }public double calcForceExertedByY(Planet p){ return this.calcForceExertedBy(p)*(p.yyPos-this.yyPos)/this.calcDistance(p); }public double calcNetForceExertedByX(Planet[] p){ double NetExertedByX=0; for(int i=0; i【cs61b Project0:NBody Simulation】

2.NBody.java代码
public class NBody{public static double readRadius(String path){ In in =new In(path); int firstinteger=in.readInt(); double ReadRadius=in.readDouble(); return ReadRadius; }public static Planet[] readPlanets(String path){ In in=new In(path); int numbersum=in.readInt(); Planet[] p =new Planet[numbersum]; double ReadRadius=in.readDouble(); for(int i=0; i

    推荐阅读