COS - nbody outline

# COS - nbody outline - for(int i = 0 for(int j = 0 Double fx...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 read N, R declare arrays based on N loop read N lines Cue Music Set up canvas (set scale) infinite loop: update positions redraw canvas >> draw starfield, draw each body, then use StdDraw.show(DISPLAY_TIME) [declare int DISPLAY_TIME = 30 fx[i][j] --> body i acting on body j fy[i][j] for (i = 0, i < for (int j = 0, i < N if (i != j){ find dx, dy r = Math.sqrt(dx*dx + dy*dy) fx[i][j] = G * m[i] *m[j] * dx/(r*r*r)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (int i = 0 for (int j = 0 Double fx = new Double[i][j] Double fy = new Double[i][j] if (i != j){ double dx = rx[i] - rx[j] double dy = ry[i] - ry[j] double r = Math.sqrt(dx*dx + dy*dy) fx[i][j] = G * mass[i] * mass[j] * dx / (r*r*r) fy[i][j] = G * mass[i] * mass[j] * dy / (r*r*r) } } } java NBody < planets.txt Sheet1 Page 2 i++) j++) i < N i++){ j < N j++){...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

COS - nbody outline - for(int i = 0 for(int j = 0 Double fx...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online