Hi,

here’s a solution in python. It does the following

- gets the equation of the line
- interpolates the spline with a given stepsize. This determines accuracy of the solution
- It calculates how far each interpolated point is from being on the line
- finds the points on the spline with the stepsize of the line

Here’s the code and some screenshots

Cheers,

Chris

### 1 solution

### 0 solutions

### 4 solutions

```
from ij import IJ
imp = IJ.getImage()
# get the roi manager
from ij.plugin.frame import RoiManager
roim = RoiManager.getInstance()
# I'm storing the spline roi first and the line second
spline = roim.getRoi(0)
line = roim.getRoi(1)
# get the points of
x0,x1=line.getPolygon().xpoints
y0,y1=line.getPolygon().ypoints
# get finely spaced points from the spline
# the smaller you make the step the more accurate the intersection
ds=0.2
poly = spline.getInterpolatedPolygon(-ds,True)
xpoints = poly.xpoints
ypoints = poly.ypoints
def deviaton_from_line( x,y, x0,y0, x1,y1):
from math import sqrt
# if x,y are on line formed by (x1,y0) and (x1,y1)
# this returns 0
# see https://en.wikipedia.org/wiki/Line_(geometry)#On_the_Cartesian_plane
# and https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
a = (y1-y0)
b = (x1-x0)
return abs(a*(x-x0)-b*(y-y0))/sqrt(a*a+b*b)
# calculate the deviation for the points in the line
dev = [ deviaton_from_line(x,y, x0,y0, x1,y1) for x,y in zip(xpoints,ypoints) ]
# find maximun with the stepsize
from ij.plugin.filter import MaximumFinder
indx = MaximumFinder.findMinima(dev, ds,False)
# keep solutions less tha 2*the stepsize
sols_x = [ xpoints[i] for i in indx if dev[i]<2*ds ]
sols_y = [ ypoints[i] for i in indx if dev[i]<2*ds ]
# plot the points
from ij.gui import PointRoi
point = PointRoi( sols_x, sols_y )
imp.setRoi( point)
```