How do I draw two lines on an image using the mouse and get the angle between the lines?

조회 수: 1 (최근 30일)
I have an image in a figure window and I would like to use the mouse to draw two lines on the image.
For example, say I have a satellite image of an airplane on landing approach to a runway. I want to draw one line through the center of the airplane along the direction of flight and a second line down the center of the runway. I want MATLAB to determine the angle between these lines.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2010년 5월 14일
This script file demonstrates how this can be done.
% function theta = measureAngle
% Get four mouse clicks from the user in the current figure
[x,y] = ginput(4);
% Draw the two lines that the four points represent
line(x(1:2), y(1:2));
line(x(3:4), y(3:4));
% Define the two vectors
v1 = [x(2) - x(1), y(2) - y(1)];
v2 = [x(4) - x(3), y(4) - y(3)];
% Compute the angle from v1 to v2
theta = acosd(dot(v1, v2) / (norm(v1) * norm(v2)) )
% end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by