PositionProperty.js 4.6 KB

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