先不管运算时间,看看算法,我觉得没错!
x=[150,85,150,145,130,0];
y=[140,85,155,50,150,0];
angle=(pi/180)*[243,236,220.5,159,230,52];
for i=1:6;
for j=1:6;
delx(i,j)=x(i)-x(j);
dely(i,j)=y(i)-y(j);
end;
end;
fval=10000;
m=1;
n=2;
for a1=m:n;
for a2=m:n;
aa=(pi/180)*[a1,a2];
delx2=delx([1,2],[1,2]);
dely2=dely([1,2],[1,2]);
for k=1:2;
for l=1:2;
c2(k,l)=cos(aa(k))-cos(aa(l));
s2(k,l)=sin(aa(k))-sin(aa(l));
end;
end;
D2=((delx2.*s2-dely2.*c2).^2)./(c2.^2+s2.^2);
if min(min(D2))<64;
continue;
else
ftest=sum((aa-angle(1:2)).^2);
if ftest>fval;
continue;
else
fval=ftest;
aval=aa;
end;
end;
for a3=m:n;
ab=(pi/180)*[a1,a2,a3];
delx3=delx([1,2,3],[1,2,3]);
dely3=dely([1,2,3],[1,2,3]);
for k=1:3;
for l=1:3;
c3(k,l)=cos(ab(k))-cos(ab(l));
s3(k,l)=sin(ab(k))-sin(ab(l));
end;
end;
D2=((delx3.*s3-dely3.*c3).^2)./(c3.^2+s3.^2);
if min(min(D2))<64;
continue;
else
ftest=sum((ab-angle(3)).^2);
if ftest>fval;
continue;
else
fval=ftest;
aval=ab;
end;
end;
for a4=m:n;
ac=(pi/180)*[a1,a2,a3,a4];
delx4=delx([1,4],[1,4]);
dely4=dely([1,4],[1,4]);
for k=1:4;
for l=1:4;
c4(k,l)=cos(ac(k))-cos(ac(l));
s4(k,l)=sin(ac(k))-sin(ac(l));
end;
end;
D2=((delx4.*s4-dely4.*c4).^2)./(c4.^2+s4.^2);
if min(min(D2))<64;
continue;
else
ftest=sum((ac-angle(4)).^2);
if ftest>fval;
continue;
else
fval=ftest;
aval=ac;
end;
end;
for a5=m:n;
ad=(pi/180)*[a1,a2,a3,a4,a5];
delx5=delx([1,5],[1,5]);
dely5=dely([1,5],[1,5]);
for k=1:5;
for l=1:5;
c5(k,l)=cos(ad(k))-cos(ad(l));
s5(k,l)=sin(ad(k))-sin(ad(l));
end;
end;
D2=((delx5.*s5-dely5.*c5).^2)./(c5.^2+s.^2);
if min(min(D2))<64;
continue;
else
ftest=sum((ad-angle(5)).^2);
if ftest>fval;
continue;
else
fval=ftest;
aval=ad;
end;
end;
for a6=m:n;
a=(pi/180)*[a1,a2,a3,a4,a5,a6];
for k=1:6;
for l=1:6;
c(k,l)=cos(a(k))-cos(a(l));
s(k,l)=sin(a(k))-sin(a(l));
end;
end;
D2=((delx.*s-dely.*c).^2)./(c.^2+s.^2);
if min(min(D2))>=64;
ftest=sum((a-angle).^2);
if ftest<fval;
fval=ftest;
aval=a;
fval
aval
end;
end;
end;
end;
end;
end;
end;
end;
|