# Polyline issues question

**URL:** <https://community.cesium.com/t/polyline-issues-question/52>\
**Category:** CesiumJS\
**Created:** [July 9, 2012, 5:14pm UTC](https://community.cesium.com/t/polyline-issues-question/52 "2012-07-09T17:14:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonah\_Taylor](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@Jonah\_Taylor](https://community.cesium.com/u/Jonah_Taylor)\
**Post date:** [July 9, 2012, 5:14pm UTC](https://community.cesium.com/t/polyline-issues-question/52/1 "2012-07-09T17:14:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![patrick](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/patrick/32/2045_2.png) [@patrick](https://community.cesium.com/u/patrick)\
**Post date:** [July 9, 2012, 7:50pm UTC](https://community.cesium.com/t/polyline-issues-question/52/2 "2012-07-09T19:50:06Z")

</div>

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](https://github.com/virtualglobebook/OpenGlobe/blob/master/Source/Core/Geometry/Ellipsoid.cs)

Regards,

Patrick

---

<div class="post-metadata">

**Author:** ![Jonah\_Taylor](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@Jonah\_Taylor](https://community.cesium.com/u/Jonah_Taylor)\
**Post date:** [July 9, 2012, 8:08pm UTC](https://community.cesium.com/t/polyline-issues-question/52/3 "2012-07-09T20:08:48Z")

</div>

Thanks for that information, Patrick.

---

<div class="post-metadata">

**Author:** ![andreas.silva1](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@andreas.silva1](https://community.cesium.com/u/andreas.silva1)\
**Post date:** [November 14, 2013, 5:39pm UTC](https://community.cesium.com/t/polyline-issues-question/52/4 "2013-11-14T17:39:33Z")

</div>

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)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var earth = Cesium.Ellipsoid.WGS84;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (granularity \<= 0.0)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('Granularity must be greater than zero.');  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var normal = Cesium.Cartesian3.normalize(Cesium.Cartesian3.cross(start,stop));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var theta = Cesium.Cartesian3.angleBetween(start,stop) \* (180/Math.PI);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var n = Math.max((theta / granularity) - 1, 0);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var positions = new Array();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;positions.push(start);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 1; i \<= n; ++i)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var phi = (i \* granularity);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;positions.push(earth.scaleToGeocentricSurface( start.rotateAroundAxis( normal, phi)));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;positions.push(stop);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return positions;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},

but the rotateAroundAxis no longer exists in Cartesian3. So I went to [https://github.com/AnalyticalGraphicsInc/cesium/pull/106/files](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](http://img.wonderhowto.com/img/69/63/63456506790428/0/create-concentric-circles-ellipses-cardioids-more-using-straight-lines-and-circle.w654.jpg)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var curve = me.computeCurve(cartesianStartPos, cartesianEndPos, 0.5);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xpolyline.setPositions(curve);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![patrick](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/patrick/32/2045_2.png) [@patrick](https://community.cesium.com/u/patrick)\
**Post date:** [November 15, 2013, 1:38pm UTC](https://community.cesium.com/t/polyline-issues-question/52/5 "2013-11-15T13:38:02Z")

</div>

Instead of using that, use the new-ish [EllipsoidGeodesic](http://cesium.agi.com/Cesium/Build/Documentation/EllipsoidGeodesic.html).

Patrick

---

<div class="post-metadata">

**Author:** ![andreas.silva1](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@andreas.silva1](https://community.cesium.com/u/andreas.silva1)\
**Post date:** [November 15, 2013, 2:44pm UTC](https://community.cesium.com/t/polyline-issues-question/52/6 "2013-11-15T14:44:51Z")

</div>

Thank you Patrick,

that was really helpful

---

<div class="post-metadata">

**Author:** ![Brandon\_Chen](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@Brandon\_Chen](https://community.cesium.com/u/Brandon_Chen)\
**Post date:** [March 11, 2014, 12:51pm UTC](https://community.cesium.com/t/polyline-issues-question/52/7 "2014-03-11T12:51:32Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://community.cesium.com/u/Steven)\
**Post date:** [March 11, 2014, 10:08pm UTC](https://community.cesium.com/t/polyline-issues-question/52/8 "2014-03-11T22:08:59Z")

</div>

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写道：

---

<div class="post-metadata">

**Author:** ![patrick](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/patrick/32/2045_2.png) [@patrick](https://community.cesium.com/u/patrick)\
**Post date:** [March 12, 2014, 1:04pm UTC](https://community.cesium.com/t/polyline-issues-question/52/9 "2014-03-12T13:04:30Z")

</div>

See this discussion: [https://groups.google.com/forum/#!topic/cesium-dev/dMcJG0hgbKY](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](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/CHANGES.md).

Patrick
