Find specified number of points on curve with identical chord length (not arc length)
Show older comments
Hello!
I have the user draw a line and obtain the points on that line:
% Load example image
I = imread('peppers.png');
imshow(I)
% Draw line
roi = drawassisted('Closed', false);
% Obtain positions of points
points_input = roi.Position;
% Number of target points
num_points_target = 10;
% Find these
points_output
I want to find a specified number of points (num_points_target) along the described curve, so that the chord length between the outputs points (points_output) would be identical. I am specifically looking for chord length, not arc length. I have seen this but it uses arc length ( https://uk.mathworks.com/matlabcentral/fileexchange/34874-interparc/files/interparc.m ).
I assume some interpolation - linear would likely be okay - would be in order as, depending on the drawing speed, the points_input might not be spaced very evenly.
Code would obviously be great but if someone felt like just explaining the mathematical approach to this, that would already be very helpful. At the moment, I think I would be able to cobble something dreadful with many loops together myself but it seems to me that there must be an elegant solution to this problem surely.
5 Comments
Image Analyst
on 26 Apr 2026
There may be more than one points along the drawn curve that are the same distance from the starting point. Are you planning on handling that situation? Just take the first one in the list of (x,y) pixel locations that they drew?
The ambiguity mentioned by @Image Analyst's can also lead to multiple valid solutions. Consider the path ABCD below. If the specified number of sub-chords is two, then all sequences AQD are possible solutions, where Q is any point on line segment BC.

Julia
on 26 Apr 2026
Julia
on 27 Apr 2026
I would tend towards @Image Analyst's suggestion and use the first point in the list (so the first drawn point) if there are multiple solutions.
No matter what rule you choose, the solution will be a discontinuous function of the input points, meaning that the results can vary unstably across different computers and CPUs. For example, using the "first point" rule, the first point in my original configuration above that gives you a solution is B, and the path you would choose is ABD. However, if I were to rotate BC by even the smallest epsilon>0 degrees, either clockwise or counterclockwise (see below), then now the only solution is the path through the center, AOD. Not only that, but the chord length drops discontinuously from AB to the circle radius AO.

Accepted Answer
More Answers (2)
Image Analyst
on 26 Apr 2026
Edited: Image Analyst
on 26 Apr 2026
Use pdist2 to find the distance of every point to every other point. Then run along every row, starting with the diagonal element in each row and going to the right side of the array and use min to find the other element that is closest to your desired chord length. Pseudocode (untested):
xy = [x(:), y(:)];
distances = pdist2(xy, xy);
for row = 1 : height(xy)
thisRow = distances(row, :);
thisRow(1:row) = inf; % So we don't find any points earlier in the tracing.
[min, column] = min(abs(thisRow - desiredChordLength));
% Save the column
nextPoint(row) = column;
end
Admittedly, interparc does not solve the problem you want to solve. At least, not the probem you CLAIM you want to solve. As the author, I'll admit that. The problem is, the question you have posed is not well-posed, as there are infinitely many solutions. Consider this curve:
x = [0 1 1.5 2 3];
y = [0 0 10 0 0];
plot(x,y,'o-')
grid on
The actual arc length along that curve is fairly long, at 22.025 units.
dt = sum(sqrt(diff(x).^2 + diff(y).^2))
However, if I choose a curve with unit chordal spacing, I might get this:
x1 = [0 1 2 3]; y1 = [0 0 0 0];
hold on
plot(x1,y1,'rs-')
But I could have also chosen a curve that follows that hat shape, also with unit chordal spacing. And worse, I could have done so in various ways. This is why I claim your question is ill-posed, because it would have multiple solutions, all equally valid, yet all very different.
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


