智慧水务管理系统 - 精河县供水工程综合管理平台

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import Check from "../Core/Check.js";
  3. import CesiumMath from "../Core/Math.js";
  4. /**
  5. * A ParticleEmitter that emits particles within a sphere.
  6. * Particles will be positioned randomly within the sphere and have initial velocities emanating from the center of the sphere.
  7. *
  8. * @alias SphereEmitter
  9. * @constructor
  10. *
  11. * @param {number} [radius=1.0] The radius of the sphere in meters.
  12. */
  13. function SphereEmitter(radius) {
  14. radius = radius ?? 1.0;
  15. //>>includeStart('debug', pragmas.debug);
  16. Check.typeOf.number.greaterThan("radius", radius, 0.0);
  17. //>>includeEnd('debug');
  18. this._radius = radius ?? 1.0;
  19. }
  20. Object.defineProperties(SphereEmitter.prototype, {
  21. /**
  22. * The radius of the sphere in meters.
  23. * @memberof SphereEmitter.prototype
  24. * @type {number}
  25. * @default 1.0
  26. */
  27. radius: {
  28. get: function () {
  29. return this._radius;
  30. },
  31. set: function (value) {
  32. //>>includeStart('debug', pragmas.debug);
  33. Check.typeOf.number.greaterThan("value", value, 0.0);
  34. //>>includeEnd('debug');
  35. this._radius = value;
  36. },
  37. },
  38. });
  39. /**
  40. * Initializes the given {Particle} by setting it's position and velocity.
  41. *
  42. * @private
  43. * @param {Particle} particle The particle to initialize
  44. */
  45. SphereEmitter.prototype.emit = function (particle) {
  46. const theta = CesiumMath.randomBetween(0.0, CesiumMath.TWO_PI);
  47. const phi = CesiumMath.randomBetween(0.0, CesiumMath.PI);
  48. const rad = CesiumMath.randomBetween(0.0, this._radius);
  49. const x = rad * Math.cos(theta) * Math.sin(phi);
  50. const y = rad * Math.sin(theta) * Math.sin(phi);
  51. const z = rad * Math.cos(phi);
  52. particle.position = Cartesian3.fromElements(x, y, z, particle.position);
  53. particle.velocity = Cartesian3.normalize(
  54. particle.position,
  55. particle.velocity,
  56. );
  57. };
  58. export default SphereEmitter;