PositionProperty.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import Matrix3 from "../Core/Matrix3.js";
  5. import ReferenceFrame from "../Core/ReferenceFrame.js";
  6. import Transforms from "../Core/Transforms.js";
  7. /**
  8. * The interface for all {@link Property} objects that define a world
  9. * location as a {@link Cartesian3} with an associated {@link ReferenceFrame}.
  10. * This type defines an interface and cannot be instantiated directly.
  11. *
  12. * @alias PositionProperty
  13. * @constructor
  14. * @abstract
  15. *
  16. * @see CompositePositionProperty
  17. * @see ConstantPositionProperty
  18. * @see SampledPositionProperty
  19. * @see TimeIntervalCollectionPositionProperty
  20. */
  21. function PositionProperty() {
  22. DeveloperError.throwInstantiationError();
  23. }
  24. Object.defineProperties(PositionProperty.prototype, {
  25. /**
  26. * Gets a value indicating if this property is constant. A property is considered
  27. * constant if getValue always returns the same result for the current definition.
  28. * @memberof PositionProperty.prototype
  29. *
  30. * @type {boolean}
  31. * @readonly
  32. */
  33. isConstant: {
  34. get: DeveloperError.throwInstantiationError,
  35. },
  36. /**
  37. * Gets the event that is raised whenever the definition of this property changes.
  38. * The definition is considered to have changed if a call to getValue would return
  39. * a different result for the same time.
  40. * @memberof PositionProperty.prototype
  41. *
  42. * @type {Event}
  43. * @readonly
  44. */
  45. definitionChanged: {
  46. get: DeveloperError.throwInstantiationError,
  47. },
  48. /**
  49. * Gets the reference frame that the position is defined in.
  50. * @memberof PositionProperty.prototype
  51. * @type {ReferenceFrame}
  52. */
  53. referenceFrame: {
  54. get: DeveloperError.throwInstantiationError,
  55. },
  56. });
  57. /**
  58. * Gets the value of the property at the provided time in the fixed frame.
  59. * @function
  60. *
  61. * @param {JulianDate} time The time for which to retrieve the value.
  62. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  63. * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
  64. */
  65. PositionProperty.prototype.getValue = DeveloperError.throwInstantiationError;
  66. /**
  67. * Gets the value of the property at the provided time and in the provided reference frame.
  68. * @function
  69. *
  70. * @param {JulianDate} time The time for which to retrieve the value.
  71. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  72. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  73. * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
  74. */
  75. PositionProperty.prototype.getValueInReferenceFrame =
  76. DeveloperError.throwInstantiationError;
  77. /**
  78. * Compares this property to the provided property and returns
  79. * <code>true</code> if they are equal, <code>false</code> otherwise.
  80. * @function
  81. *
  82. * @param {Property} [other] The other property.
  83. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  84. */
  85. PositionProperty.prototype.equals = DeveloperError.throwInstantiationError;
  86. const scratchMatrix3 = new Matrix3();
  87. /**
  88. * @private
  89. */
  90. PositionProperty.convertToReferenceFrame = function (
  91. time,
  92. value,
  93. inputFrame,
  94. outputFrame,
  95. result
  96. ) {
  97. if (!defined(value)) {
  98. return value;
  99. }
  100. if (!defined(result)) {
  101. result = new Cartesian3();
  102. }
  103. if (inputFrame === outputFrame) {
  104. return Cartesian3.clone(value, result);
  105. }
  106. let icrfToFixed = Transforms.computeIcrfToFixedMatrix(time, scratchMatrix3);
  107. if (!defined(icrfToFixed)) {
  108. icrfToFixed = Transforms.computeTemeToPseudoFixedMatrix(
  109. time,
  110. scratchMatrix3
  111. );
  112. }
  113. if (inputFrame === ReferenceFrame.INERTIAL) {
  114. return Matrix3.multiplyByVector(icrfToFixed, value, result);
  115. }
  116. if (inputFrame === ReferenceFrame.FIXED) {
  117. return Matrix3.multiplyByVector(
  118. Matrix3.transpose(icrfToFixed, scratchMatrix3),
  119. value,
  120. result
  121. );
  122. }
  123. };
  124. export default PositionProperty;