Colouring/shading of a sector of a polar representation in combination with animatedline

3 vues (au cours des 30 derniers jours)
How do I combine the animation of an animatedline with a 30° sector? I would like the animated point of the animatedline to always be highlighted with a 30° sector (+-15°). The animated line should become longer and longer, while the sector runs along with the first point and disappears as soon as the 360° is reached. I have the following code for the animated line and for the 30° sector, but I have no idea how to combine them as described.
%polarplot
ax = polaraxes('ThetaZeroLocation', 'top');
polarplot(ax, 0, 1);
hold on;
random_vector = 10 + (20 - 10) * rand(1, 360);
theta_rad = deg2rad(1:360);
rlim([0, max(random_vector)]);
h = animatedline(ax, 'Color', 'b', 'LineWidth', 2);
for i = 1:length(random_vector)
addpoints(h, theta_rad(i), random_vector(i));
drawnow;
pause(0.01);
end
hold off;
%highlighted sektor
teta= linspace(0,pi/6,500);
rho = [0 100*ones(499,1)'];
a = polar(teta,rho);
patch( get(a,'XData'), get(a,'YData'),[0, 0.4470, 0.7410],'FaceAlpha',0.2);

Réponse acceptée

Ganesh
Ganesh le 12 Juin 2024
Hi @Kalle,
Starting R2024a, you can achieve this using "polarregion()". You can use "theta_rad(i)" to find the range of theta and plot accordingly. You can use the code below:
%polarplot
ax = polaraxes('ThetaZeroLocation', 'top');
hold on;
random_vector = 10 + (20 - 10) * rand(1, 360);
theta_rad = deg2rad(1:360);
rlim([0, max(random_vector)]);
h = animatedline(ax, 'Color', 'b', 'LineWidth', 2);
% Initial sector plot (invisible at start)
sectorAngle = 15;
sectorPlot = polarplot(ax, [0, 0], [0, 0], 'r', 'LineWidth', 2);
teta1 = 0;
rho1 = 1;
teta2 = pi/6;
rho2 = 1;
prev = polarregion([0 pi/6], [0 max(random_vector)]);
for i = 1:length(random_vector)
addpoints(h, theta_rad(i), random_vector(i));
drawnow;
pause(0.01);
sectorStart = theta_rad(i) - deg2rad(sectorAngle);
sectorEnd = theta_rad(i) + deg2rad(sectorAngle);
prev.FaceAlpha = 0;
prev = polarregion([sectorStart sectorEnd], [0 max(random_vector)]);
end
prev.FaceAlpha = 0;
hold off;
Please find the relevant documentation on "polarregion" below:

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by