# Unproject cartesian to cartesian

**URL:** https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163
**Category:** Cesium for Unreal
**Created:** [June 19, 2024, 6:41am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163 "2024-06-19T06:41:59Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 19, 2024, 6:42am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/1 "2024-06-19T06:42:00Z")

</div>

Hi!

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.

Best  
Rikard

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 19, 2024, 6:45am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/2 "2024-06-19T06:45:06Z")

</div>

Just to clarify, the points are placed in reference to a web mercator projected map.

---

<div class="post-metadata">

### Author: ![arbertrary](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/arbertrary/32/16330_2.png) [@arbertrary](https://community.cesium.com/u/arbertrary)
#### Post date: [June 19, 2024, 9:02am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/3 "2024-06-19T09:02:07Z")

</div>

There are functions to transform ECEF or LongitudeLatitude coordinates to Unreal positions and vice versa. Is this what you are looking for?

 ![grafik](https://global.discourse-cdn.com/cesium/original/3X/c/4/c43a1172bab7aa60cf2e61284fa12c7edd2ffda8.png)

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 19, 2024, 10:23am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/4 "2024-06-19T10:23:23Z")

</div>

Thank you arbertrary,

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.

Best  
Rikard

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 19, 2024, 10:27am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/5 "2024-06-19T10:27:56Z")

</div>

There seems to exist such functions in the javascript library. But I cannot find the same in the unreal plugin: [WebMercatorProjection - Cesium Documentation](https://cesium.com/learn/cesiumjs/ref-doc/WebMercatorProjection.html)

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [June 20, 2024, 12:37am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/6 "2024-06-20T00:37:14Z")

</div>

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](https://github.com/CesiumGS/cesium-native/blob/main/CesiumGeospatial/include/CesiumGeospatial/WebMercatorProjection.h) 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.

If that doesn’t work for you, you can also consider using Unreal’s built-in Georeferencing plugin, which can do arbitrary transformations with PROJ. I believe it’s Blueprint-accessible as well:  
[https://dev.epicgames.com/documentation/en-us/unreal-engine/georeferencing-a-level-in-unreal-engine](https://dev.epicgames.com/documentation/en-us/unreal-engine/georeferencing-a-level-in-unreal-engine)

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 20, 2024, 7:46am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/7 "2024-06-20T07:46:24Z")

</div>

That’s great news. I can use the WebMercatorProjection functions using C++. Thank you Kevin.

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 24, 2024, 9:50am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/8 "2024-06-24T09:50:34Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [June 24, 2024, 10:34pm UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/9 "2024-06-24T22:34:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 25, 2024, 7:40am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/10 "2024-06-25T07:40:34Z")

</div>

Of course. I apologize I didn’t do it to begin with:

```auto
CesiumGeospatial::WebMercatorProjection projection(CesiumGeospatial::Ellipsoid::WGS84);
FVector originDegrees = CesiumGeoreference->GetOriginLongitudeLatitudeHeight();
CesiumGeospatial::Cartographic originCartoGraphic(originDegrees.X * (pi / 180.0), originDegrees.Y * (pi / 180.0), originDegrees.Z);
SimLocation = projection.project(originCartoGraphic);
CesiumGeospatial::Cartographic simLocGeo = projection.unproject(glm::dvec3(SimLocation.x, SimLocation.y, SimLocation.z));
CesiumGeospatial::Cartographic testCarto = projection.unproject(glm::dvec3(10000.0 + SimLocation.x, 10000.0 + SimLocation.y, SimLocation.z));

UE_LOG(LogTemp, Warning, TEXT(simLocGeo is lon: %f . lat: %f . %f), simLocGeo.longitude * (180.0 / pi), simLocGeo.latitude * (180.0 / pi), simLocGeo.height);
UE_LOG(LogTemp, Warning, TEXT(testCarto is lon: %f . lat: %f . %f), testCarto.longitude * (180.0/pi), testCarto.latitude * (180.0 / pi), testCarto.height);

```

Output:

```auto
LogTemp: Warning: simLocGeo is lon: -105.104505 . lat: 39.409924 . 2250.000000
LogTemp: Warning: testCarto is lon: -105.014673 . lat: 39.479295 . 2250.000000

```

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.

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [June 27, 2024, 11:28am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/11 "2024-06-27T11:28:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Rikard](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rikard/32/14037_2.png) [@Rikard](https://community.cesium.com/u/Rikard)
#### Post date: [June 27, 2024, 3:08pm UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/12 "2024-06-27T15:08:59Z")

</div>

Aha. Then I suppose I have some learning to do. I thought that a meter in projected space would amount to a meter on the globe after you unproject it.

Thank you

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [June 30, 2024, 1:32am UTC](https://community.cesium.com/t/unproject-cartesian-to-cartesian/33163/13 "2024-06-30T01:32:37Z")

</div>

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.
