 # Need a working example of Ray intersection and an Ellipsoid

Hi,
Can some one give me a working example of how I can find the intersection point of an Ellipsoid with a Ray?

I have tried a lot but could not find a way to make it work…thanks very much

This is a code which I have written

``````var origin=  new Cesium.Cartesian3(x, y, 0);
var direction=  new Cesium.Cartesian3(a, b, 0);
var ray=new Cesium.Ray(origin, direction);
``````

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

``````var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, cartesianPosition);
var point = Cesium.Ray.getPoint(ray, intersection.start);

``

thanks very much``````

It would be helpful to include the values for x, y, a, and b in your example.

Here’s an example using the Earth’s ellipsoid.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var globe = viewer.scene.globe;

var ellipsoid = globe.ellipsoid;

console.log("e0: " + ellipsoid);

var p0 = Cesium.Cartesian3.fromDegrees(0.0, 0.0, 10000.0);

var p1 = new Cesium.Cartesian3(-1.0, 0.0, 0.0);

var ray = new Cesium.Ray(p0, p1);

console.log("p0: "+ p0);

console.log("p1: "+ p1);

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

console.log("i0: " + intersection);

if ((intersection !== undefined) && (intersection !== null)) {

``````var point = Cesium.Ray.getPoint(ray, intersection.start);

console.log("pi: " + point);
``````

}

``

Dear Scott,
thank you so much,I had a problem with my laptop today I’ll do as you said,

Can you give me a tip how to show a custom ellipsoid on map as entity??