Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How do I transform ECEF (x,y,z) coordinates to Unity Coordinates

Discussion in 'Scripting' started by JD2225, Jun 17, 2023.

  1. JD2225

    JD2225

    Joined:
    Mar 25, 2023
    Posts:
    5
    Hi all,
    I wasn't really sure which topic to post this question in but here felt the most appropriate as it will involve scripting.

    I am trying to model a satellite in its orbit and I've calculated its ECEF coordinates relative to the topocentric position of La Palma. However I am unsure how to transform these ECEF coordinates into the unity coordinate system. For example , I am trying to position a camera object at the La Palma location (lat = 28.7603135, lon = -17.8796168,elevation (m) = 2387 ) which converts to
    X : 5327.41 km
    Y : -1718.614 km
    Z : 3051.788 km

    in ECEF coordinates ( https://www.oc.nps.edu/oc2902w/coord/llhxyz.htm). I would like to know how to transform this in the unity world-space as an example which would obviously help me transform my satellite coordinates.

    Thanks,
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Traditionally Unity regards 1 world unity as 1 meter.

    The only place this actually matters is the Physics system because of how time advances.

    Otherwise Unity is essentially dimensionless.

    You're welcome to map your ECEF thingies however works best for you.

    Remember that Unity uses 32-bit floating point numbers. This means you have 6 to 9 places of decimal accuracy, no more.

    That means the farther you are away from something, the less-precisely you know where it is.

    If you need massive distances, track it yourself in a higher-precision format such as
    double
    , or else use a floating origin system.
     
  3. JD2225

    JD2225

    Joined:
    Mar 25, 2023
    Posts:
    5
    Interesting, I read here that [https://discussions.unity.com/t/lat-long-to-unity-world-coordinates/133155/2] " X is forward, Y is right, D is down, which means X in ECEF is really Z in unity, Y in ECEF is X in unity, and Z in ECEF is really -Y in Unity" So I assumed that this would yield the correct transform (or at least points to a transform being needed)
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Not sure about all that noise.

    Unity is left hand rule.

    Hold your left hand up, palm outward.

    Your thumb is +X

    Your index finger is +Y

    Your palm is +Z
     
  5. JD2225

    JD2225

    Joined:
    Mar 25, 2023
    Posts:
    5
    Thanks, So I'm guessing I can just use all the ECEF positions I have already (Satellite position and La Palma)
     
  6. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,834
    The directions which you describe are just conventions, but the Y/-Y thing is about the chirality or handedness of the coordinate system. Everything outside of game development uses the right-handed coordinate system as God intended. Decades ago, Microsoft did the world a dirty, and now many game development engines including Unity use the sinister left-handed coordinate system. Thus, one coordinate in your right-handed format does need to be inverted as you convert into Unity.

    See the #18 post in this thread, which I wrote some time ago, about the conventions of forward/right/up in Unity.

    https://forum.unity.com/threads/what-is-transform-forward.338384/#post-3684166