diff --git a/Physics/MovingParticles.mch b/Physics/MovingParticles.mch index 60cfdf00dc9dcf3feed2b36bef8723a0a275cde6..5bd288488156fc80ea0ed15441264a4254cc9e6e 100644 --- a/Physics/MovingParticles.mch +++ b/Physics/MovingParticles.mch @@ -1,7 +1,7 @@ MACHINE MovingParticles INCLUDES Vectors DEFINITIONS - "LibraryReals.def"; + "LibraryReals.def"; "SORT.def"; MASS == FLOAT; POS == FLOAT; SPEED == FLOAT; @@ -10,13 +10,25 @@ DEFINITIONS SCALE == 1.25e11; // 100 % in visualisation SCALE100 == (SCALE/100.0); SPEED_MULTIPLIER == 1000000.0; - MAXMASS == 1.989e30 - + GRAV_MULTIPLIER == 1000000000000.0; + MAXMASS == 1.989e30; + + gravitation == %i.(i:OBJ | sigma_vecs( + SQUASH( + %j.(j:OBJ & j/=i | + times_vec( force_between(i,j,pos(i),pos(j)) / mass(i) , + unit_vec(delta_vec(pos(j),pos(i))))) + ) ) ) // acceleration +ABSTRACT_CONSTANTS + force_between CONSTANTS mass, nobjs PROPERTIES nobjs : 1..10 & mass : OBJ --> MASS & - + + force_between = %(a,b,pa,pb).(a:OBJ & b:OBJ & a/=b | (G * mass(a) * mass(b)) / (distance(pa,pb)**2)) + + & n = 2 & // two dimensional space nobjs = 3 & mass = [5.97e24, 1.989e30, 1.989e30] VARIABLES pos, speed @@ -27,9 +39,10 @@ INITIALISATION pos := [ [0.0,0.0] , [0.0,4.5e10] , [0.0,-4.5e10 ] ] || speed := [ [0.05e04,0.0], [3.0e04,0.0], [-3.0e04,0.0] ] OPERATIONS r <-- ForceBetween(a,b) = PRE a:OBJ & b:OBJ & a/= b THEN - r := (G * mass(a) * mass(b)) / (distance(pos(a),pos(b))**2) + r := force_between(a,b,pos(a),pos(b)) END; - Move(delta) = PRE delta:REAL & delta = 100000.0 THEN + Move(delta) = PRE delta:REAL & delta = 10000.0 THEN + speed := %i.(i:OBJ | add_vec(speed(i),times_vec(delta,gravitation(i)) )) || pos := %i.(i:OBJ | add_vec(pos(i),times_vec(delta,speed(i))) ) END END diff --git a/Physics/Vectors.mch b/Physics/Vectors.mch index 53807d4d47a512067f6930351261b8bb7e755538..369ca3d09a8da78b633f9e3ce0dca615e2d321ec 100644 --- a/Physics/Vectors.mch +++ b/Physics/Vectors.mch @@ -13,7 +13,9 @@ ABSTRACT_CONSTANTS distance, add_first, - sigma_reals + sigma_reals, + add_firstv, + sigma_vecs PROPERTIES n:NATURAL1 & DIM = (1..n) & @@ -22,6 +24,9 @@ PROPERTIES add_first = %v.(v:seq1(REAL) | (v(1)+v(2)) -> tail(tail(v))) & sigma_reals = %v.(v:VEC | (iterate(add_first,n-1)(v))(1)) & + add_firstv = %v.(v:seq1(VEC) | add_vec(v(1),v(2)) -> tail(tail(v))) & + sigma_vecs = %v.(v:seq1(VEC) | (iterate(add_firstv,size(v)-1)(v))(1)) & + add_vec = %(v1,v2).(v1:VEC & v2:VEC | %i.(i:DIM| v1(i)+v2(i))) & delta_vec = %(v1,v2).(v1:VEC & v2:VEC | %i.(i:DIM| v1(i)-v2(i))) & // dot_product = %(v1,v2).(v1:VEC & v2:VEC | SIGMA(i).(i:DIM| v1(i)*v2(i))) & diff --git a/Physics/three_bodies.json b/Physics/three_bodies.json index 221fce5415c857b3e02ee540ed1930049d5a2375..d620b46d0e095262392035a590f973e12611430d 100644 --- a/Physics/three_bodies.json +++ b/Physics/three_bodies.json @@ -44,6 +44,31 @@ "id": "speed%0", "attr": "y2", "value" : "(pos(%0)(2)+ SPEED_MULTIPLIER*speed(%0)(2)) / SCALE100" + }, + + { + "for": {"from":1, "to":3}, + "id": "gravitation%0", + "attr": "x1", + "value" : "pos(%0)(1) / SCALE100" + }, + { + "for": {"from":1, "to":3}, + "id": "gravitation%0", + "attr": "y1", + "value" : "pos(%0)(2) / SCALE100" + }, + { + "for": {"from":1, "to":3}, + "id": "gravitation%0", + "attr": "x2", + "value" : "(pos(%0)(1)+ GRAV_MULTIPLIER*gravitation(%0)(1)) / SCALE100" + }, + { + "for": {"from":1, "to":3}, + "id": "gravitation%0", + "attr": "y2", + "value" : "(pos(%0)(2)+ GRAV_MULTIPLIER*gravitation(%0)(2)) / SCALE100" } ], "events": [ diff --git a/Physics/three_bodies.svg b/Physics/three_bodies.svg index 3f84ed9b7e942a49f98c52b4eff4fe7979456eb3..f451a986e74a206b31de6c8fd1faad6c6af38605 100644 --- a/Physics/three_bodies.svg +++ b/Physics/three_bodies.svg @@ -14,12 +14,12 @@ <marker id="startarrow" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto"> - <polygon points="10 0, 10 7, 0 3.5" fill="blue" /> + <polygon points="10 0, 10 7, 0 3.5" fill="green" /> </marker> <marker id="endarrow" markerWidth="10" markerHeight="7" refX="0" refY="3.5" orient="auto"> - <polygon points="0 0, 10 3.5, 0 7" fill="blue" /> + <polygon points="0 0, 10 3.5, 0 7" fill="green" /> </marker> </defs> @@ -46,5 +46,18 @@ stroke-width="0.3" marker-end="url(#arrowhead)" id = "speed3" /> + + <line x1="45" y1="15" x2="55" y2="15" stroke="green" + stroke-width="0.3" marker-end="url(#endarrow)" + id = "gravitation1" + /> + <line x1="5" y1="15" x2="0" y2="0" stroke="green" + stroke-width="0.3" marker-end="url(#endarrow)" + id = "gravitation2" + /> + <line x1="35" y1="45" x2="35" y2="55" stroke="green" + stroke-width="0.3" marker-end="url(#endarrow)" + id = "gravitation3" + /> </svg>