Effacer les filtres
Effacer les filtres

Finding and plotting evenly-spaced points along a vector

20 vues (au cours des 30 derniers jours)
Diondra
Diondra le 5 Nov 2015
Réponse apportée : dpb le 5 Nov 2015
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

Réponse acceptée

Federico Becattini
Federico Becattini le 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.

Plus de réponses (1)

dpb
dpb le 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.

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by