nearest tangent point from Ginput point to line ?

1 vue (au cours des 30 derniers jours)
Ramesh Bala
Ramesh Bala le 22 Oct 2018
Commenté : Image Analyst le 30 Oct 2018
I'm trying to get the nearest by creating a ginput and then ginput point finds the nearest point to the line.
x = [0,20]
y= [20,50]
plot(x,y)
[x,y] = ginput(1);
h1 = text(x,y,'o', ...
'HorizontalAlignment','center', ...
'Color', [1 0 0], ...
'FontSize',8);

Réponse acceptée

Rik
Rik le 22 Oct 2018
My FEX submission should help here. Unlike what the documented behavior should be, pt is actually not extended to 3D automatically, so you'll have to do that yourself until I update the file. The code below should work as intended.
x = [0,20];
y= [20,50];
v1=[x(1) y(1) 0];
v2=[x(2) y(2) 0];
plot(x,y)
[x,y] = ginput(1);
pt=[x(:),y(:),zeros(numel(y),1)];
h1 = text(x,y,'o', ...
'HorizontalAlignment','center', ...
'Color', [1 0 0], ...
'FontSize',8);
distance=point_to_line_distance(pt, v1, v2)
  11 commentaires
Rik
Rik le 30 Oct 2018
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.
Image Analyst
Image Analyst le 30 Oct 2018
Perhaps have your code draw a line from the point perpendicularly to the closest point on the line, then run your code, and save a screenshot of the figure and upload it. Maybe if he sees that he will accept it.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 22 Oct 2018
Use sqrt():
uiwait(helpdlg('Click one point.'));
[xUser, yUser] = ginput(1);
distances = sqrt((xUser - xLine).^2 + (yUser - yLine) .^ 2);
[minDistance, indexOfMin] = min(distances);
hold on;
% Put a marker on the line.
plot(xLine(indexOfMin), yLine(indexOfMin), 'r*');
% Draw a line from the user-clicked point to the point on the line.
line([xUser, xLine(indexOfMin)], [yUser, yLine(indexOfMin)], 'LineWIdth', 2, 'Color', 'r');
  3 commentaires
Ramesh Bala
Ramesh Bala le 23 Oct 2018
It's like the point getting projected to the line @ shortest travel distance.
Image Analyst
Image Analyst le 23 Oct 2018
OK, I thought you had a bunch of points along a line, not just two. In that case you'll have to use the point-to-line distance formula, which are readily avalable all over the web.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Specifying Target for Graphics Output 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!

Translated by