/*	Planet.java*/import Vec3D;class Planet{	/*	A Planet is a body from which a Rocket is launched.  It is assumed		that the planet is the only relevant gravitational attractor in		the Rocket's environment.  A Planet can calculate the gravitational		force and air drag vectors, given a position and velocity.	*/		public double radius;		// mean surface radius (m)	public double G;			// accel. due to gravity at surface (m/s^2)	public double airDensity;	// air density (kg/m^3) at surface	public double airFalloff;	// height to 1/e air density (m)		// constructors	public Planet()		// by default, construct Earth	{ radius = 6378150; G = 9.8; airDensity = 1.29; airFalloff = 8000; }	public Planet(double pRadius, double pG, double pAir, double pFalloff)	{ radius = pRadius; G = pG; airDensity = pAir; airFalloff = pFalloff; }		public Vec3D GetGravity( Vec3D position, double mass )	{		// gravity falls with the square of the distance from the center		// but we'll assume it doesn't increase if you're below ground!		double r = position.Length();	// radius from center of planet		double a;						// acceleration		if (r <= radius) a = G;		else a = G * radius*radius / (r*r);				// Now we have the acceleration; we need to compute the force		// vector.  Since position is relative to our center, the		// direction is simply the inverse of this position.		// We normalize (divide by its length), then multiply by		// the magnitude of the force (F=ma).				return position.Times(-mass*a/radius);	}		public double GetAirDensity( Vec3D position )	{	return GetAirDensity( position.Length() - radius ); }		public double GetAirDensity( double altitude )	{		if (altitude < 10) return airDensity;				// I assume that air density falls off exponentially:		return airDensity / Math.exp( altitude / airFalloff );	}		public double GetAirDrag( Vec3D position, Vec3D velocity,			double cd, double area )	{ return GetAirDrag( position.Length() - radius,				velocity.Length(), cd, area ); }		public double GetAirDrag( double altitude, double speed,			double cd, double area )	{		// I'll assume basic Newtonian drag for now:		return speed*speed * area * cd * GetAirDensity(altitude) / 2.0;	}}