# How to use lookAtMoon() in MoonSpec.js?

**URL:** <https://community.cesium.com/t/how-to-use-lookatmoon-in-moonspec-js/34856>\
**Category:** CesiumJS\
**Created:** [August 30, 2024, 12:59pm UTC](https://community.cesium.com/t/how-to-use-lookatmoon-in-moonspec-js/34856 "2024-08-30T12:59:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumpjack](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jumpjack/32/3589_2.png) [@jumpjack](https://community.cesium.com/u/jumpjack)\
**Post date:** [August 30, 2024, 12:59pm UTC](https://community.cesium.com/t/how-to-use-lookatmoon-in-moonspec-js/34856/1 "2024-08-30T12:59:09Z")

</div>

I can’t find any example about [this function](https://github.com/CesiumGS/cesium/blob/2568dfee4b1f213f8adbbc6ba477067ff33d6dbb/packages/engine/Specs/Scene/MoonSpec.js#L29), and apparently Simon1994PlanetaryPositions returns wrong position for Sun and Moon.

My [sandcastle](https://sandcastle.cesium.com/#c=bZDRa8IwEMb/ldCnFlyKsBddlYFMEDYmKHvqS0xPDUvvJLlWuuH/vqTOMdQ8JXe/7/vu0ionWgNHcGIiEI5iBt40tfzoa2mZ6P49I2RlEFyZZE8llnjWSK8BQdZEKP2ejsGDXQO3hFY1OCW3tltT+h3aXIFng4oN4fgSujI14XA0elxahcDKdUvyJiJeaqoPDcNbiLoUF/iiHO8XYSw2ys5dCEmzQXSPtAWGsdg2qCOcZqLPjT30ZEFa2oX9CGd/7Nx2Yk0iZog0zMr0EFfLfpfmU4mneEsGSeG5szAtUfTn2dQHciwaZ1Mpc4ZgqRh8vmn0J7DU3kdhRIv8v7SoTCtMNbnz0UJb5X3obBtrV+YLymRa5IG/kVpSlcHdewvOqi5i++H09VyUUhZ5eN5XMpHdKHfl/AM).

Gray and Yellow: Simon1994 pointing (wrong)  
Red and Orange: [suncalc](https://www.suncalc.org/#/42,12,8/2024.08.30/14:40/1/3) and [mooncalc](https://www.mooncalc.org/#/42,12,8/2024.08.30/14:39/1/3) pointing (right)

Cesium **does** put the Moon and the Sun in the right positions… but WHERE does it store them and how can I access them?  
And how can I access lookAtMoon()? viewer.scene.lookAtMoon() does not work.

---

<div class="post-metadata">

**Author:** ![jumpjack](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jumpjack/32/3589_2.png) [@jumpjack](https://community.cesium.com/u/jumpjack)\
**Post date:** [August 31, 2024, 2:05pm UTC](https://community.cesium.com/t/how-to-use-lookatmoon-in-moonspec-js/34856/2 "2024-08-31T14:05:14Z")

</div>

I found that rather than using lookAtMoon, I can just reuse its algorithm (but I am still curious about how to access any function which I can find in the source code):

```auto
var specificTime = Cesium.JulianDate.fromDate(new Date(Date.UTC(2024, 7, 31, 4, 0, 0))); // Define custom time
viewer.clock.currentTime = specificTime; // apply to view
const icrfToFixed = new Cesium.Matrix3(); // Setup Matrix to convert from ICRF reference to Fixed reference
Cesium.Transforms.computeTemeToPseudoFixedMatrix(specificTime, icrfToFixed); /// Use time to setup the conversion matrix
var moonPos = Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(specificTime); // Use time to calculate Moon position in ICRF reference
Cesium.Matrix3.multiplyByVector(icrfToFixed, moonPos, moonPos); //Convert moon position from ICRF to Fixed reference

```

Alternative syntax:

```auto
var specificTime = Cesium.JulianDate.fromDate(new Date(Date.UTC(2024, 7, 31, 4, 0, 0))); // Define custom time
viewer.clock.currentTime = specificTime; // apply to view
var icrfToFixed = new Cesium.Transforms.computeTemeToPseudoFixedMatrix(specificTime); /// Use time to make the conversion
var moonPos = Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(specificTime); // Use time to calculate Moon position in ICRF reference
var fixedPos = new Cesium.Matrix3.multiplyByVector(icrfToFixed, moonPos,new Cesium.Cartesian3()); //Convert moon position from ICRF to Fixed reference

```

Sandcastle: [link](https://sandcastle.cesium.com/#c=jVZrTxs5FP0rVj7NdL0zSYq0SyBoIRQtqxYimrJabVaV6zjEwmOPPB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