Accessing Moon position

232 views
Skip to first unread message

Hyper Sonic

unread,
Dec 27, 2014, 7:08:22 PM12/27/14
to cesiu...@googlegroups.com
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?

Matthew Amato

unread,
Dec 29, 2014, 10:18:00 AM12/29/14
to cesiu...@googlegroups.com
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

On Sat, Dec 27, 2014 at 7:08 PM, Hyper Sonic <gman...@gmail.com> wrote:
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 received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hyper Sonic

unread,
Dec 29, 2014, 11:57:02 AM12/29/14
to cesiu...@googlegroups.com
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.

Hyper Sonic

unread,
Dec 31, 2014, 10:12:49 AM12/31/14
to cesiu...@googlegroups.com
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
<script type="text/javascript" src="../../../Source/Core/Cartesian3.js"></script>
<script type="text/javascript" src="../../../Source/Core/Simon1994PlanetaryPositions.js"></script>

Patrick Cozzi

unread,
Dec 31, 2014, 10:26:53 AM12/31/14
to cesiu...@googlegroups.com
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

Hyper Sonic

unread,
Dec 31, 2014, 10:53:45 AM12/31/14
to cesiu...@googlegroups.com
Thanks, that fixed it! Adding this script
<script type="text/javascript" src="../../../Source/Cesium.js"></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.

Hyper Sonic

unread,
Dec 31, 2014, 11:22:53 AM12/31/14
to cesiu...@googlegroups.com
Actually <script type="text/javascript" src="../../../Source/Cesium.js"></script> isn't required, in fact adding that added a huge list of Uncaught Errors. I just needed to add the Cesium prefix.
Reply all
Reply to author
Forward
0 new messages