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

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

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

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)
}
});

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)
at Function.Cartesian3.normalize (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)
at EllipsoidTangentPlane.projectPointsOntoPlane (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)
at Function.PolygonGeometry.createGeometry (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:33157:46)
at createPolygonGeometry (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createPolygonGeometry.js:33341:32)
at createGeometry (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:30450:30)
at https://cesiumjs.org/Cesium/Build/CesiumUnminified/Workers/createGeometry.js:30338:42

``

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

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. Let me know if you have any luck with that.

Thanks,

Gabby