Find intersection of two EllipsoidGeodesics

Is there any way to find the intersection of two EllipsoidGeodesics?

I need to do this in order to calculate where a line, on a specific bearing from a point on the map, intersects another line.

I’ve tried to use vector math to solve this (https://math.stackexchange.com/questions/982521/definite-method-for-finding-the-intersection-of-two-cartesian-lines-in-3d), but I think it is failing because the map in Cesium is an ellipsoid.

Hi Harry,

I’m not 100% sure, but I think you should be able to use the math you’ve provided and EllipsoidGeodesic objects. You can use the interpolate functions to get a location point along the line at t and s for each line respectively.

Thanks,

Gabby

Thanks Gabby.

I found a solution using another library in combination with Cesium - https://github.com/chrisveness/geodesy

Here’s my solution for anyone who encounters the same problem:

let Cesium = require(“cesium”)

let geodesy = require(“geodesy”)

// Convert Cesium.Cartographic to geodesy.LatLonVectors class

function toLatLon(point) {

return new geodesy.LatLonVectors(

Cesium.Math.toDegrees(point.latitude), Cesium.Math.toDegrees(point.longitude));

}

// Create one geodesic

const start1 = new Cesium.Cartographic(-80, 45);

const end1 = new Cesium.Cartographic(-85, 45);

const geod1 = new Cesium.EllipsoidGeodesic(start1, end1);

// Create second geodesic

const start2 = new Cesium.Cartographic(-83, 40);

const end2 = new Cesium.Cartographic(-83, 49);

const geod2 = new Cesium.EllipsoidGeodesic(start2, end2);

/**

  • Get the bearing of the geodesic from the start point

  • Yes, you could probably use EllipsoidGeodesic.startHeading

  • I just prefer to use one library for all the calculations in case there is a difference in math

*/

const start1Vector = toLatLon(start1); // Create start1 geodesy.LatLonVectors

const end1Vector = toLatLon(end1) // Create end1 geodesy.LatLonVectors

const geod1Bearing = start1Vector.bearingTo(end1Vector); // Get bearing

// Do the same for the second geodesic

const start2Vector = toLatLon(start2);

const end2Vector = toLatLon(end2)

const geod2Bearing = start1Vector.bearingTo(end2Vector);

// Caluclate the intersection

const geoIntersect = geodesy.LatLonVectors.intersection(

start1Vector, geod1Bearing, start2Vector, geod2Bearing);

``

Try it with RunKit - https://runkit.com/hnipps/59e8c572ba85c70011243c55

Thanks,

Harry

Awesome, great example. Thanks for following up!

Updated link for the RunKit notebook - runkit.com/hnipps/calculate-geodesic-intersection