# Accessing Moon position

I noticed that you can travel to the Moon, and it appears to be at the proper distance from Earth and at the proper radius. Camera control is coarse as it’s based on the distance from the Earth. I’d like to rectify that, but I need to be able to access the Cartesian3 location of the center of the Moon. How can one access the moon position from within the scope of the sandcastle apps?

You can compute the position of the moon yourself using Simon1994PlanetaryPositions: http://cesiumjs.org/Cesium/Build/Documentation/Simon1994PlanetaryPositions.html (As the name implies, this is in the inertial frame).

You can also check out Moon primitive code, which uses the above to render the ellipsoid for the moon: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Moon.js

Hi, thanks for the response!

I’m having a tough time with scope from within Camera_tutorial.html Currently I’m modifying viewer.clock.onTick.addEventListener(function(clock) {

The first line is

var camera = scene.camera;

So I have no problems accessing properties and methods of the camera object.

If I try something like var mymoon = scene.moon;

I get this error: ReferenceError: Simon1994PlanetaryPositions is not defined

If I try something like var mypoint = new Cartesian3();

I get this error: ReferenceError: Cartesian3 is not defined

I’ve imported my own 3D math library because I don’t know how to use Cesium’s. However my library is array based, so I have to do stuff like convert from object to array:

var cam_pos = [camera.position.x,camera.position.y,camera.position.z];

then from array back to object

var camera_position={x:cam_pos[0],y:cam_pos[1],z:cam_pos[2]};

not truly a Cartesian3 object, but it seems to do the job.

If I knew how to use Cesium’s vector math library I’d use that instead, such as cross, dot, add, subtract, normal, and projection functions. I noticed that Simon1994PlanetaryPositionsSpec.js has moon.x, moon.y, moon.z, it would be great if I had access to those properties!

I must say Camera control in Cesium is fantastic! I’m making good use out of the look,move,and rotate methods of the camera object.

Well the core of my problem is how to define.

Why is it that from Camera Tutorial.html the camera object and functions such as Cesium.Math.toRadians are accessible, while functions such as ‘Cartesian3.cross’ and ‘new Cartesian3’ are not (throws ReferenceError: Cartesian3 is not defined.)

How do I define these from a Sandcastle app?

You’ve suggested that I use Simon1994PlanetaryPositions, but when I try that I get: ReferenceError: Simon1994PlanetaryPositions is not defined

I tried adding this to no avail

If Cesium.js is included with the script tag, make sure to prefix all Cesium types with “Cesium.” so, for example, these should be defined:

Cesium.Cartesian3.cross

Cesium.Cartesian3

Cesium.Simon1994PlanetaryPositions

Patrick

Thanks, that fixed it! Adding this script

With the Cesium prefix I can now access the functions, as this doesn’t throw an error:
Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame

Thanks again for the assistance, now I can calculate the Moon’s position, as well as access the vector math functions.

Since Cesium already continuously calculates the moon position it would be nice to tap into that, rather than calculate it a second time on the same frame, for greater efficiency.

Actually isn’t required, in fact adding that added a huge list of Uncaught Errors. I just needed to add the Cesium prefix.