瀏覽代碼

Vector3: introduce the cross product

customisations
alemart 10 月之前
父節點
當前提交
556a9cdaaf
共有 2 個檔案被更改,包括 28 行新增0 行删除
  1. 14
    0
      docs/api/vector3.md
  2. 14
    0
      src/geometry/vector3.ts

+ 14
- 0
docs/api/vector3.md 查看文件

78
 
78
 
79
 A new unit vector pointing to `v` from `this`.
79
 A new unit vector pointing to `v` from `this`.
80
 
80
 
81
+### cross
82
+
83
+`vector.cross(v: Vector3): Vector3`
84
+
85
+Compute the cross product of `this` and `v`.
86
+
87
+**Arguments**
88
+
89
+* `v: Vector3`. A vector.
90
+
91
+**Returns**
92
+
93
+The cross product `this` x `v`.
94
+
81
 ### equals
95
 ### equals
82
 
96
 
83
 `vector.equals(v: Vector3): boolean`
97
 `vector.equals(v: Vector3): boolean`

+ 14
- 0
src/geometry/vector3.ts 查看文件

110
     }
110
     }
111
 
111
 
112
     /**
112
     /**
113
+     * The cross product of this and v
114
+     * @param v a vector
115
+     * @returns the cross product this x v
116
+     */
117
+    cross(v: Vector3): Vector3
118
+    {
119
+        const x = this.y * v.z - this.z * v.y;
120
+        const y = this.z * v.x - this.x * v.z;
121
+        const z = this.x * v.y - this.y * v.x;
122
+
123
+        return new Vector3(x, y, z);
124
+    }
125
+
126
+    /**
113
      * Check if this and v have the same coordinates
127
      * Check if this and v have the same coordinates
114
      * @param v a vector
128
      * @param v a vector
115
      * @returns true if this and v have the same coordinates
129
      * @returns true if this and v have the same coordinates

Loading…
取消
儲存