浏览代码

Zero vector orthogonal to every vector

WestLangley 5 年之前
父节点
当前提交
23649acb80
共有 3 个文件被更改,包括 9 次插入7 次删除
  1. 2 2
      docs/api/en/math/Vector3.html
  2. 2 2
      docs/api/zh/math/Vector3.html
  3. 5 3
      src/math/Vector3.js

+ 2 - 2
docs/api/en/math/Vector3.html

@@ -117,7 +117,7 @@ var d = a.distanceTo( b );
 
 
 		<h3>[method:Float angleTo]( [param:Vector3 v] )</h3>
 		<h3>[method:Float angleTo]( [param:Vector3 v] )</h3>
 		<p>
 		<p>
-		Returns the angle between this vector and vector [page:Vector3 v] in radians. Neither this vector nor [page:Vector3 v] can be the zero vector.
+		Returns the angle between this vector and vector [page:Vector3 v] in radians.
 		</p>
 		</p>
 
 
 		<h3>[method:this ceil]()</h3>
 		<h3>[method:this ceil]()</h3>
@@ -317,7 +317,7 @@ var d = a.distanceTo( b );
 		</p>
 		</p>
 
 
 		<h3>[method:this projectOnVector]( [param:Vector3 v] )</h3>
 		<h3>[method:this projectOnVector]( [param:Vector3 v] )</h3>
-		<p>[link:https://en.wikipedia.org/wiki/Vector_projection Projects] this vector onto [page:Vector3 v]. [page:Vector3 v] cannot be the zero vector.</p>
+		<p>[link:https://en.wikipedia.org/wiki/Vector_projection Projects] this vector onto [page:Vector3 v].</p>
 
 
 		<h3>[method:this reflect]( [param:Vector3 normal] )</h3>
 		<h3>[method:this reflect]( [param:Vector3 normal] )</h3>
 		<p>
 		<p>

+ 2 - 2
docs/api/zh/math/Vector3.html

@@ -114,7 +114,7 @@ var d = a.distanceTo( b );
 
 
 		<h3>[method:Float angleTo]( [param:Vector3 v] )</h3>
 		<h3>[method:Float angleTo]( [param:Vector3 v] )</h3>
 		<p>
 		<p>
-		以弧度返回该向量与向量[page:Vector3 v]之间的角度。 Neither this vector nor [page:Vector3 v] can be the zero vector.
+		以弧度返回该向量与向量[page:Vector3 v]之间的角度。
 		</p>
 		</p>
 
 
 		<h3>[method:this ceil]()</h3>
 		<h3>[method:this ceil]()</h3>
@@ -313,7 +313,7 @@ var d = a.distanceTo( b );
 		</p>
 		</p>
 
 
 		<h3>[method:this projectOnVector]( [param:Vector3] )</h3>
 		<h3>[method:this projectOnVector]( [param:Vector3] )</h3>
-		<p>投影([link:https://en.wikipedia.org/wiki/Vector_projection Projects])该向量到向量[page:Vector3 v]上。[page:Vector3 v]不能是零向量。</p>
+		<p>投影([link:https://en.wikipedia.org/wiki/Vector_projection Projects])该向量到向量[page:Vector3 v]上。</p>
 
 
 		<h3>[method:this reflect]( [param:Vector3 normal] )</h3>
 		<h3>[method:this reflect]( [param:Vector3 normal] )</h3>
 		<p>
 		<p>

+ 5 - 3
src/math/Vector3.js

@@ -534,9 +534,11 @@ Object.assign( Vector3.prototype, {
 
 
 	projectOnVector: function ( v ) {
 	projectOnVector: function ( v ) {
 
 
-		// v cannot be the zero v
+		var denominator = v.lengthSq();
 
 
-		var scalar = v.dot( this ) / v.lengthSq();
+		if ( denominator === 0 ) return this.set( 0, 0, 0 );
+
+		var scalar = v.dot( this ) / denominator;
 
 
 		return this.copy( v ).multiplyScalar( scalar );
 		return this.copy( v ).multiplyScalar( scalar );
 
 
@@ -563,7 +565,7 @@ Object.assign( Vector3.prototype, {
 
 
 		var denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
 		var denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
 
 
-		if ( denominator === 0 ) console.error( 'THREE.Vector3: angleTo() can\'t handle zero length vectors.' );
+		if ( denominator === 0 ) return Math.PI / 2;
 
 
 		var theta = this.dot( v ) / denominator;
 		var theta = this.dot( v ) / denominator;