sub
方法用于对向量进行减法运算,它将减去另一个向量并返回结果。这个方法将修改现有的向量。
vector.sub(anotherVector);
anotherVector
: {Vector3},一个三维向量,用于减去现有向量。const vector1 = new Yuka.Vector3(1, 2, 3);
const vector2 = new Yuka.Vector3(4, 5, 6);
vector1.sub(vector2);
console.log(vector1); // 输出: Vector3 { x: -3, y: -3, z: -3 }
sub
方法使用叉积公式计算得出新向量:
result.x = this.x - anotherVector.x;
result.y = this.y - anotherVector.y;
result.z = this.z - anotherVector.z;
如果不想修改现有向量,可以使用 clone
方法对现有向量进行复制。