MATLAB Answers

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

4 views (last 30 days)
Yunliang Qi
Yunliang Qi on 17 Jul 2021
Commented: Yunliang Qi on 19 Jul 2021
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.
load data
hold on
axis equal
[x0,y0,~,~] = intersections(xline,yline,xdata,ydata);

Accepted Answer

Simon Chan
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([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)]');

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!