Cylindrical.js 1.0 KB

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