How do I draw two lines on an image using the mouse and get the angle between the lines?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuesta aceptada
MathWorks Support Team
el 14 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Exploration en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!