Преглед на файлове

Merge pull request #7963 from WestLangley/dev-vec2

Vector2: added angle() method
Mr.doob преди 9 години
родител
ревизия
110fea8a77
променени са 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 ) );