Finding and plotting evenly-spaced points along a vector

17 次查看(过去 30 天)
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

采纳的回答

Federico Becattini
Federico Becattini 2015-11-5
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.

更多回答(1 个)

dpb
dpb 2015-11-5
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.

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by