瀏覽代碼

Add Vector3 class

ApisNecros 4 月之前
父節點
當前提交
0f9fdf19b8
共有 1 個文件被更改,包括 40 次插入0 次删除
  1. 40 0
      12/12_1.js

+ 40 - 0
12/12_1.js

@@ -0,0 +1,40 @@
+
+
+class Vector3 {
+    /**
+     * A 3D vector
+     *
+     * @param {number} x The X value of this vector
+     * @param {number} y The Y value of this vector
+     * @param {number} z The Z value of this vector
+     */
+    constructor(x, y, z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /**
+     * Add another vector to this one
+     *
+     * @param {Vector3} operand The vector to add to this one
+     * @returns {void}
+     */
+    add(operand) {
+        this.x += operand.x;
+        this.y += operand.y;
+        this.z += operand.z;
+    }
+}
+
+/**
+ * Find the gravitational influence two moons have on each other
+ *
+ * @param {Vector3} moonA The first moon to consider
+ * @param {Vector3} moonB The second moon to consider
+ *
+ * @returns {void}
+ */
+function calculateGravity(moonA, moonB) {
+    
+}