Cylindrical.js 953 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  3. */
  4. class Cylindrical {
  5. constructor( radius = 1, theta = 0, y = 0 ) {
  6. this.radius = radius; // distance from the origin to a point in the x-z plane
  7. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  8. this.y = y; // 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. copy( other ) {
  18. this.radius = other.radius;
  19. this.theta = other.theta;
  20. this.y = other.y;
  21. return this;
  22. }
  23. setFromVector3( v ) {
  24. return this.setFromCartesianCoords( v.x, v.y, v.z );
  25. }
  26. setFromCartesianCoords( x, y, z ) {
  27. this.radius = Math.sqrt( x * x + z * z );
  28. this.theta = Math.atan2( x, z );
  29. this.y = y;
  30. return this;
  31. }
  32. clone() {
  33. return new this.constructor().copy( this );
  34. }
  35. }
  36. export { Cylindrical };