I have a lot of cartesian coordinates (moving points on a plane) that I want to place programatically on the globe. Does the Unreal plugin provide any function for unprojecting coordinates. Preferrably resulting in cartesian coordinates. I’m a newbie so sorry if my question makes poor sense.
It depends. Do any of the functions unproject projected coordinates? I have points that exist in web mercator projection space. I need to unproject them so that they are correctly placed on the curved globe surface.
Cesium for Unreal doesn’t have anything built-in for working with Web Mercator coordinates. However, if you can use C++, Cesium for Unreal’s underlying library, called cesium-native, has a WebMercatorProjection class that will do what you want. Specifically, it will allow you to transform Web Mercator coordinates to longitude/latitude, at which point you can use the functions @arbertrary mentioned.
I’m using the project/unproject functions in that class but it seems to give incorrect results, or probably I’m using it wrong. I am first using ‘project’ to find the CesiumGeoreference origin in web mercator space (they appear to be correct). But then I am adding my web mercator coordinates to the x and y of that origin and doing unproject. The result are geographic coordinates that are a fair bit off. (10000m = about 7700m).
Can you share your code? Adding your coordinates to something derived from the CesiumGeorefence origin doesn’t sound right, but if I can see your code I’ll know for sure.
The simLocGeo latitude and longitude is exactly the same as the GeoReference origin I have set in the editor. I expect (perhaps erroneously) the testCarto latitude and longitude to be located at 10000x10000 meters on the globe in relation to the origin. However, It is at around 7700x7700 meters.
Your code looks right to me, and I can believe that ~7700 meters is correct. Keep in mind that Web Mercator meters are not actually meters. They get larger as you get further from the equator.
No, I don’t believe any projection does (or can) have that property. You can instead use a local Cartesian coordinate system centered at a point on the Earth, but that wouldn’t be considered a projection. And if set up your coordinate systemn so that Z=0 is Mean Sea Level at a particular point on Earth, then a little distance away from that point, Mean Sea Level would be below Z=0 due to Earth curvature. Think of Z=0 as a plane touching the Earth at a point, and the curved Earth falls away beneath it.