2
0
Эх сурвалжийг харах

Merge pull request #7963 from WestLangley/dev-vec2

Vector2: added angle() method
Mr.doob 9 жил өмнө
parent
commit
110fea8a77

+ 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 ) );