|
@@ -6,15 +6,15 @@ import { _Math } from './Math.js';
|
|
*
|
|
*
|
|
* Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
|
|
* Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
|
|
*
|
|
*
|
|
- * The poles (phi) are at the positive and negative y axis.
|
|
|
|
- * The equator starts at positive z.
|
|
|
|
|
|
+ * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
|
|
|
|
+ * The azimuthal angle (theta) is measured from the positive z-axiz.
|
|
*/
|
|
*/
|
|
|
|
|
|
function Spherical( radius, phi, theta ) {
|
|
function Spherical( radius, phi, theta ) {
|
|
|
|
|
|
this.radius = ( radius !== undefined ) ? radius : 1.0;
|
|
this.radius = ( radius !== undefined ) ? radius : 1.0;
|
|
- this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
|
|
|
|
- this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
|
|
|
|
|
|
+ this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
|
|
|
|
+ this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
|
|
|
|
|
|
return this;
|
|
return this;
|
|
|
|
|
|
@@ -58,9 +58,15 @@ Object.assign( Spherical.prototype, {
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- setFromVector3: function ( vec3 ) {
|
|
|
|
|
|
+ setFromVector3: function ( v ) {
|
|
|
|
|
|
- this.radius = vec3.length();
|
|
|
|
|
|
+ return this.setFromCartesianCoords( v.x, v.y, v.z );
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ setFromCartesianCoords: function ( x, y, z ) {
|
|
|
|
+
|
|
|
|
+ this.radius = Math.sqrt( x * x + y * y + z * z );
|
|
|
|
|
|
if ( this.radius === 0 ) {
|
|
if ( this.radius === 0 ) {
|
|
|
|
|
|
@@ -69,8 +75,8 @@ Object.assign( Spherical.prototype, {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
|
|
|
|
- this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
|
|
|
|
|
|
+ this.theta = Math.atan2( x, z );
|
|
|
|
+ this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|