Extract intersection between a plane defined by 3 points and the terrain

Hello,

Let’s 3 points A, B and C forming a triangle ABC.
C is the position of a Cesum camera.

These points are included in a plane, by definition.

I would like to extract the intersection line (3D geometry as WKB/WKT or GeoJSON) of this plane with the terrain, especially the portion between point A’ and B’.

  • A’ being the intersection of the ray \vec{CA} with the terrain, if it exists.
  • B’ being the intersection of the ray \vec{CB} with the terrain, if it exists.

From here, three situations are possible:

  • If A’ and B’ doesn’t exist, the returned geometry should be null (i.e. both rays are toward the sky).
  • If either A’ or B’ exists, the geometry should be a 3D line starting from that point, and having a defined length, e.g. 50km (note that this line geometry is fully included in the plane ABC).
  • If both A’ and B’ exists, the line is simply the line between A’ and B’.

This looks like a simple problem but the more I’m thinking of it, the more ‘not so simple’ it is…
Which tool can I use to achieve that in a performant way? I’m starting from scratch.
Thanks.