Browse Source

Add function to calculate gravity between two bodies

ApisNecros 4 months ago
parent
commit
7f676806ea
1 changed files with 10 additions and 2 deletions
  1. 10 2
      12/12_1.js

+ 10 - 2
12/12_1.js

@@ -43,5 +43,13 @@ class Vector3 {
  * @returns {void}
  */
 function calculateGravity(moonA, moonB) {
-    
-}
+    // The gravitational pull on Moon A caused by Moon B
+    const gravityA = new Vector3(
+        // eslint-disable-next-line no-nested-ternary
+        moonB.x > moonA.x ? 1 : (moonB.x < moonA.x ? -1 : 0),
+        // eslint-disable-next-line no-nested-ternary
+        moonB.y > moonA.y ? 1 : (moonB.y < moonA.y ? -1 : 0),
+        // eslint-disable-next-line no-nested-ternary
+        moonB.z > moonA.z ? 1 : (moonB.z < moonA.z ? -1 : 0),
+    );
+}