Hey guys, I noticed a few issues that are being worked on polylines. I was just wondering if these modifications include making them render curved correctly along the sphere like polygons currently are?
Hi Jonah,
The polyline changes are to improve performance for a large number of a polylines. We have plans for geodesic and rhumb line interpolators that sub-sample points so the polylines approximately matches the ellipsoid’s curvature; however, these are not part of the current polyline effort.
In the meantime, you should be able to easily port some C# code that Kevin and I wrote a while back to compute a great arc, which is pretty close to a geodesic (I believe a geodesic on a sphere is a great arc). See ComputeCurve:
https://github.com/virtualglobebook/OpenGlobe/blob/master/Source/Core/Geometry/Ellipsoid.cs
Regards,
Patrick
Thanks for that information, Patrick.
Hi Patrick,
I'm pretty new to Cesium and virtual globes in general.
My goal is to draw a polyline on the surface of the globe.
So I picked the ComputeCurve C# function and transformed it to Javascript:
computeCurve: function(start, stop, granularity)
{
var earth = Cesium.Ellipsoid.WGS84;
if (granularity <= 0.0)
{
console.log('Granularity must be greater than zero.');
}
var normal = Cesium.Cartesian3.normalize(Cesium.Cartesian3.cross(start,stop));
var theta = Cesium.Cartesian3.angleBetween(start,stop) * (180/Math.PI);
var n = Math.max((theta / granularity) - 1, 0);
var positions = new Array();
positions.push(start);
for (var i = 1; i <= n; ++i)
{
var phi = (i * granularity);
positions.push(earth.scaleToGeocentricSurface( start.rotateAroundAxis( normal, phi)));
}
positions.push(stop);
return positions;
},
but the rotateAroundAxis no longer exists in Cartesian3. So I went to https://github.com/AnalyticalGraphicsInc/cesium/pull/106/files and took it.
Anyway, the graphic result on this was not a smooth polyline on the globe surface but something more like this http://img.wonderhowto.com/img/69/63/63456506790428/0/create-concentric-circles-ellipses-cardioids-more-using-straight-lines-and-circle.w654.jpg
var curve = me.computeCurve(cartesianStartPos, cartesianEndPos, 0.5);
xpolyline.setPositions(curve);
xprimitives.add(xpolylines);
Is there now anything on Cesium that could help me to draw this line/curve? Or can you point me out a solution for this?
Any help would be appreciated,
Thank you
Instead of using that, use the new-ish EllipsoidGeodesic.
Patrick
Thank you Patrick,
that was really helpful
Hi Patrick
Do you have a working example of using the EllipsoidGeodesic to draw an arc between 2 points?
And would the EllipsoidGeodesic solution also be the best way of drawing the arc?
I raised the question here - http://stackoverflow.com/questions/22280416/cesium-js-best-way-to-get-an-array-of-points-for-an-arc, hoping someone from the Cesium team can help.
Brandon
Hi Brandon,
I am also working this too. Below is what I have right now. It didn’t work. I’ve tried to add the instance of EllipsoidGeodesic to polylines and primitive in order to display the arc onto the globe, but none of them worked. I will let you know if I figure it out, and if you have some new idea, please let me know.
Steven
var widget = new Cesium.CesiumWidget(‘cesiumContainer’);
var scene = widget.scene;
var ellipsoid = widget.centralBody.getEllipsoid();
var primitives = scene.getPrimitives();
// var polylines = new Cesium.PolylineCollection();
var firstPoint = new Cesium.Cartographic.fromDegrees(-180, 0);
var secondPoint = new Cesium.Cartographic.fromDegrees(180,0);
var geodesic = new Cesium.EllipsoidGeodesic(firstPoint, secondPoint, ellipsoid);
// polylines.add(lineInstance);
var primitive = new Cesium.Primitive(geodesic);
primitives.add(primitive);
在 2014年3月11日星期二UTC-7上午5时51分32秒,Brandon Chen写道:
See this discussion: https://groups.google.com/forum/#!topic/cesium-dev/dMcJG0hgbKY
There’s been some minor breaking changes to the Cesium API since then so the code examples may need minor updates. See CHANGES.md.
Patrick