IauOrientationAxes.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import Cartesian3 from "./Cartesian3.js";
  2. import defined from "./defined.js";
  3. import Iau2000Orientation from "./Iau2000Orientation.js";
  4. import JulianDate from "./JulianDate.js";
  5. import CesiumMath from "./Math.js";
  6. import Matrix3 from "./Matrix3.js";
  7. import Quaternion from "./Quaternion.js";
  8. /**
  9. * The Axes representing the orientation of a Globe as represented by the data
  10. * from the IAU/IAG Working Group reports on rotational elements.
  11. * @alias IauOrientationAxes
  12. * @constructor
  13. *
  14. * @param {IauOrientationAxes.ComputeFunction} [computeFunction] The function that computes the {@link IauOrientationParameters} given a {@link JulianDate}.
  15. *
  16. * @see Iau2000Orientation
  17. *
  18. * @private
  19. */
  20. function IauOrientationAxes(computeFunction) {
  21. if (!defined(computeFunction) || typeof computeFunction !== "function") {
  22. computeFunction = Iau2000Orientation.ComputeMoon;
  23. }
  24. this._computeFunction = computeFunction;
  25. }
  26. const xAxisScratch = new Cartesian3();
  27. const yAxisScratch = new Cartesian3();
  28. const zAxisScratch = new Cartesian3();
  29. function computeRotationMatrix(alpha, delta, result) {
  30. const xAxis = xAxisScratch;
  31. xAxis.x = Math.cos(alpha + CesiumMath.PI_OVER_TWO);
  32. xAxis.y = Math.sin(alpha + CesiumMath.PI_OVER_TWO);
  33. xAxis.z = 0.0;
  34. const cosDec = Math.cos(delta);
  35. const zAxis = zAxisScratch;
  36. zAxis.x = cosDec * Math.cos(alpha);
  37. zAxis.y = cosDec * Math.sin(alpha);
  38. zAxis.z = Math.sin(delta);
  39. const yAxis = Cartesian3.cross(zAxis, xAxis, yAxisScratch);
  40. if (!defined(result)) {
  41. result = new Matrix3();
  42. }
  43. result[0] = xAxis.x;
  44. result[1] = yAxis.x;
  45. result[2] = zAxis.x;
  46. result[3] = xAxis.y;
  47. result[4] = yAxis.y;
  48. result[5] = zAxis.y;
  49. result[6] = xAxis.z;
  50. result[7] = yAxis.z;
  51. result[8] = zAxis.z;
  52. return result;
  53. }
  54. const rotMtxScratch = new Matrix3();
  55. const quatScratch = new Quaternion();
  56. /**
  57. * Computes a rotation from ICRF to a Globe's Fixed axes.
  58. *
  59. * @param {JulianDate} date The date to evaluate the matrix.
  60. * @param {Matrix3} result The object onto which to store the result.
  61. * @returns {Matrix3} The modified result parameter or a new instance of the rotation from ICRF to Fixed.
  62. */
  63. IauOrientationAxes.prototype.evaluate = function (date, result) {
  64. if (!defined(date)) {
  65. date = JulianDate.now();
  66. }
  67. const alphaDeltaW = this._computeFunction(date);
  68. const precMtx = computeRotationMatrix(
  69. alphaDeltaW.rightAscension,
  70. alphaDeltaW.declination,
  71. result
  72. );
  73. const rot = CesiumMath.zeroToTwoPi(alphaDeltaW.rotation);
  74. const quat = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, rot, quatScratch);
  75. const rotMtx = Matrix3.fromQuaternion(
  76. Quaternion.conjugate(quat, quat),
  77. rotMtxScratch
  78. );
  79. const cbi2cbf = Matrix3.multiply(rotMtx, precMtx, precMtx);
  80. return cbi2cbf;
  81. };
  82. /**
  83. * A function that computes the {@link IauOrientationParameters} for a {@link JulianDate}.
  84. * @callback IauOrientationAxes.ComputeFunction
  85. * @param {JulianDate} date The date to evaluate the parameters.
  86. * @returns {IauOrientationParameters} The orientation parameters.
  87. * @private
  88. */
  89. export default IauOrientationAxes;