Hello everyone!
how can i get a random point on the min and max circles on these:
format short
A = load('C:\Users\Stefan\Desktop\MatiValjasMatLAb/vruut.txt')
nurgad=A(:,1)
kaugused=A(:,2)
%polarplot(nurgad,kaugused,'o')
%Joonise järgi võiks lähendada ringjoonega
%Arvandmete järgi võiks ka eeldada, et saab lähendada ringjoonega
%sest raadiused ei kõigu palju.
%joonised
x = kaugused.*cos(nurgad); y = kaugused.*sin(nurgad);
plot(x,y,'.')
axis equal
hold on
c = [x y ones(length(x),1)]\-(x.^2+y.^2); %vähim ruutude meetod
xhat = -c(1)/2;
yhat = -c(2)/2;
raadius = sqrt(xhat^2+yhat^2-c(3));
plot(raadius*cos(nurgad)+xhat,raadius*sin(nurgad)+yhat,...
'g','linewidth',1) %parim ring(best fit circle)
hold on
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
raadius
kesk=[xhat, yhat]
plot(xhat,yhat,'O')
hold on
B=max(kaugused);
C=min(kaugused);
theta=0:0.01:2*pi;
xmax=B*cos(theta)+xhat;
ymax=B*sin(theta)+yhat;
plot(xmax,ymax)
hold on
hold on
xmin=C*cos(theta)+xhat;
ymin=C*sin(theta)+yhat;
plot(xmin,ymin)
hold on
hold off
The plot looks like this :

 采纳的回答

These lines define your circle for each point theta
xmax=B*cos(theta)+xhat;
ymax=B*sin(theta)+yhat;
All you need to do is define theta as random values between 0 and 2pi to plot random points on the circle.
B = 5;
xhat = 3;
yhat = -2;
theta = linspace(-pi,pi,500);
xmax=B*cos(theta)+xhat;
ymax=B*sin(theta)+yhat;
plot(xmax,ymax)
axis equal
n = 20; % number of random points
rng('default')
thetaRand = rand(1,n) * 2*pi;
xp=B*cos(thetaRand)+xhat;
yp=B*sin(thetaRand)+yhat;
hold on
plot(xp,yp,'o')

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Polar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by