Cylindrical.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @author Mugen87 / https://github.com/Mugen87
  3. *
  4. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  5. *
  6. */
  7. function Cylindrical( radius, theta, y ) {
  8. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  9. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  10. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  11. return this;
  12. }
  13. Object.assign( Cylindrical.prototype, {
  14. set: function ( radius, theta, y ) {
  15. this.radius = radius;
  16. this.theta = theta;
  17. this.y = y;
  18. return this;
  19. },
  20. clone: function () {
  21. return new this.constructor().copy( this );
  22. },
  23. copy: function ( other ) {
  24. this.radius = other.radius;
  25. this.theta = other.theta;
  26. this.y = other.y;
  27. return this;
  28. },
  29. setFromVector3: function ( vec3 ) {
  30. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  31. this.theta = Math.atan2( vec3.x, vec3.z );
  32. this.y = vec3.y;
  33. return this;
  34. }
  35. } );
  36. export { Cylindrical };