How to create a ring?

1,007 views
Skip to first unread message

pim.res...@gmail.com

unread,
Apr 14, 2014, 2:46:18 AM4/14/14
to cesiu...@googlegroups.com
Hi,All,
Cesium can create an ellipse. But, there is no method to create a ring. Does it have official way to create a ring. Or, How to create it from scratch?

Thanks,
-Jonathan

skaug...@gmail.com

unread,
Apr 14, 2014, 12:41:50 PM4/14/14
to cesiu...@googlegroups.com, pim.res...@gmail.com

If you want just a circle, there's an example of an Outline Circle in the Circles and Ellipses Sandcastle example: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Circles%20and%20Ellipses.html&label=Showcases

pim.res...@gmail.com

unread,
Apr 14, 2014, 11:47:49 PM4/14/14
to cesiu...@googlegroups.com, pim.res...@gmail.com, skaug...@gmail.com

Sorry, what I need is a hollow circle. The APIs, demoed in this showcase, is just able to draw a circle not hollow circle.

bmc...@gmail.com

unread,
Apr 15, 2014, 12:05:31 PM4/15/14
to cesiu...@googlegroups.com, pim.res...@gmail.com, skaug...@gmail.com
Well, that's not true. Click on the link above.

researcher pim

unread,
Apr 16, 2014, 12:13:51 PM4/16/14
to bmc...@gmail.com, cesiu...@googlegroups.com, skaug...@gmail.com
Hi,
Attachment is what I need. Could you drop me a snipped to show how to draw such hollow circle?

Thanks a lot,
-Jonathan
test.jpg

skaug...@gmail.com

unread,
Apr 16, 2014, 12:47:33 PM4/16/14
to cesiu...@googlegroups.com, bmc...@gmail.com, skaug...@gmail.com, pim.res...@gmail.com
Well there's 2 ways to do this, one is in the example above. You can do it by just changing the width of the polyline. This might not give the desired results because the line width stays the same regardless of the zoom level.

The other way is to use the polygonHierarchy property of the Cesium.Polygon object. You just have to compute 2 circles with different radii, make the outer one the positions and make the inner one a hole.

require(['Cesium'], function(Cesium) {
"use strict";

function createPrimitives(scene, ellipsoid) {
var primitives = scene.primitives;

var outerPositions = Cesium.Shapes.computeCircleBoundary(
ellipsoid,
ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-82.0, 37.0)),
300000.0);
var innerPositions = Cesium.Shapes.computeCircleBoundary(
ellipsoid,
ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-82.0, 37.0)),
200000.0);
var hierarchy = {
positions: outerPositions,
holes: [{
positions: innerPositions
}]
};
var circle = new Cesium.Polygon({
polygonHierarchy: hierarchy
});
circle.material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 0.5);
primitives.add(circle);

}

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.screenSpaceEventHandler.setInputAction(function(movement) {
var pickedPrimitive = viewer.scene.pick(movement.endPosition);
Sandcastle.highlight(pickedPrimitive);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

createPrimitives(viewer.scene, viewer.centralBody.ellipsoid);

Sandcastle.finishedLoading();
});

researcher pim

unread,
Apr 20, 2014, 12:22:44 PM4/20/14
to Scott Przybylski, cesiu...@googlegroups.com, Ben Carlsen
It worked! Thanks a lot.

A further question. How to draw a half hollow circle?  Like attachment.

Thanks,
-Jonathan
fhc.jpg
Reply all
Reply to author
Forward
0 new messages