aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrahiel <rahiel@protonmail.ch>2015-10-21 21:31:10 +0200
committerrahiel <rahiel@protonmail.ch>2015-10-21 21:33:11 +0200
commit51f77c0035693d5ef9393b65ffd56d51eec4b861 (patch)
tree1dc18e551afeeb416bff279bb364fb02ff04833e
parentd59e570b3929b7b96c2517403e35dcbf29e18d1e (diff)
#6: scaled down solar system (also doesn't work)
-rw-r--r--calc.js2
-rw-r--r--systems.js32
2 files changed, 25 insertions, 9 deletions
diff --git a/calc.js b/calc.js
index ab35efc..0a7db19 100644
--- a/calc.js
+++ b/calc.js
@@ -4,7 +4,7 @@ import Body from "./systems.js";
export const G = 6.67408E-11;
-function accel(i, b) {
+export function accel(i, b) {
// Compute acceleration due to gravity on body i by all other bodies
let a = new Vec3(0, 0, 0);
for (let j = 0; j < b.length; j++) {
diff --git a/systems.js b/systems.js
index 3b84773..fa8bb72 100644
--- a/systems.js
+++ b/systems.js
@@ -155,23 +155,39 @@ 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, mars, jupiter, saturn, uranus,
+ neptune, pluto];
+ // let bodies = [sun, mercury, venus, earth];
let scaleRadius = rad => Math.pow(rad, 1/5);
+ let scaleFactor = 1E-9;
- for (let b of bodies) {
- b.rad = scaleRadius(b.rad);
+ // copy bodies
+ let b = [];
+ for (let e of bodies) {
+ b.push(e);
}
+ 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: bodies,
+ bodies: b,
// stepsize: 10000. * (60 * 60 * 24),
- stepsize: 10,
+ stepsize: 1,
stepsPerFrame: 1,
- scalePosition: vec => vec.multiplyScalar(1E-08),
+ // scalePosition: vec => vec.multiplyScalar(1E-08),
// 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},