# Calculate normals to an irregular curve at the intersection points with a line

1 view (last 30 days)
Yunliang Qi on 17 Jul 2021
Commented: Yunliang Qi on 19 Jul 2021
Hi,
I am trying to calculate normals to an irregular curve at the points where the curve intersects with a line. The curve is like in the picture below.
I have tried the code of 2D Line Curvature and Normals, it works very well for the original points of the curve, but I am not able to find how to calculate the normal at an interstection point.
My first thought was that if the intersection points could be inserted into the original points with the right order, then I could use the code of 2D Line Curvature and Normals to calculate the normals. But this brought another problem, the curve is irregular, I wasn't able to sort the intersection points with the original points in the right order that would not change the curve shape.
My preliminary code is like below. The data has been attached. The intersections function in the code is the Fast and Robust Curve Intersections.
Has anyone dealt with the similar problem? Any suggestion is appreciated.
plot(xdata,ydata,'b')
hold on
axis equal
xline=[210,250];
yline=[250,75];
plot(xline,yline,'r')
[x0,y0,~,~] = intersections(xline,yline,xdata,ydata);
plot(x0,y0,'ro','markersize',10,'linewidth',2)

Simon Chan on 17 Jul 2021
For function 'intersections', you can output the vector 'jout' which is the location of the intersecting points on the segments.
Then you can use this as an index to find the normal near the intersection.
[x0,y0,~,jout] = intersections(xline,yline,xdata,ydata);
idx_lower = floor(jout);
idx_upper = ceil(jout);
plot(x0,y0,'ro','markersize',10,'linewidth',2)
Vertices=[xdata,ydata];
N=LineNormals2D(Vertices);
plot([Vertices(idx_lower,1) Vertices(idx_lower,1)+10*N(idx_lower,1)]',[Vertices(idx_lower,2) Vertices(idx_lower,2)+10*N(idx_lower,2)]');
plot([Vertices(idx_upper,1) Vertices(idx_upper,1)+10*N(idx_upper,1)]',[Vertices(idx_upper,2) Vertices(idx_upper,2)+10*N(idx_upper,2)]');
Yunliang Qi on 19 Jul 2021
Thank you Simon.