how to find the distance from a point to a line

23 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2022-4-26
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
Rik 2022-4-26
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)

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2020-7-27
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 个评论
Rik
Rik 2022-5-25
@Maite Osaba, latitude and longitude can be very non-linear. If you want accuracy, I would suggest not taking shortcuts.
Image Analyst
Image Analyst 2022-5-25
@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.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mapping Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by