// Gravitational field of a point earth. // Illustrates simple three dimensional // plotting routines. #include using namespace std; const double km = 1000; // Note this procedure! // An alternate naming // convention capitalizes // all global constants const double gravitationalConstant = 6.67e-11; const double earthMass = 5.97e24; const double earthRadius = 6380 * km; const int matSize = 20; // This MUST be declared a const int // to be used in the subsequent // type statements ! double gravitationalField (double aX, double aY) { return gravitationalConstant * earthMass / (aX * aX + aY * aY); } int main() { double position[matSize]; // x and y coordinate space float offset = matSize / 2 - 0.5; // Determines the starting // point of the grid for (int loop = 0; loop < matSize; loop++) position[loop] = 0.1 * earthRadius * (loop - offset); float x, y; for (int outerLoop = 0; outerLoop < matSize; outerLoop++) { x = position[outerLoop]; for (int innerLoop = 0; innerLoop < matSize; innerLoop++) { y = position[innerLoop]; cout << x << " " << y << " " << gravitationalField(x,y) << endl; } } }