浏览代码

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,6 +78,20 @@ Compute a unit vector pointing to `v` from `this`.
78 78
 
79 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 95
 ### equals
82 96
 
83 97
 `vector.equals(v: Vector3): boolean`

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

@@ -110,6 +110,20 @@ export class Vector3
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 127
      * Check if this and v have the same coordinates
114 128
      * @param v a vector
115 129
      * @returns true if this and v have the same coordinates

正在加载...
取消
保存