aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJaro Camphuijsen <jjecamphuijsen@gmail.com>2015-10-28 03:47:51 +0100
committerJaro Camphuijsen <jjecamphuijsen@gmail.com>2015-10-28 04:15:23 +0100
commit4666a2bd9cdec8f2a78cac716eb1ddef6d78cd9e (patch)
treedd927830dde4bcf7ca06a8806a50cc699811d878
parent388165b70514c6bb5b38f32714341dd4470afdce (diff)
Working solarsystem, closed #6
-rw-r--r--main.js23
-rw-r--r--systems.js30
2 files changed, 24 insertions, 29 deletions
diff --git a/main.js b/main.js
index b296252..ae7b747 100644
--- a/main.js
+++ b/main.js
@@ -24,8 +24,9 @@ let menuList = [
{"label":"Butterfly 1", "function": systems.genButterFly1, "args": []},
{"label":"Yin Yang 1", "function": systems.genYinYang1, "args": []},
{"label":"Goggles", "function": systems.genGoggles, "args": []},
- {"label":"Yarn", "function": systems.genYarn, "args": []}
- // {"label":"Solar System", "function": systems.genSolarSystem, "args": [true] }
+ {"label":"Yarn", "function": systems.genYarn, "args": []},
+ {"label":"Solar System", "function": systems.genSolarSystem, "args": [true] }
+
];
gui(menuList);
@@ -43,7 +44,7 @@ function gui(buttonList) {
.attr("class", "menuSvg");
var buttons = menuSvg.selectAll(".button")
- .data(menuList);
+ .data(menuList)
buttons.enter()
.append("g")
@@ -99,6 +100,13 @@ function simulate(sysFunc, args){
if (system.hasOwnProperty("stepsPerFrame")) {
steps = system.stepsPerFrame;
}
+ // if (system.hasOwnProperty("scaleposition")) {
+ // for (b in system.bodies){
+ // b.set(system.scalePosition(b.r),b.v);
+
+ // }
+ // // console.log()
+ // }
else { steps = 1; }
[spheres] = init();
animate_leapfrog();
@@ -144,7 +152,7 @@ function init() {
sun.material.emissive.set(0xfcd440);
// sunlight
- let light = new THREE.PointLight(0xfcd440, 2, 2000);
+ let light = new THREE.PointLight(0xfcd440, 2, 8000);
sun.add(light);
// sun glow
@@ -167,7 +175,6 @@ function init() {
scene.add(ambient);
}
-
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0x000000);
renderer.setSize(window.innerWidth, window.innerHeight);
@@ -191,11 +198,13 @@ function animate() {
for (let i = 0; i < steps; i ++) {
bodies = calc.symplectic_euler(bodies, system.stepsize);
}
+
- [bodies, spheres] = calc.removeLostBodies(bodies, spheres, scene, 2000);
+ // [bodies, spheres] = calc.removeLostBodies(bodies, spheres, scene, 2000);
for (let i = 0; i < bodies.length; i++) {
- let pos = bodies[i].r;
+ let pos = bodies[i].r.clone();
+
if (system.hasOwnProperty("scalePosition")) {
pos = system.scalePosition(pos);
}
diff --git a/systems.js b/systems.js
index b791228..9b6e7db 100644
--- a/systems.js
+++ b/systems.js
@@ -152,39 +152,25 @@ export function genSolarSystem(sunOn) {
"pluto",
new Vec3());
- let bodies = [sun, mercury, venus, earth, mars, jupiter, saturn, uranus,
- neptune, pluto];
+
// let bodies = [sun, mercury, venus, earth];
+ let bodies = [sun, mercury, venus, earth, moon, mars, jupiter, saturn, uranus, neptune, pluto];
let scaleRadius = rad => Math.pow(rad, 1/5);
- let scaleFactor = 1E-9;
-
- // copy bodies
- let b = [];
- for (let e of bodies) {
- b.push(e);
+ for (let b of bodies) {
+ b.rad = scaleRadius(b.rad);
}
function sqrtVec(vec) {
return new Vec3(Math.sqrt(vec.x), Math.sqrt(vec.y), Math.sqrt(vec.z));
}
- // try to scale quantities keeping physical proportions
- for (let i = 0; i < bodies.length; i++) {
- b[i].rad = scaleRadius(b[i].rad);
- b[i].r = b[i].r.multiplyScalar(scaleFactor);
- b[i].m = b[i].m * Math.pow(scaleFactor, 2);
- // F = mv^2 / r -> v = sqrt( a * r)
- b[i].v = calc.accel(i, bodies).multiply(b[i].r);
- }
- console.log(b);
-
return {
- bodies: b,
+ bodies: bodies,
// stepsize: 10000. * (60 * 60 * 24),
- stepsize: 1,
- stepsPerFrame: 1,
- // scalePosition: vec => vec.multiplyScalar(1E-08),
+ stepsize: .1 * (60 * 60 * 24),
+ stepsPerFrame: 1 ,
+ scalePosition: vec => vec.multiplyScalar(2 * 1E-09),
// scalePosition: vec => vec.setLength(Math.pow(vec.length(), 1/6)),
// scalePosition: vec => vec.setLength(Math.log(vec.length)/Math.log(1.4)),
camera: {x: 0, y: 0, z: 1300},