필터 지우기
필터 지우기

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 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