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에서 Tracking and Sensor Fusion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!