Dear all,
I think that this is not a Cesium issue, but I’m facing a strange behaviour in computing positions over a circumference. Sorry for that, but I’m a little bit rusty with trigonometry.
1. A concise explanation of the problem you’re experiencing.
I would like to calculate the evenly spaced position of some object around a circumference dynamically.
2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.
//Loop on the nodes
$.each(microservices,function(index,microservice){
var centerLat = 46.0702531;
var centerLon = 11.1216386;
var coordinates = pointOnCircle(radius, index, microservices.length, centerLat, centerLon);
var position = Cesium.Cartesian3.fromDegrees(coordinates.lon, coordinates.lat, settings.microservicesList.apparence.nodes.maxHeight);
var entity = microservicesNodesDataSource.entities.add({
position : position,
category : “microservice”,
id : microservice.id,
ellipsoid : {
radii : new Cesium.Cartesian3(entityRadius, entityRadius, entityRadius),
material : materialColor
}
});
});
//The function to calculate the positions
function pointOnCircle(radius, currentPointIndex, totalPoints, centerLat, centerLon) {
var cartesianCenter = new Cesium.Cartesian3.fromDegrees(centerLon, centerLat, 0);
var theta = (Cesium.Math.TWO_PI / totalPoints);
var angle = (theta * currentPointIndex);
cartesianCenter.x = cartesianCenter.x + (radius * Math.cos(angle));
cartesianCenter.y = cartesianCenter.y + (radius * Math.sin(angle));
var carto = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesianCenter);
var newLon = Cesium.Math.toDegrees(carto.longitude);
var newLat = Cesium.Math.toDegrees(carto.latitude);
return {lat: newLat, lon: newLon};
}
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I have an array of elements in a JSON structure and for each element I call the pointOnCircle function in order to compute the position with the following parameters:
- radius : radius of the circumference
- index : the number of the element in the loop
- microservices.length : totol number of the elements to visualize
- centerLat : latitude of the center of the circumference
- centerLon : longitudeof the center of the circumference
The following image rappresents the result, as you can see not all the points are on the perimeter:
What am I doing wrong?
4. The Cesium version you’re using, your operating system and browser.
Cesium-1.41