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

1 view (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 May 2010
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

More Answers (0)

Categories

Find more on Data Exploration in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!