Search Unity

Cartesian x,y,z coordinates and spherical rotoation

Discussion in 'Scripting' started by eco_bach, Apr 12, 2020.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Attempting to build a virtual globe. have completed a bunch of Spherical(Lat, Long,alt) to 3D Cartesian (x,y,z) conversions and checked them with this online tool http://www.apsalin.com/convert-geodetic-to-cartesian.aspx

    But what confuses me is how do I translate these x,y,z points to x rot, y rot, z rot values? When a specific location is selected I need to rotate my virtual globe(sphere) so the converted 3D Cartesian coordinate is centered on the screen. Or to put it another way, given xyz coord on a sphere, how to rotate the sphere to that point? Any suggestions?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    You only need latitude and longitude to reach an arbitrary point on the globe.

    Which order you apply them in is the trick, but traditionally you would apply longitude first (spin around the Y axis), then tilt along the resultant local X axis. This might be best accomplished with two separate transforms above your globe in the hierarchy:

    Screen Shot 2020-04-11 at 8.04.47 PM.png

    Set that up, go into the inspector for Lat and Long and wiggle the X and Y rotation fields and see if that's what you're looking for. With the above hierarchy, once you tilt the latitude, you'll see that spinning the longitude would seem appropriate if a globe on a table is your reference behavior.