How do I draw two lines on an image using the mouse and get the angle between the lines?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
Risposta accettata
MathWorks Support Team
il 14 Mag 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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Exploration in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!