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
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Exploration についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!