Normal distance from one curve to another at specific points
16 views (last 30 days)
If I have two curves with datapoints, how can I get the distance from any point in one curve to the another one?
I am trying to do it with the following steps:
Find normals to the reference curve (red one) at each point and then find the points where the normals intersect the target curve (blue here). But I cannot put it in code. Also, I want to use the normals for the next step. So, is there a way to get equations of the normals at each points?
Image Analyst on 8 Jul 2022
If you have 4 vectors - curve1x, curve1y, curve2x, curve2y - and a point at some point, index1, in curve1, then you can find the closest point in curve 2 to that point.
distances = sqrt((curve2x - curve1x(index1)) .^ 2 + (curve2y - curve1y(index1)) .^ 2);
[minDistance, index2] = min(distances);
% Now you can fit a line through the two points.
xNormal = [curve1x(index1), curve2x(index2)];
yNormal = [curve1y(index1), curve2y(index2)];
line(xNormal, yNormal, 'Color', 'r', 'LineWidth', 2);
coefficients = polyfit(xNormal, yNormal, 1); % Get equation of a line
So does that do what you want?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Sam Chak on 8 Jul 2022