4

Cesium polylines follow the curvature of the earth, between two points, by default. How do I make arcs, which go above the ground, like in this example?

http://armsglobe.chromeexperiments.com/

1

1 Answer 1

2

From https://groups.google.com/forum/#!topic/cesium-dev/anp15p-DIew

function addLines(pointA,pointB){ 

var earth = Cesium.Ellipsoid.WGS84;
// start and end points on the surface of the earth 
var startPoint = earth.cartographicToCartesian(Cesium.Cartographic.fromDegrees(pointA[0][0], pointA[0][1], 0.0)); 
var endPoint = earth.cartographicToCartesian(Cesium.Cartographic.fromDegrees(pointB[0][0], pointB[0][1], 0.0)); 


// determine the midpoint (point will be inside the earth) 
var midpointCartesian = startPoint.add(endPoint).divideByScalar(2.0); 

// move the midpoint to the surface of the earth 
earth.scaleToGeodeticSurface(midpointCartesian); 

// add some altitude if you want (1000 km in this case) 
var midpointCartographic = earth.cartesianToCartographic(midpointCartesian); 
midpointCartographic.height = 1000000; 
midpointCartesian = earth.cartographicToCartesian(midpointCartographic); 

// create a hermite spline that goes through these three points 
var hermiteSpline = new Cesium.HermiteSpline( [ 
    {point: startPoint, time: 0.0}, 
    {point: midpointCartesian, time: 0.5}, 
    {point: endPoint, time: 1.0} 
]); 

// create a 20 point polyline that follows the spline 
var polylinePoints = []; 
for(var i=0; i<20; ++i) { 
    polylinePoints.push(hermiteSpline.evaluate(i/20)); 
} 

var polylineCollection = new Cesium.PolylineCollection(); 
var polyline = polylineCollection.add(); 
polyline.setPositions(polylinePoints); 

var primitives = widget.scene.getPrimitives(); 
primitives.add(polylineCollection); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.