# x,y,z coordinates relative to lat,long,height

**URL:** <https://community.cesium.com/t/x-y-z-coordinates-relative-to-lat-long-height/7060>\
**Category:** CesiumJS\
**Created:** [June 20, 2018, 4:35pm UTC](https://community.cesium.com/t/x-y-z-coordinates-relative-to-lat-long-height/7060 "2018-06-20T16:35:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick.ht.janssen](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@patrick.ht.janssen](https://community.cesium.com/u/patrick.ht.janssen)\
**Post date:** [June 20, 2018, 4:35pm UTC](https://community.cesium.com/t/x-y-z-coordinates-relative-to-lat-long-height/7060/1 "2018-06-20T16:35:53Z")

</div>

**1. A concise explanation of the problem you’re experiencing.**

I want to use the Cesium.Cartesian3.fromArray() coordinates, so that I can work in xyz. Then when I create my entity, I want to position it somewhere on the globe relative to an origin specified in degrees, so my xyz origin gets moved.

**2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.**

var viewer = new Cesium.Viewer(‘cesiumContainer’);

//create points using xyz

var points3 = ;

points3.push(Cesium.Cartesian3.fromArray([0, 0, 0]));

points3.push(Cesium.Cartesian3.fromArray([1e5, 0, 0]));

points3.push(Cesium.Cartesian3.fromArray([1e5, 1e5, 0]));

console.log(points3);

//create the polygon

var redPolygon = viewer.entities.add({

name : ‘Red polygon on surface’,

position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),

polygon : {

hierarchy : points3,

material : Cesium.Color.RED

}

});

viewer.zoomTo(viewer.entities);

**3. Context. Why do you need to do this? We might know a better way to accomplish your goal.**

I am generating different building designs, I do not want to work in degrees.

**4. The Cesium version you’re using, your operating system and browser.**

Cesium sandbox, Windows 7, Chrome 67

---

<div class="post-metadata">

**Author:** ![patrick.ht.janssen](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@patrick.ht.janssen](https://community.cesium.com/u/patrick.ht.janssen)\
**Post date:** [June 21, 2018, 10:19am UTC](https://community.cesium.com/t/x-y-z-coordinates-relative-to-lat-long-height/7060/2 "2018-06-21T10:19:34Z")

</div>

I have been trying another approach using instances, but I am getting another error.  
What I am expecting is a box to be located somewhere left of africa, 10k x 10k meters in size, extruded up 10k meters.

I think I am misunderstanding something fundamental about Cartesian3 coordinate system. Or maybe about the modelMatrix transformation, I am not sure. Any help would be much appreciated.

var viewer = new Cesium.Viewer(‘cesiumContainer’);  
var scene = viewer.scene;

var points = [  
new Cesium.Cartesian3(0, 0, 0),  
new Cesium.Cartesian3(1e4, 0, 0),  
new Cesium.Cartesian3(1e4, 1e4, 0),  
new Cesium.Cartesian3(0, 1e4, 0)  
];

console.log(points);

var geom = new Cesium.PolygonGeometry({  
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX\_FORMAT,  
polygonHierarchy : new Cesium.PolygonHierarchy(points),  
extrudedHeight: 1e4  
});

var m1 = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(0, 0));

console.log(m1);

var ins1 = new Cesium.GeometryInstance({  
geometry : geom,  
modelMatrix : Cesium.Matrix4.multiplyByTranslation(m1, new Cesium.Cartesian3(0.0, 0.0, 0.0), m1),  
attributes : {  
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE)  
}  
});

scene.primitives.add(new Cesium.Primitive({  
geometryInstances : [ins1],  
appearance : new Cesium.PerInstanceColorAppearance({  
translucent : false,  
closed : true  
})  
}));

``

The error I get is as follows

An error occurred while rendering. Rendering has stopped.

DeveloperError: normalized result is not a number  
Error  
at new DeveloperError ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:89:19](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:89:19))  
at Function.Cartesian3.normalize ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:1855:19](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:1855:19))  
at EllipsoidTangentPlane.projectPointOntoPlane ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:25026:20](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:25026:20))  
at EllipsoidTangentPlane.projectPointsOntoPlane ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:25071:26](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:25071:26))  
at Object.PolygonGeometryLibrary.polygonsFromHierarchy ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:31845:44](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:31845:44))  
at Function.PolygonGeometry.createGeometry ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:33157:46](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:33157:46))  
at createPolygonGeometry ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:33341:32](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:33341:32))  
at createGeometry ([https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:30450:30](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:30450:30))  
at [https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:30338:42](https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:30338:42)

``

---

<div class="post-metadata">

**Author:** ![patrick.ht.janssen](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@patrick.ht.janssen](https://community.cesium.com/u/patrick.ht.janssen)\
**Post date:** [June 21, 2018, 5:04pm UTC](https://community.cesium.com/t/x-y-z-coordinates-relative-to-lat-long-height/7060/3 "2018-06-21T17:04:44Z")

</div>

After a little more research, I can see that the Cartesian3 uses the ECEF (“earth-centered, earth-fixed”) coordinate system.

But I still cannot figure out why the code in the previous post does not work. The ModelMatrix should transform the polygon drawn at the centre of ECEF origin to a location on the surface of the earth, in this case (0,0).

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [June 26, 2018, 2:00pm UTC](https://community.cesium.com/t/x-y-z-coordinates-relative-to-lat-long-height/7060/4 "2018-06-26T14:00:44Z")

</div>

Hey there,

In your examples, make sure you are passing the right types to functions. I think you may be getting a few errors passing, for example, Cartesian3 objects where a Matrix4 is expected.

It looks like you could use the same solution proposed in this [thread](https://groups.google.com/forum/#!searchin/cesium-dev/matrix%2420geometry%7Csort:date/cesium-dev/PpNZCyvARrw/c1lnvfS2CQAJ). Let me know if you have any luck with that.

Thanks,

Gabby
