fractalkitty looking for math? fractalkitty.com

all

two bodies with lots of bodies

#vectors#physics#image#3d#interactive#animation#data#space

ephearthstarsephArrayvelkappaloadData

let eph;
let earth;
let stars;
let ephArray = [];
let pos = [];
let vel = [];
let kappa = 6.67408e-11,
  m = 1200,
  M = 5.97219e24,
  dt = 2,
  sf = 40000;

function preload() {
  eph = loadTable("/assets/planet%20sats.csv", "csv");
  earth = loadImage("/assets/earth.jpg");
  stars = loadImage("/assets/starmap2.jpg");
}
function setup() {
  createCanvas(windowWidth, windowHeight, WEBGL);
  texture(earth);
  background(0);
  noStroke();
  loadData();
  smooth();
}

function draw() {
  orbitControl(0.5, 0.4, 0.1);
  background(0);
  push();
  texture(earth);
  sphere(6.378e6 / sf, 24, 50);
  pop();
  push();
  rotateY(frameCount / 10000);
  texture(stars);
  sphere(4000, 24, 50);
  pop();
  for (let i = 0; i < pos.length; i++) {
    r = sqrt(sq(pos[i].x) + sq(pos[i].y) + sq(pos[i].z));
    grav = -(kappa * m * M) / sq(r);
    force = createVector(
      grav * (pos[i].x / r),
      grav * (pos[i].y / r),
      grav * (pos[i].z / r)
    );
    accel = createVector(force.x / m, force.y / m, force.z / m);
    vel[i] = createVector(
      vel[i].x + accel.x * dt,
      vel[i].y + accel.y * dt,
      vel[i].z + accel.z * dt
    );
    pos[i] = createVector(
      pos[i].x + vel[i].x * dt,
      pos[i].y + vel[i].y * dt,
      pos[i].z + vel[i].z * dt
    );
    push();
    translate(pos[i].x / sf, pos[i].y / sf, pos[i].z / sf);
    normalMaterial();
    sphere(0.5, 10, 10);
    box(2, 0.5, 0);
    pop();
  }
}
function loadData() {
  ephArray = eph.getArray();
  for (let i = 0; i < ephArray.length; i++) {
    for (let j = 0; j < 6; j++) {
      pos[i] = createVector(
        float(ephArray[i][0].replaceAll(",", "")),
        float(ephArray[i][1].replaceAll(",", "")),
        float(ephArray[i][2].replaceAll(",", ""))
      );
      vel[i] = createVector(
        float(ephArray[i][3].replaceAll(",", "")),
        float(ephArray[i][4].replaceAll(",", "")),
        float(ephArray[i][5].replaceAll(",", ""))
      );
    }
  }
}