IauOrientationAxes.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. var xAxisScratch = new Cartesian3();
  27. var yAxisScratch = new Cartesian3();
  28. var zAxisScratch = new Cartesian3();
  29. function computeRotationMatrix(alpha, delta, result) {
  30. var 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. var cosDec = Math.cos(delta);
  35. var zAxis = zAxisScratch;
  36. zAxis.x = cosDec * Math.cos(alpha);
  37. zAxis.y = cosDec * Math.sin(alpha);
  38. zAxis.z = Math.sin(delta);
  39. var 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. var rotMtxScratch = new Matrix3();
  55. var 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. var alphaDeltaW = this._computeFunction(date);
  68. var precMtx = computeRotationMatrix(alphaDeltaW.rightAscension, alphaDeltaW.declination, result);
  69. var rot = CesiumMath.zeroToTwoPi(alphaDeltaW.rotation);
  70. var quat = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, rot, quatScratch);
  71. var rotMtx = Matrix3.fromQuaternion(Quaternion.conjugate(quat, quat), rotMtxScratch);
  72. var cbi2cbf = Matrix3.multiply(rotMtx, precMtx, precMtx);
  73. return cbi2cbf;
  74. };
  75. /**
  76. * A function that computes the {@link IauOrientationParameters} for a {@link JulianDate}.
  77. * @callback IauOrientationAxes~ComputeFunction
  78. * @param {JulianDate} date The date to evaluate the parameters.
  79. * @returns {IauOrientationParameters} The orientation parameters.
  80. */
  81. export default IauOrientationAxes;