Intersection of polyline with relief in cesium

I am using Cesium and am trying to detect where the polyline intersects with the ground on Earth. I have a polyline that starts at some point in the air and stretches towards the Earth at a certain angle.

Right now I only calculate the end point using the given distance, so I have a start and an end. I want to determine where this polyline first hits the surface of the Earth and stops drawing it at that point. For example, if there is a high mountain, I do not want the line to continue on the other side of the mountain.

I have tried several different approaches using IntersectionTests

in particular grazingAltitudeLocation

and rayEllipsoid

but no luck. I create a ray with the start and end points of my polyline and then using it viewer.scene.globe.ellipsoid

as an ellipsoid in functions. I keep getting the starting point returned as the intersection point.

Does anyone know what I am doing wrong, or suggestions differently? Any help would be greatly appreciated.

EDIT: this is the edited / added content

Here is the code I used, it grazingAltitudeLocation

returns the starting point and rayEllipsoid

returns undefined.

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
var globe = scene.globe;
var ellipsoid = scene.globe.ellipsoid;
var primitives = scene.primitives;

globe.depthTestAgainstTerrain = true;

var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({url : '//cesiumjs.org/stk-terrain/tilesets/world/tiles'});
scene.terrainProvider = cesiumTerrainProviderMeshes;

var startLon = -117.69;
var startLat = 35.69;
var startElv = 20000;
var endLon = -120.0417;
var endLat = 39.0917;
var endElv = 0;

var startCart = Cesium.Cartographic.fromDegrees(startLon, startLat, startElv);
var start = ellipsoid.cartographicToCartesian(startCart);

var endCart = Cesium.Cartographic.fromDegrees(endLon, endLat, endElv);
var end = ellipsoid.cartographicToCartesian(endCart);

var ray = new Cesium.Ray(start, end);

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

var intersection2 = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid);
var point = Cesium.Ray.getPoint(ray, intersection2.start);

      

+3


source to share


1 answer


I think you should make your choice on the Globe , not the ellipsoid. Hope this helps:

function pickGlobeIntersection(viewer, p0, p1) {
      //all positions are in Cartesian3
      var direction = new Cesium.Cartesian3();
      Cesium.Cartesian3.subtract(p1, p0, direction);
      Cesium.Cartesian3.normalize(direction, direction);

      var ray = new Cesium.Ray(p0, direction);
      var hitPos = viewer.scene.globe.pick(ray, viewer.scene);

      if ((hitPos !== undefined) && (hitPos !== null)) {
        return hitPos;
      } else {
        return null;
      }
}

      



Hello

0


source







All Articles