COS - nbody outline

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

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

View Full Document Right Arrow Icon
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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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 &lt; planets.txt Sheet1 Page 2 i++) j++) i &lt; N i++){ j &lt; N j++){...
View Full Document

Page1 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online