Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Rtyper · May 04, 2015 at 03:47 PM · coordinatestrigonometry

Mapping co-ordinates from Google maps onto sphere.

I have a sphere in Unity which I've textured with (I believe) satellite images from NASA to get a relatively accurate image of the earth - I'd like to be able to pinpoint locations on this sphere using Long/Lat co-ordinates from Google Maps.

I found some info online on converting from spherical to cartesian co-ordinate systems, and tried to implement it like this:

 Vector3 convertSphericalToCartesian(Vector2 latlong){
         float earthRadius = sphere.radius; //SphereCollider with the correct radius
 
         float lat = latlong.y*Mathf.Deg2Rad;
         float lon = latlong.x*Mathf.Deg2Rad;
         float x = earthRadius * Mathf.Cos(lat)*Mathf.Cos(lon);
         float y = earthRadius * Mathf.Cos(lat)*Mathf.Sin(lon);
         float z = earthRadius * Mathf.Sin(lat);
         return new Vector3(x,y,z);
     }

At first this seemed to work, but it only does when it is given either a longitude or a latitude, but not both. Otherwise it seems to drift really far from the correct location.

For example, at 0 , 50 it's correct: alt text

or 50 , 0:

alt text

But at 50,50 it's wrong:

alt text

I just don't know what's going on here. I know that the earth is actually an ellipsoid rather than a sphere, and that that will cause some error in the positions, but I'm sure that isn't the issue here. If anyone has any idea what's happening, I could really use your help!

Thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image riker96 · Mar 23, 2016 at 08:22 AM 0
Share

Same problem here. Any answers?

avatar image tanoshimi · Mar 23, 2016 at 09:43 AM 1
Share

There are many different ways to project a curved 3D surface (i.e. your lat/long data) onto a flat 2D surface (i.e. your x/y). Some common map projections are $$anonymous$$ercator, Equirectangular, for example (see https://en.wikipedia.org/wiki/$$anonymous$$ap_projection).

However, by definition, all map projections must distort the data in some way - either its shape, area, or both. You won't get a lat/long point to line up with the same position on your map image unless you're using the same projection method by which the map was produced. Check the metadata of the NASA image you have to see how the map was flattened, and ensure you use the same method in your conversion formula.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Fredex8 · Mar 23, 2016 at 01:28 PM

In the map view Google Maps uses Mercator projection which is basically a representation of the Earth's surface unwrapped around a cylinder. Since Google Maps is in 2D it works well enough and looks good but it is quite inaccurate and stretches countries so they are bigger than in reality. If you switch back and forth between Maps and Earth view you will see countries appear to change shape as a result of the different projection methods.

The NASA Earth textures use Equirectangular projection which works far better for texturing spheres and creates a reasonable facsimile of the real Earth but does crunch things up at the poles.

When you are comparing maps that use two different projection techniques things will never match up that accurately and since the NASA maps become more compressed towards the poles these errors will be magnified at the extremes of south and north. This is especially noticeable for European countries.

The error you are getting with those coordinates in Russia does look too large to be fully explained by this but it is something you should be aware of. I'm not sure how you are moving from one point to the next but it looks like diagonal movement is resulting in the figures being essentially doubled. I've had something similar to that before.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 23, 2016 at 02:00 PM 1
Share

Right, nevertheless you should be able to convert the coordinates to a meaningful representation in your used projection.

I guess that the vector should be new Vector3(x,z,y); ins$$anonymous$$d as at least Unity's default sphere has it's "poles" on the y axis, not on the z axis. You may also need to flip one or more coordinates depending on the image and mesh layout. It's also possible that the mesh is somehow rotated. Usually lat / lon 0/0 should be at a normalized point (0,0,-1).

  lat  lon   x   y   z
  --------------------
    0    0   0   0  -1
    0   90   1   0   0
    0  180   0   0   1
    0  270  -1   0   0
   90    0   0   1   0
  -90    0   0  -1   0




There was this old question which asked basically the opposite: how to calculate the lat / lon from a given cartesian point. I've made a webplayer build for that.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Map Google lat lng coordinates to sphere 1 Answer

Screen Space is non standard in Unity? 1 Answer

Single number coordinates display 1 Answer

Origin Placement Android Uity (Coordinates of Tuch positions) 0 Answers

Fix a GUI's position relative to a 3D object 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges