0

I made a 3D earth model in scenekit and I want to put stuff on this model based on longitude and latitude and don't know where to begin.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Paul John
  • 115
  • 8
  • Welcome to SO Paul. The question is beyond answerable here it is too broad. It is not a simple task to map real life coordinates to a custom 3D model. –  Apr 05 '17 at 04:15
  • @Sneak im trying to make an iss (international space station) tracker with a 3D earth model that shows the position of the iss based on this API: http://api.open-notify.org/iss-now.json – Paul John Apr 05 '17 at 04:32
  • You need to do alot of calculations and map the numbers to your custom model. it takes some work and some great math. Check out these thread I found for you http://stackoverflow.com/questions/15211776/earth-latitude-longitude-to-latitude-longitude-on-a-3d-sphere http://stackoverflow.com/questions/10473852/convert-latitude-and-longitude-to-point-in-3d-space http://stackoverflow.com/questions/11511988/rendering-dots-on-a-globe-with-correct-longitude-and-latitude-in-opengl http://stackoverflow.com/questions/5674149/3d-coordinates-on-a-sphere-to-latitude-and-longitude –  Apr 05 '17 at 04:37
  • If you google a bit you might get more pointers. If you run into a specific problem , you should create an answer with the specific problem, for now, it is off-topic. Good luck –  Apr 05 '17 at 04:37
  • 1
    @Sneak thanks a bunch! – Paul John Apr 05 '17 at 04:39

1 Answers1

2

You don't need to go into complex math to do this. All you need to do is add two extra helper nodes.

Lets assume the Earth is represented by earthNode with its geometry (a sphere) at the centre of the node and with a radius of 100 points.

Add a child node to it with the same centre called longtudeHandle, without any geometry.

Now add another child node to the first one latitudeHandle, without any geometry.

Then you add the space station node stationNode as a child to latitudeHandleNode, but not in the centre. Offset it along the X axis by, say, 105 points to place it 5 points above "the Equator".

SCNNode * longtudeHandle = [SCNNode node];
[earthNode addChildNode:longtudeHandle];

SCNNode * latitudeHandle = [SCNNode node];
[longtudeHandle addChildNode:latitudeHandle];    

stationNode.position = SCNVector3Make(105, 0, 0);
[latitudeHandle addChildNode:stationNode];

You should end up with the following node graph in your scene

earthNode
  |
  |--------longitudeHandle
              |
              |----------latitudeHandle
                            |
                            |-----------stationNode

As a result you have 4 nested coordinate systems and every node 3D rotation is set according to its parent node coordinate system.

You can then manipulate the long/lat position of your Station using

  • longitudeHanlde.eulerAngles Y component for longitude angle in radians
  • latitudeHanlde.eulerAngles Z component for latitude angle in radians

which should look like

longitudeHandle.eulerAngles = SCNVector3Make(0, LONGITUDE, 0);
latitudeHanlde.eulerAngles = SCNVector3Make(0, 0, LATITUDE);

An additional benefit of using these nested helper nodes is that the Station will always be perpendicular to it's parent's X axis and respectively the planet surface, while if you use complex math to position it in orbit and want to achieve the same effect it becomes even more complex.


Alternatively, you should be able to do the same with only one helper (positioning) node and whichever "rotational" property you are familiar with to orient it in 3D space

.euler​Angles  // SCNVector3
.rotation     // SCNVector4
.orientation  // SCNQuaternion
.transform    // SCNMatrix4, includes position and scale

but this will require some math and/or use of matrices or quaternions (which I've not spent time to learn yet).

Sulevus
  • 669
  • 5
  • 13
  • Forgot to mention: radians = degrees * PI / 180 – Sulevus Apr 08 '17 at 14:54
  • Good explanation, upvoted, but out of interest, how do you come to the conclusion that no complex map is required for this? The earth isnt a perfect sphere, and mapping long/lat on a perfect sphered 3D model without any math (as mentioned here for example: http://stackoverflow.com/questions/5674149/3d-coordinates-on-a-sphere-to-latitude-and-longitude) , will not show the exact position of the object, but rather an estimate, or did I miss out on something? –  Apr 17 '17 at 22:02