Clear Filters
Clear Filters

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

5 views (last 30 days)
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

Answers (1)

RobF
RobF on 23 Jan 2018
Edited: RobF on 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

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!