![1Untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232498/1Untitled.png)
convert line to pixel coordinate
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mohammed alany
le 3 Août 2019
Modifié(e) : Image Analyst
le 4 Août 2019
Hi,
if i have a path consist of six points , and i have obstacle, what i want is to put nodes in all the path to count the minimum distance between
the obstacle and the path
![example.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232490/example.jpeg)
4 commentaires
Réponse acceptée
Image Analyst
le 4 Août 2019
What if you just take the average of the initial, known points?
x = sort(rand(9, 1));
y = sort(rand(9, 1));
plot(x, y, '.-', 'Color', [247, 148, 20]/255, 'MarkerSize', 40);
grid on;
xlabel('X');
ylabel('Y');
xAve = (x(1:end-1) + x(2:end))/2;
yAve = (y(1:end-1) + y(2:end))/2;
hold on;
plot(xAve, yAve, '.', 'Color', [206, 24, 18]/255, 'MarkerSize', 40);
legend('Original Points', 'Mid Points', 'Location', 'north');
![0001 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232568/0001%20Screenshot.png)
3 commentaires
Image Analyst
le 4 Août 2019
Modifié(e) : Image Analyst
le 4 Août 2019
You could use linspace() instead of just averaging. Try this:
x = sort(rand(9, 1));
y = sort(rand(9, 1));
% Now we have sample data and can begin.
numPoints = 2; % # points in between, not including the knot endpoints.
xAve = x(1);
yAve = y(1);
for k = 2 : length(y)
inBetweenPoints = linspace(x(k-1), x(k), numPoints + 2); % 2 more to include the knots.
xAve = [xAve, inBetweenPoints(2:end)];
inBetweenPoints = linspace(y(k-1), y(k), numPoints + 2);
yAve = [yAve, inBetweenPoints(2:end)];
end
plot(xAve, yAve, '.', 'Color', [206, 24, 18]/255, 'MarkerSize', 40);
hold on;
plot(x, y, '.-', 'Color', [247, 148, 20]/255, 'MarkerSize', 40);
grid on;
xlabel('X');
ylabel('Y');
legend('Mid Points', 'Original Points', 'Location', 'north');
![0001 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/232590/0001%20Screenshot.png)
You could also use interparc (File Exchange), or use splines (demo attached).
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!