PositionProperty.js 4.6 KB

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