how to find the distance from a point to a line

조회 수: 24 (최근 30일)
Rhazen Mae Tuastomban
Rhazen Mae Tuastomban 2020년 7월 27일
댓글: Image Analyst 2022년 5월 25일
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