Borrar filtros
Borrar filtros

How to a creat a sweeping radius, like that of a radar.

3 visualizaciones (últimos 30 días)
Alex
Alex el 20 de Feb. de 2014
Respondida: Iain el 20 de Feb. de 2014
For my university assignment I have to create a projectile simulator in the form of a radar, and I am struggling to create a radius that sweeps through the circle and was wondering if anyone could help, thanks very much.

Respuestas (3)

Wayne King
Wayne King el 20 de Feb. de 2014
It's easy enough to simulate that, but are you just interested in something for visual effect? In other words, not tied to any underlying computation.
theta=0:.01:2*pi;
y=exp(1i*theta);
for j=1:length(theta)
h=compass(real(y(j)),imag(y(j)));
set(h,'linewidth',2);
set(h,'color',[0 0 0])
title('(cos(\theta),sin(\theta))','fontsize',18);
pause(.01);
end

Alex
Alex el 20 de Feb. de 2014
Thanks for the quick reply, not exactly what I was hoping for, I was thinking more of just a visual effect, that serves no real purpose other than to make it look more interesting for the code:
clear %Clear Command Workspace
clc %Clear Command Window
x_data=[15.88,18.81,21.76,24.88,27.67]; %x data values
y_data=[5.55,10.61,14.30,17.35,19.26]; %y data values
p=polyfit(x_data,y_data,2) %Plot line of best fit
for i=13:52 %For the range given
x(i)=i;
y(i)=p(1)*x(i)^2+p(2)*x(i)+p(3);
end
figure(1)
clf %Clear Figure 1
plot(x_data,y_data,'r*') %Plots points
hold on
plot(x,y) %Plots points
axis([-60,60,-60,60]) %Set axis limits
set(gca,'color','black') %Set grid area colour to black
set(gcf,'color','black') %Set grid out area colour to black
set(gca,'xcolor','w') %Set x axits colur to white
set(gca,'ycolor','w') %Set y axis colour to white
grid on %Turns Gridlines on
%Plots radar isolines
plot(0,0,'go', 'MarkerSize', 110)
plot(0,0,'go', 'MarkerSize', 220)
plot(0,0,'go', 'MarkerSize', 330)
plot(0,0,'go', 'MarkerSize', 440)
plot(0,0,'go', 'MarkerSize', 550)
plot(0,0,'go', 'MarkerSize', 660)
plot(0,0,'go', 'MarkerSize', 770)
a=p(1) %Value for a
b=p(2) %Value for b
c=p(3) %Value for c
d = sqrt(b^2 - 4*a*c); %Quadratic formula discriminant
x(1) = ( -b + d )/(2*a) %Solution 1
x(2) = ( -b - d )/(2*a) %Solution 2
Thanks again

Iain
Iain el 20 de Feb. de 2014
This is NOT the full answer, but it should get you started.
a = plot([0 xmax],[0 0],'r-');
hold on
b = plot(x,y,'bx');
c = plot(x1,y1,'cx');
for i = 0:360
set(a,'XData',[0, xmax],'YData',[0 ymax*sin(i*pi/180)])
% figure out how close the line is to passing a marker, and if its close enough
set(b,'Markersize',BIG)
% and if it's not...
set(c,'Markersize',small)
pause(0.1)
end

Categorías

Más información sobre Polar Plots 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