I want to create curves based on moving points P6 and P7. Here is what I have so far. Can someone please tell me how I can create a curve that could be used to calculate the area between two points?
hold on
axis ([-20 20 -20 20])
axis off
P1=[-11,0];
P2=[-1,0];
h{1}=plot([P1(1) P2(1)],[P1(2) P2(2)],'LineWidth',5,'Color','black');
x=5*pi/8;
b=0:pi/40:x;
P6vct=nan(numel(b),2)
P7vct=nan(numel(b),2);
for k=1:numel(b)
Z=[4,0];
h{2}=viscircles(Z,5,'LineWidth',2,'LineStyle','--','Color','black');
A=[0,0];
h{3} = viscircles(A,1,'LineWidth',2,'Color','black');
PA=A+[cos(b(k)-(pi)),sin(b(k)-(pi))];
h{4}=viscircles(PA,.1,'Color','black');
B = [4-4*cos(2*asin(.25)),-4*sin(2*asin(.25))];
h{5} = viscircles(B,1,'LineWidth',2,'Color','green');
PB=B+[cos(-b(k)-(pi/2)),sin(-b(k)-(pi/2))];
h{6}=viscircles(PB,.1,'Color','green');
C = [4-4*cos(4*asin(.25)),-4*sin(4*asin(.25))];
h{7} = viscircles(C,1,'LineWidth',2,'Color','blue');
PC=C+[cos(b(k)-(pi/2)),sin(b(k)-(pi/2))];
h{8}=viscircles(PC,.1,'Color','blue');
D = [4-4*cos(6*asin(.25)),-4*sin(6*asin(.25))];
h{9} = viscircles(D,1,'LineWidth',2,'Color','red');
PD=D+[cos(-b(k)-(pi/2)),sin(-b(k)-(pi/2))];
h{10}=viscircles(PD,.1,'Color','red');
E = [4-4*cos(8*asin(.25)),-4*sin(8*asin(.25))];
h{11} = viscircles(E,1,'LineWidth',2,'Color','yellow');
PE=E+[cos(b(k)-(pi/2)),sin(b(k)-(pi/2))];
h{12}=viscircles(PE,.1,'Color','yellow');
P3=B+[cos(b(k)),sin(b(k))];
P4=C+[cos(b(k)),sin(b(k))];
P5=D+[cos(b(k)),sin(b(k))];
P6=E+[cos(b(k)-x),sin(b(k)-x)];
P7=E+[11*cos(b(k)-x),11*sin(b(k)-x)];
P6vct(k,:)=P6;
P7vct(k,:)=P7;
h{13} = plot([P6(1) P7(1)],[P6(2) P7(2)],'LineWidth',5,'Color','black');
%h{14}=plot(P6vct(:,1),P6vct(:,2),'LineWidth',3,'Color','black');
curve1=[P6vct(:,1),P6vct(:,2)];
curve2=[P7vct(:,1),P7vct(:,2)];
%h{15}=plot(curve2,'LineWidth',3,'Color','black');
drawnow();
pause(0.001);
if k<numel(b)
delete(vertcat(h{2:13}));
end
area(curve1)
fill(curve1,curve2,'blue');
str = {'Area Swept:'};
annotation('textbox',[0.2 0.5 0.3 0.3],'String',str,'FitBoxToText','on');
end
hold off
axis ([-20 20 -20 20])
axis off

댓글 수: 2

KSSV
KSSV 2019년 3월 5일
This is not the full ocde...give the full code with all variables defined.
Allison Bushman
Allison Bushman 2019년 3월 5일
I've fixed it so my whole code is provided.

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2019년 3월 5일

0 개 추천

hold on
axis ([-20 20 -20 20])
axis off
P1=[-11,0];
P2=[-1,0];
h{1}=plot([P1(1) P2(1)],[P1(2) P2(2)],'LineWidth',5,'Color','black');
x=5*pi/8;
b=0:pi/40:x;
P6vct=nan(numel(b),2)
P7vct=nan(numel(b),2);
cP6 = zeros([],2) ;
cP7 = zeros([],2) ;
for k=1:numel(b)
Z=[4,0];
h{2}=viscircles(Z,5,'LineWidth',2,'LineStyle','--','Color','black');
A=[0,0];
h{3} = viscircles(A,1,'LineWidth',2,'Color','black');
PA=A+[cos(b(k)-(pi)),sin(b(k)-(pi))];
h{4}=viscircles(PA,.1,'Color','black');
B = [4-4*cos(2*asin(.25)),-4*sin(2*asin(.25))];
h{5} = viscircles(B,1,'LineWidth',2,'Color','green');
PB=B+[cos(-b(k)-(pi/2)),sin(-b(k)-(pi/2))];
h{6}=viscircles(PB,.1,'Color','green');
C = [4-4*cos(4*asin(.25)),-4*sin(4*asin(.25))];
h{7} = viscircles(C,1,'LineWidth',2,'Color','blue');
PC=C+[cos(b(k)-(pi/2)),sin(b(k)-(pi/2))];
h{8}=viscircles(PC,.1,'Color','blue');
D = [4-4*cos(6*asin(.25)),-4*sin(6*asin(.25))];
h{9} = viscircles(D,1,'LineWidth',2,'Color','red');
PD=D+[cos(-b(k)-(pi/2)),sin(-b(k)-(pi/2))];
h{10}=viscircles(PD,.1,'Color','red');
E = [4-4*cos(8*asin(.25)),-4*sin(8*asin(.25))];
h{11} = viscircles(E,1,'LineWidth',2,'Color','yellow');
PE=E+[cos(b(k)-(pi/2)),sin(b(k)-(pi/2))];
h{12}=viscircles(PE,.1,'Color','yellow');
P3=B+[cos(b(k)),sin(b(k))];
P4=C+[cos(b(k)),sin(b(k))];
P5=D+[cos(b(k)),sin(b(k))];
P6=E+[cos(b(k)-x),sin(b(k)-x)];
P7=E+[11*cos(b(k)-x),11*sin(b(k)-x)];
P6vct(k,:)=P6;
P7vct(k,:)=P7;
cP6(k,:) = P6 ;
cP7(k,:) = P7 ;
h{13} = plot([P6(1) P7(1)],[P6(2) P7(2)],'LineWidth',5,'Color','black');
%h{14}=plot(P6vct(:,1),P6vct(:,2),'LineWidth',3,'Color','black');
curve1=[P6vct(:,1),P6vct(:,2)];
curve2=[P7vct(:,1),P7vct(:,2)];
%h{15}=plot(curve2,'LineWidth',3,'Color','black');
drawnow();
pause(0.001);
if k<numel(b)
delete(vertcat(h{2:13}));
end
area(curve1)
fill(curve1,curve2,'blue');
str = {'Area Swept:'};
annotation('textbox',[0.2 0.5 0.3 0.3],'String',str,'FitBoxToText','on');
end
plot(cP6(:,1),cP6(:,2),'r')
plot(cP7(:,1),cP7(:,2),'b')
hold off
axis ([-20 20 -20 20])
axis off

댓글 수: 5

Allison Bushman
Allison Bushman 2019년 3월 5일
How would I fill the area between cP6 and cP7?
Read about patch
patch(cP7(:,1),cP7(:,2),'r')
Allison Bushman
Allison Bushman 2019년 3월 5일
This is somewhat working, but it is making two separate semicircles and not filling the area between the two curves.
KSSV
KSSV 2019년 3월 5일
Combine bot the curve sinto one an duse patch.
I am not sure how to do this. This is the code that I have now.
patch([cP7(:,1) cP7(:,2)],[cP6(:,1) cP6(:,2)],'r','FaceAlpha',.3);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2019년 3월 5일

댓글:

2019년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by