1
0

Cylindrical.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. Cylindrical.prototype = {
  14. constructor: Cylindrical,
  15. set: function ( radius, theta, y ) {
  16. this.radius = radius;
  17. this.theta = theta;
  18. this.y = y;
  19. return this;
  20. },
  21. clone: function () {
  22. return new this.constructor().copy( this );
  23. },
  24. copy: function ( other ) {
  25. this.radius = other.radius;
  26. this.theta = other.theta;
  27. this.y = other.y;
  28. return this;
  29. },
  30. setFromVector3: function( vec3 ) {
  31. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  32. this.theta = Math.atan2( vec3.x, vec3.z );
  33. this.y = vec3.y;
  34. return this;
  35. }
  36. };
  37. export { Cylindrical };
粤ICP备19079148号