فهرست منبع

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.
 		</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>
 		<div>
 		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 ) {
 
 		return Math.sqrt( this.distanceToSquared( v ) );