Hi,
I am going to create a circle and in each degree I create a ray and find the intersection of that ray with surrounding objects,
well, I come up with this code
var viewer = new Cesium.Viewer('cesiumContainer');
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(click) {
var alertText = '';
function addToMessage(key, value) {
alertText += key + ': ' + value + '\n';
}
// var pickedObject = scene.pick(click.position);
// addToMessage('target', pickedObject.id.id);
var position = viewer.camera.pickEllipsoid(click.position);
addToMessage('screenX', click.position.x);
addToMessage('screenY', click.position.y);
addToMessage('didHitGlobe', Cesium.defined(position));
var cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
addToMessage('longitude', cartographicPosition.longitude);
addToMessage('latitude', Cesium.Math.toDegrees(cartographicPosition.latitude));
terrainSamplePositions = [cartographicPosition];
Cesium.sampleTerrain(viewer.terrainProvider, 9, terrainSamplePositions).then(function() {
addToMessage('height', terrainSamplePositions[0].height);
}).always(function() {
// alert(alertText);
});
var x=Cesium.Math.toDegrees(cartographicPosition.latitude);
var y=Cesium.Math.toDegrees(cartographicPosition.longitude);
// alert(x);//35
// alert(y);//-101
var radius=0.01;
var segmants=360;
var seg=Math.PI*2/segmants;
var origin= new Cesium.Cartesian3(x, y, 0);
var shape = [];
for (i = 0; i <= segmants; i++) {
var teta=seg*i;
var a =x+Math.cos(teta)*radius;
var b =y+Math.sin(teta)*radius;
shape.push(a);
shape.push(b);
var origin= new Cesium.Cartesian3(x, y, 0);
var direction= new Cesium.Cartesian3(a, b, 0);
alert(direction.toString());
alert(origin.toString());
var ray=new Cesium.Ray(origin, direction);
var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, cartesianPosition);
alert(intersection.toString());
if(intersection!=undefined){
var point = Cesium.Ray.getPoint(ray, intersection.start);
alert(point.toString());
}
// shape.push(point.x);
/// alert(point.x.toString());
// shape.push(point.y);
}
shape.push(shape[0]);
shape.push(shape[1]);
alert(shape);
var resultPolygon = viewer.entities.add({
name : 'result',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray(shape),
material : Cesium.Color.YELLOW
}
});
viewer.zoomTo(resultPolygon.position);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
position= Cesium.Cartesian3.fromDegrees(-101.2660238862044, 35.334352672773285,0.01);
var cartesianPosition = Cesium.Ellipsoid.WGS84.fromCartesian3(position);
var blueEllipse = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(-101.2660238862044, 35.334352672773285,0.01),
name : 'Blue translucent, rotated, and extruded ellipse with outline',
ellipse : {
semiMinorAxis : 150000.0,
semiMajorAxis : 300000.0,
extrudedHeight : 200000.0,
rotation : Cesium.Math.toRadians(45),
material : Cesium.Color.BLUE.withAlpha(0.5),
outline : true
}
});
``
I know that '***cartesianPosition ’ is an ***Ellipsoid but why it gives me such a error?
***thanks for your help ***