瀏覽代碼

Vector2: added angle() method

WestLangley 9 年之前
父節點
當前提交
6866b14f65
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 5 0
      docs/api/math/Vector2.html
  2. 12 0
      src/math/Vector2.js

+ 5 - 0
docs/api/math/Vector2.html

@@ -120,6 +120,11 @@
 		Normalizes this vector.
 		Normalizes this vector.
 		</div>
 		</div>
 
 
+		<h3>[method:Float angle]()</h3>
+		<div>
+		Computes the angle in radians of this vector with respect to the positive x-axis.
+		</div>
+
 		<h3>[method:Float distanceTo]( [page:Vector2 v] )</h3>
 		<h3>[method:Float distanceTo]( [page:Vector2 v] )</h3>
 		<div>
 		<div>
 		Computes distance of this vector to *v*.
 		Computes distance of this vector to *v*.

+ 12 - 0
src/math/Vector2.js

@@ -370,6 +370,18 @@ THREE.Vector2.prototype = {
 
 
 	},
 	},
 
 
+	angle: function () {
+
+		// computes the angle in radians with respect to the positive x-axis
+
+		var angle = Math.atan2( this.y, this.x );
+
+		if ( angle < 0 ) angle += 2 * Math.PI;
+
+		return angle;
+
+	},
+
 	distanceTo: function ( v ) {
 	distanceTo: function ( v ) {
 
 
 		return Math.sqrt( this.distanceToSquared( v ) );
 		return Math.sqrt( this.distanceToSquared( v ) );