Borrar filtros
Borrar filtros

Adding an arrow to a polar plot

37 visualizaciones (últimos 30 días)
Jelena Starovic
Jelena Starovic el 18 de Dic. de 2015
Editada: Walter Roberson el 9 de Jun. de 2018
Is there any way to add an arrow to a polar plot? I want to show the orientation of a polar curve.
This is the curve that I am plotting:
t = 0:pi/100:2*pi;
r = abs((2+cos(t)).*(exp(2*1i*t)));
the = angle((2+cos(t)).*exp(2*1i*t));
polar(the,r)

Respuesta aceptada

Rebecca Krosnick
Rebecca Krosnick el 22 de Dic. de 2015
There is not a single function or property in MATLAB that will allow you to add arrows to a polar plot to indicate orientation, but the following code will accomplish this. It uses the "quiver" function to display velocity vectors of the curve:
t = 0:pi/100:2*pi;
r = abs((2+cos(t)).*(exp(2*1i*t)));
the = angle((2+cos(t)).*exp(2*1i*t));
polar(the,r)
[X,Y] = pol2cart(the,r); % get Cartesian coordinates
factor = 5; % sampling ratio; factor=5 means the arrow will be drawn for every 5th point on the curve
i = 1; % index into quiver array
j = factor * factor; % index into X,Y Cartesian coordinates
u = []; % array for x component of quiver vector
v = []; % array for y component of quiver vector
xt = []; % array for x position of quiver vector
yt = []; % array for y position of quiver vector
while (j+1) <= length(X)
xt(i) = X(j);
yt(i) = Y(j);
u(i) = X(j+1) - X(j);
v(i) = Y(j+1) - Y(j);
i = i + 1;
j = i*factor;
end
hold on;
quiver(xt, yt, u, v);
A couple aspects of this code you may want to modify:

Más respuestas (0)

Categorías

Más información sobre Vector Fields en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by