Effacer les filtres
Effacer les filtres

How can I plot in the same coordinate system this two images that the execution of the two codes below gives?

5 vues (au cours des 30 derniers jours)
function h = circle(x,y,r) % r is 30 hold on th = 0:pi/50:2*pi; xunit = r * cos(th) + x; yunit = r * sin(th) + y; h = plot(xunit, yunit); hold off
AND
R = 15 ; Delta = 3; xVertex = R * cos((0:6)*pi/3 ); yVertex = R * sin((0:6)*pi/3 ); xVertex = [xVertex , xVertex(1 )]; yVertex = [yVertex , yVertex(1 )]; requiredPoints = 20 ; plot(xVertex, yVertex, 'b+-', 'LineWidth', 3 ); grid on ; numPointsIn = 1 ; while numPointsIn < requiredPoints testx = 2 * R * rand(1) - R ; testy = 2 * R * rand(1) - R ; if inpolygon(testx, testy, xVertex, yVertex ) x(numPointsIn) = testx ; y(numPointsIn) = testy ;
D = x - R
if D <= Delta
Sc = x
end
numPointsIn = numPointsIn + 1 ;
end
end
hold on ;
plot(x,y,'r+', 'MarkerSize', 10, 'LineWidth', 2 );
yAngle = atan2(y, x) + pi
x

Réponses (1)

RobF
RobF le 23 Jan 2018
Modifié(e) : RobF le 23 Jan 2018
You might want to delete/comment out the hold off statement and try the following:
% circle(1, 2, 3)
x=1;
y=2;
r=3;
% function h = circle(x,y,r)
% r is 30
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
% hold off
R = 15 ;
Delta = 3;
xVertex = R * cos((0:6)*pi/3 );
yVertex = R * sin((0:6)*pi/3 );
xVertex = [xVertex , xVertex(1 )];
yVertex = [yVertex , yVertex(1 )];
requiredPoints = 20;
plot(xVertex, yVertex, 'b+-', 'LineWidth', 3 );
grid on;
numPointsIn = 1;
while numPointsIn < requiredPoints
testx = 2 * R * rand(1) - R ;
testy = 2 * R * rand(1) - R ;
if inpolygon(testx, testy, xVertex, yVertex )
x(numPointsIn) = testx ;
y(numPointsIn) = testy ;
D = x - R
if D <= Delta
Sc = x
end
end
numPointsIn = numPointsIn + 1 ;
end
hold on;
plot(x,y,'r+', 'MarkerSize', 10, 'LineWidth', 2 );
yAngle = atan2(y, x) + pi;
% end
  1 commentaire
RobF
RobF le 23 Jan 2018
Modifié(e) : RobF le 23 Jan 2018
function call:
x=1;
y=2;
r=3;
h=circle(x,y,r)
and remove the commenting:
function h = circle(x,y,r)
...
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by