how to find the distance from a point to a line
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am ask to find the distance from a point to a line
with this given
(0,0,12); x=4t, y=-2t, z=2t
but I don't know to to encode it to MATLAB
6 Kommentare
Image Analyst
am 26 Apr. 2022
I use a Firefox plug-in/add-on called WebArchives that searched Google plus several other archives. It's a icon on the Firefox toolbar (once installed).
Rik
am 26 Apr. 2022
I wonder why a normal search turns up a cached page, but this plug-in doesn't. Otherwise this would make it a lot easier.
(for the record: it is also available for Chromium-based browsers)
Antworten (1)
Image Analyst
am 27 Jul. 2020
See attached demo
% Get the distance from a point (x3, y3) to
% a line defined by two points (x1, y1) and (x2, y2);
% Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
function distance = GetPointLineDistance(x3,y3,x1,y1,x2,y2)
try
% Find the numerator for our point-to-line distance formula.
numerator = abs((x2 - x1) * (y1 - y3) - (x1 - x3) * (y2 - y1));
% Find the denominator for our point-to-line distance formula.
denominator = sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2);
% Compute the distance.
distance = numerator ./ denominator;
catch ME
callStackString = GetCallStack(ME);
errorMessage = sprintf('Error in program %s.\nTraceback (most recent at top):\n%s\nError Message:\n%s',...
mfilename, callStackString, ME.message);
uiwait(warndlg(errorMessage))
end
return; % from GetPointLineDistance()
end
4 Kommentare
Rik
am 25 Mai 2022
@Maite Osaba, latitude and longitude can be very non-linear. If you want accuracy, I would suggest not taking shortcuts.
Image Analyst
am 25 Mai 2022
@Maite Osaba it is probably good for short distances where the earth is fairly flat. Of course it's the straight line distance and if the points are very widely spaced, you're getting the straight line distances, which would mean boring through the earth, if the earth is significantly curved over that distance. If you want to do this in general, then I'm sure there are probably functions in the Mapping Toolbox to help you though I'm not sure what they are since I don't have that toolbox. (Expand comments to see @Rik's comments just before mine.)
Siehe auch
Kategorien
Mehr zu Mapping Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!