I have two lines on a plot and I want Julia to find the intersection between the two lines but I can’t seem to find a package that can help with that.
fill_between function uses the
gmtspatial module to do that.
basically, if we don’t have explicit function expression, the curve is a set of data
simplify way is link two points to segment ,then check whether two segment intersect
this is naive method.
But I thought this is not a simple question, for numerical method, neighbors are problem
- package Meshes.jl for Segment method
using Meshes s1 = Segment((0.0,0.0), (1.0,0.0)) s2 = Segment((0.5,0.0), (2.0,0.0)) inst=s1 ∩ s2
if segment does’nt intersect, then return nothing
iterate to find intersection point
using Meshes step = 100 xspan = range(-2, 2, step) arr =  d1 = [(x, x^2) for x in xspan] .|> (d -> (round(d, digits=4), round(d, digits=4))) d2 = [(x, 2 * x) for x in xspan] .|> (d -> (round(d, digits=4), round(d, digits=4))) for i in 1:step-1 local s1 = Segment(d1[i], d1[i+1]) local s2 = Segment(d2[i], d2[i+1]) local bool = s1 ∩ s2 |> d -> (typeof(d) == Point2) (bool == true) && push!(arr, res) end arr