# Fly me to the Moon

**URL:** <https://community.cesium.com/t/fly-me-to-the-moon/9008>\
**Category:** CesiumJS\
**Created:** [January 12, 2020, 10:52pm UTC](https://community.cesium.com/t/fly-me-to-the-moon/9008 "2020-01-12T22:52:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harold\_Ensle](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@Harold\_Ensle](https://community.cesium.com/u/Harold_Ensle)\
**Post date:** [January 12, 2020, 10:52pm UTC](https://community.cesium.com/t/fly-me-to-the-moon/9008/1 "2020-01-12T22:52:35Z")

</div>

**Can my flight simulator fly to the moon using CesiumJS?**

**I noticed a MOON ellipsoid, but I saw no examples in the sandcastles. Do there exist terrain tiles for the moon?**

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [January 22, 2020, 2:13am UTC](https://community.cesium.com/t/fly-me-to-the-moon/9008/2 "2020-01-22T02:13:33Z")

</div>

CesiumJS does have compute the positions for the sun and moon correctly based on the given time in the viewer, but those are just images, not geometry.

While Cesium ion does not have terrain data for the moon, if you have lunar terrain (perhaps from some open datasets that NASA publishes) you can upload those GeoTIFFs to Cesium ion, replace the ellipsoid with the moon’s ellipsoid, and visualize the moon instead of the Earth.

CesiumJS currently only supports one central body, see: [https://github.com/AnalyticalGraphicsInc/cesium/issues/6419](https://github.com/AnalyticalGraphicsInc/cesium/issues/6419)

---

<div class="post-metadata">

**Author:** ![Harold\_Ensle](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@Harold\_Ensle](https://community.cesium.com/u/Harold_Ensle)\
**Post date:** [January 23, 2020, 6:51pm UTC](https://community.cesium.com/t/fly-me-to-the-moon/9008/3 "2020-01-23T18:51:38Z")

</div>

Thanks Omar for the info.

---

<div class="post-metadata">

**Author:** ![PJP](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/pjp/32/1987_2.png) [@PJP](https://community.cesium.com/u/PJP)\
**Post date:** [September 10, 2020, 7:54pm UTC](https://community.cesium.com/t/fly-me-to-the-moon/9008/4 "2020-09-10T19:54:31Z")

</div>

Based on my findings I suspect it’s still not possible to “fly to the moon” via the camera, due to the moon being an image instead of 2nd ellipsoid, with the Earth being the sole ellipsoid in Cesium?

I’m new to Cesium and have tried a few different ways to “fly to the moon” and have only had success with replacing the Earth ellipsoid with Cesium.Ellipsoid.MOON. While this works, it’s not practical for our needs.

The simple sandcastle demo linked below is one of my attempts to “fly to the moon”, and it seems as though it does but there is no moon to be seen. Am I doing something wrong, or is this just not possible while still maintaining the Earth ellipsoid?

The simple code:

> Blockquote  
> var viewer = new Cesium.Viewer(“cesiumContainer”);  
> viewer.scene.moon.show = true;  
> viewer.scene.camera.flyTo({  
> destination: Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(),  
> complete: function() {  
> console.log(“onComplete: Fly To Moon (flyto-moon)”);  
> }  
> });

Lastly, I found that this “MoonSpec.js” file (…\Specs\Scene\MoonSpec.js) contains a function lookAtMoon(camera, date). Could this be leveraged in any way?

Sandcastle demo:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/#c=bZDRa8IwEMb/ldCnFlyKsBddlYFMEDYmKHvqS0xPDUvvJLlWuuH/vqTOMdQ8JXe/7/vu0ionWgNHcGIiEI5iBt40tfzoa2mZ6P49I2RlEFyZZE8llnjWSK8BQdZEKP2ejsGDXQO3hFY1OCW3tltT+h3aXIFng4oN4fgSujI14XA0elxahcDKdUvyJiJeaqoPDcNbiLoUF/iiHO8XYSw2ys5dCEmzQXSPtAWGsdg2qCOcZqLPjT30ZEFa2oX9CGd/7Nx2Yk0iZog0zMr0EFfLfpfmU4mneEsGSeG5szAtUfTn2dQHciwaZ1Mpc4ZgqRh8vmn0J7DU3kdhRIv8v7SoTCtMNbnz0UJb5X3obBtrV+YLymRa5IG/kVpSlcHdewvOqi5i++H09VyUUhZ5eN5XMpHdKHfl/AM)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

---

<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, 2:34pm UTC](https://community.cesium.com/t/fly-me-to-the-moon/9008/5 "2024-08-30T14:34:56Z")

</div>

I eventually found a method to master Sun and Moon in Cesium.  
Have fun! [Link](https://sandcastle.cesium.com/#c=5Vnrctu4FX4VjDudUC5NUrLdteU4U9trJ2qT2LW1yWyrzg5MQhLWEMGCoG4Zv0vfpS/WgxsvuthOtvnRqXcVgeC545wPB1C4iwbpWMos74bhbDYLJpynMWZxwMUo/F140PHbHf8o7ESdgyA6CvbbYXTQjaKwHe43GfPi5XyDdDdU/06xQFNKZkSgU5SSGbogOS0mwSc95w12Yv18wVOJaUrEYKd1Alz6bZDHJCXa3ibzB5jxFJ36LwzRVZEuKU8JykANHo0oFykWBFGGrq4/DdIhGC6BABVZgiWBOW/Ipy30ZZAi+Gtoi/GECBwMRZFLUAV0oNvpxXIcSH6LE4rTXMsAIx6tFW9JLrUVCWGMo5zRBMzRBqgoAPWdmTpFCY+LCUllMCLykhE1PF/0Eu9VSfRKh8GwfcKsIM9waZpXJialkAAnyeUUyN7TXIJzwntF06yQr3zkQuJVUTDKQM9xey/DIie9VHpyTPNgqoQr2YrOKQskmUu1biAfmEqOdhTteiBCRSc8jlroD2iw8/vBjmVvLoEKnzEaAtibZDyX2C4boildUszIIK14/hgZamVsnpGYDmncpxNSrdGfCwaL8yPQwxryiRp4KnX0QE//1L/wVNL66Acf7bd9BKMI/m+1aqkXMx4/BHEhBLhnNdQVllYwLLcmyEHHrSLTKbyZql1ScUFHdCXXL7CQfCRwNqaxB2J8pdFHbccDARPyhufbuUCVeoQXOPWMChPEmKe5RDQWwz6/onOSrFQZloLO9z2nqU7ZsXO1AGmRlrUvwL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urLuG0mB4ocjG7TfvzWQQBK9DeNzMKTln91hslTzkU2URNM1gj7YbJqvLVXyfcwZbwAmSPOuidpTNTwDvhtKNq3NTF4nRPfY6h4e++0TBD60TlEGfBXaWHFwkROyp9ryAtTuEObDO2sXwPWEIyt6YZn4FhNd/u77+0IXI6veOWP8UiCS0WkANcDGCAJZeOVY0oSnMtNUIz2F0HMFQ/yAID4eRdptkhsRJzjOclpL0j4U6gGoaSEwk/wM)

Move slightly away from initial position to see the lines pointing to Sun and Moon; start clock to see them moving (updated only twice per seconds to avoid overloading). Play with the slider to change the zoom.

The trick to avoid nonsense results from Simon1994PlanetaryPositions:

```auto
var specificTime = Cesium.JulianDate.fromDate(new Date(Date.UTC(2024, 7, 31, 4, 0, 0)));
viewer.clock.currentTime = specificTime;
const icrfToFixed = new Cesium.Matrix3();
Cesium.Transforms.computeTemeToPseudoFixedMatrix(specificTime, icrfToFixed); // Time conversion
var moonPos = Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(specificTime);
Cesium.Matrix3.multiplyByVector(icrfToFixed, moonPos, moonPos); // Reference conversion

```

Don’t ask my why and how… I just reverse engineered [undocumented lookAtMoon() function](https://github.com/CesiumGS/cesium/blob/2568dfee4b1f213f8adbbc6ba477067ff33d6dbb/packages/engine/Specs/Scene/MoonSpec.js#L29)
