function clamp ( value, min, max ) { return Math.max( min, Math.min( max, value ) ); } function Spherical( radius = 1, phi = 0, theta = 0 ) { this.radius = radius this.phi = phi this.theta = theta } Object.assign( Spherical.prototype, { set: function ( radius, phi, theta ) { this.radius = radius; this.phi = phi; this.theta = theta; return this; }, clone: function () { return new this.constructor().copy( this ); }, copy: function ( other ) { this.radius = other.radius; this.phi = other.phi; this.theta = other.theta; return this; }, // restrict phi to be betwee EPS and PI-EPS makeSafe: function () { var EPS = 0.000001; this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) ); return this; }, setFromVector3: function ( v ) { 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 ) { this.theta = 0; this.phi = 0; } else { this.theta = Math.atan2( x, z ); this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) ); } return this; } } ); export default Spherical