Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. function addLines(pointA,pointB){
  2.  
  3. var earth = Cesium.Ellipsoid.WGS84;
  4. // start and end points on the surface of the earth
  5. var startPoint = earth.cartographicToCartesian(Cesium.Cartographic.fromDegrees(pointA[0][0], pointA[0][1], 0.0));
  6. var endPoint = earth.cartographicToCartesian(Cesium.Cartographic.fromDegrees(pointB[0][0], pointB[0][1], 0.0));
  7.  
  8.  
  9. // determine the midpoint (point will be inside the earth)
  10. var midpointCartesian = startPoint.add(endPoint).divideByScalar(2.0);
  11.  
  12. // move the midpoint to the surface of the earth
  13. earth.scaleToGeodeticSurface(midpointCartesian);
  14.  
  15. // add some altitude if you want (1000 km in this case)
  16. var midpointCartographic = earth.cartesianToCartographic(midpointCartesian);
  17. midpointCartographic.height = 1000000;
  18. midpointCartesian = earth.cartographicToCartesian(midpointCartographic);
  19.  
  20. // create a hermite spline that goes through these three points
  21. var hermiteSpline = new Cesium.HermiteSpline( [
  22. {point: startPoint, time: 0.0},
  23. {point: midpointCartesian, time: 0.5},
  24. {point: endPoint, time: 1.0}
  25. ]);
  26.  
  27. // create a 20 point polyline that follows the spline
  28. var polylinePoints = [];
  29. for(var i=0; i<20; ++i) {
  30. polylinePoints.push(hermiteSpline.evaluate(i/20));
  31. }
  32.  
  33. var polylineCollection = new Cesium.PolylineCollection();
  34. var polyline = polylineCollection.add();
  35. polyline.setPositions(polylinePoints);
  36.  
  37. var primitives = widget.scene.getPrimitives();
  38. primitives.add(polylineCollection);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement