Finding and plotting evenly-spaced points along a vector

42 views (last 30 days)
I've plotted a centerline along an ellipse in my image by using ginput to select 2 points and then drawing the line connecting them. Next, I would like to figure out the coordinates of 10 evenly spaced points along this line and plot them on top of the current image, creating a spine of 12 points (10 + the 2 original) along the ellipse. How would I implement this? The ultimate goal is to create 11 even-length vectors, one between every 2 points along the spine. My current code is below:
I = data(:,:,i);
imshow(I, []);
hold on
[x, y] = ginput(2);
plot(x, y, '*')
pause(1);
plot(x, y, 'r')
pause(1)
hold off
pause(5);
close all

Accepted Answer

Federico Becattini
Federico Becattini on 5 Nov 2015
If I understood correctly this is what you are looking for:
num_points = 10;
for i=1:num_points
points_x(i)=(x(1)*i+x(2)*(num_points-i+1))/(num_points+1);
points_y(i)=(y(1)*i+y(2)*(num_points-i+1))/(num_points+1);
end
plot(points_x, points_y, '*c')
By changing num_points you can choose the number of points to plot along the line.

More Answers (1)

dpb
dpb on 5 Nov 2015
Alternate way given the two end points [x,y]--
xy=[linspace(x(1),x(2),12).' linspace(y(1),y(2),12).'];
returns the points in two columns.

Categories

Find more on Data Exploration 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!