a=pi*rand;t=linspace(a,2*pi+a,5);
x=cos(t);y=sin(t);
X=[x;y];%首先随机产生正方形顶点坐标
X(:,5)=[];
id=randperm(4);
XX=X(:,id(1:3));%随机选取三个顶点
C=mean(XX,2);%这三个顶点的中心坐标
D=sum((repmat(C,1,3)-XX).^2);
ID=find(D==min(D));%距C最短的顶点位置
X4=XX(:,ID)+3*(C-XX(:,ID));%第4个顶点的坐标
scatter(XX(1,:),XX(2,:),'sr');hold on;scatter(C(1),C(2),'or');scatter(X4(1),X4(2),'sb');axis equal%看看效果吧