필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Alex
Alex 2014년 2월 20일
답변: Iain 2014년 2월 20일
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.

답변 (3개)

Wayne King
Wayne King 2014년 2월 20일
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 2014년 2월 20일
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 2014년 2월 20일
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

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by