Uncaught TypeError: Cannot read property 'x' of undefined o.multiplyComponents @ Cesium.js:423

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 ***

Hello,

Please read the documentation for Ellipsoid: http://cesiumjs.org/Cesium/Build/Documentation/Ellipsoid.html

You can’t do Ellipsoid.fromCartesian3, not Ellipsoid.WGS84.fromCartesian3

Best,

Hannah

Hi dear Hannah,
Thanks for your answer, I chacked and I used one of samples from documention

I used this code

var position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);
var cartesianPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);

``

and It works fine,But again on this line I face an error

var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, cartesianPosition);

``

this is error

Uncaught TypeError: Cannot read property ‘x’ of undefined

``

In fact I want to find the intersection point of a ray with an object,Here an ellipsoid…

Can you please help me find my mistake?

thanks

See the documentation for IntersectionTests.rayEllipsoid
You are passing in a ray and a position. You need to pass in a ray and an ellipsoid

-Hannah

Dear Hannah,
Thanks for your help.Now I got my problem,But can you help me how to show the resulted Ellipsoid on viewer?this code does not work

var elip =new Cesium.Ellipsoid(17832.12, 83234.52, 952313.73);

viewer.entities.add(elip );


``

Please see this sandcastle example for how to add an ellipsoid:

-Hannah

Thanks dear Hannah,
It seems this code should work but does not…can you please give me some hint?

var elip =new Cesium.Ellipsoid(300000.0, 300000.0,200000.0);

var redSphere = viewer.entities.add({
    name : 'Red sphere with black outline',
    position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
    ellipsoid : {
        radii : elip,
        material : Cesium.Color.RED.withAlpha(0.5),
        outline : true,
        outlineColor : Cesium.Color.BLACK
    }
});

``