How to plot an arrow with a point, length and direction?

Hi.
I want to plot an arrow with a starting point (x,y), length and direction(degree), but there shouldn't be cosinus and sinus commands in code. So, at the end of the process, the length should be the same. When I use cos and sin commands to define endpoint (xend,yend), the length is changing.
How can I do that? (I tried arrow and quiver commands but I'm failed)
Thanks for your answers.

2 commentaires

annotate() ?
If the length is changing, is it possible that you have not done
axis equal
?
I moved what poster said in an "Answer" to a comment here since it's not an "Answer" to his original question:
Walter Roberson, thanks for your answer. But I can't understand what did you mean.
In my opinion, the problem is not about the axis. Because I can't find a command that I can direction, length and point, all them together except for arrow command.
If you know anything about this that I can, could you give me a sample code?
Thanks again.

Connectez-vous pour commenter.

Réponses (3)

MATLAB does not have an arrow() command. Arrows are created using
annotation('arrow', x, y)
You cannot set direction by angle; you need to give x and y coordinates. You can use pol2cart() to do the transformation:
[delta_x, delta_y] = pol2cart(length, direction_angle);
annotation('arrow', [base_x, base_x + delta_x], [base_y, base_y + delta_y] )

2 commentaires

Majid
Majid le 12 Nov 2021
Modifié(e) : Majid le 12 Nov 2021
I guess this does not work because the input of annotation() should be between 0 and 1. Am I right?
DGM
DGM le 12 Nov 2021
Modifié(e) : DGM le 12 Nov 2021
The mistake in this answer is that the order of the arguments to pol2cart() are swapped.
[x y z] = peaks(100);
pcolor(x,y,z);
shading flat
base_x = 0;
base_y = 0;
len = 0.707;
th = pi/4;
[delta_x, delta_y] = pol2cart(th,len);
annotation('arrow', [base_x, base_x + delta_x], [base_y, base_y + delta_y] )
This might also demonstrate what may be another misconception. The annotation is being placed in normalized figure coordinates, not data coordinates. Since you haven't described the problem you're having, that might be part of it.

Connectez-vous pour commenter.

Tord Vincent Heggland
Tord Vincent Heggland le 4 Mar 2020

0 votes

[delta_x, delta_y] = pol2cart(length, direction_angle);
annotation('arrow', [base_x, base_x + delta_x], [base_y, base_y + delta_y] )

1 commentaire

I guess this does not work because the input of annotation() should be between 0 and 1. Am I right?

Connectez-vous pour commenter.

Robert Sacker
Robert Sacker le 17 Oct 2020

0 votes

Don't you have "direction" and "length" interchanged?

Tags

Modifié(e) :

DGM
le 12 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by