フィルターのクリア

Finding and plotting evenly-spaced points along a vector

20 ビュー (過去 30 日間)
Diondra
Diondra 2015 年 11 月 5 日
回答済み: dpb 2015 年 11 月 5 日
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 Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by