How can I plot in the same coordinate system this two images that the execution of the two codes below gives?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
RobF
2018-1-23
编辑:RobF
2018-1-23
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!