浏览代码

Added cartesian conversion methods

WestLangley 7 年之前
父节点
当前提交
fe4b07cdf9
共有 1 个文件被更改,包括 19 次插入7 次删除
  1. 19 7
      src/math/Vector3.js

+ 19 - 7
src/math/Vector3.js

@@ -617,11 +617,17 @@ Object.assign( Vector3.prototype, {
 
 
 	setFromSpherical: function ( s ) {
 	setFromSpherical: function ( s ) {
 
 
-		var sinPhiRadius = Math.sin( s.phi ) * s.radius;
+		return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
 
 
-		this.x = sinPhiRadius * Math.sin( s.theta );
-		this.y = Math.cos( s.phi ) * s.radius;
-		this.z = sinPhiRadius * Math.cos( s.theta );
+	},
+
+	setFromSphericalCoords: function ( radius, phi, theta ) {
+
+		var sinPhiRadius = Math.sin( phi ) * radius;
+
+		this.x = sinPhiRadius * Math.sin( theta );
+		this.y = Math.cos( phi ) * radius;
+		this.z = sinPhiRadius * Math.cos( theta );
 
 
 		return this;
 		return this;
 
 
@@ -629,9 +635,15 @@ Object.assign( Vector3.prototype, {
 
 
 	setFromCylindrical: function ( c ) {
 	setFromCylindrical: function ( c ) {
 
 
-		this.x = c.radius * Math.sin( c.theta );
-		this.y = c.y;
-		this.z = c.radius * Math.cos( c.theta );
+		return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
+
+	},
+
+	setFromCylindricalCoords: function ( radius, theta, y ) {
+
+		this.x = radius * Math.sin( theta );
+		this.y = y;
+		this.z = radius * Math.cos( theta );
 
 
 		return this;
 		return this;