1 | function [box zero range eigvec]=make_box4(points)
|
---|
2 | points=min(points,20*ones(size(points,1),size(points,2)));
|
---|
3 | fi=8;
|
---|
4 | a0=0;
|
---|
5 | %OK
|
---|
6 | N=size(points,1);
|
---|
7 | dim=size(points,2);
|
---|
8 | num_of_points=round(N^(1/dim));
|
---|
9 |
|
---|
10 | meanval=mean(points,1);
|
---|
11 | eps=0.1;
|
---|
12 | [eigvec,eigval]=eig((points-ones(N,1)*meanval)'*(points-ones(N,1)*meanval));
|
---|
13 | range=max(2*sqrt(diag(eigval)/N),eps);
|
---|
14 |
|
---|
15 | %plot(points(:,1), points(:,2),'r.' ); hold on
|
---|
16 |
|
---|
17 | pom=zeros(4,2);
|
---|
18 | p=1;
|
---|
19 | %figure
|
---|
20 | while p
|
---|
21 | for i=1:4
|
---|
22 | pom(i,:)=(range.*[(-1)^i; (-1)^floor((i-1)/2)])'*eigvec'+meanval;
|
---|
23 | end
|
---|
24 | %plot(pom(:,1),pom(:,2), 'r+'); hold on
|
---|
25 | if min(pom(:))<0
|
---|
26 | [a b]= min(pom(:,2));
|
---|
27 | [a c]= max(pom(:,2));
|
---|
28 | a1=(pom(b,1)-pom(c,1))>0;
|
---|
29 | range=range/1.05;
|
---|
30 | if range>eps
|
---|
31 | if a1~=a0
|
---|
32 | fi=2*fi;
|
---|
33 | end
|
---|
34 | a0=a1;
|
---|
35 | eigvec=[cos(pi/fi) (-1)^a1*sin(pi/fi);(-1)^(a1+1)*sin(pi/fi) cos(pi/fi)]*eigvec;
|
---|
36 | end
|
---|
37 | else
|
---|
38 | p=0;
|
---|
39 | end
|
---|
40 | end
|
---|
41 |
|
---|
42 |
|
---|
43 | %for i=1:2
|
---|
44 | % pom=eigvec(:,i)*range(i)+meanval';
|
---|
45 | % plot([meanval(1) pom(1)] , [meanval(2) pom(2)]);
|
---|
46 | %end
|
---|
47 |
|
---|
48 |
|
---|
49 | box=zeros(N,dim);
|
---|
50 | pointer=-range;
|
---|
51 | step=2*range/(num_of_points-1);
|
---|
52 | jump=[1 num_of_points];
|
---|
53 | for i=1:N
|
---|
54 | for k=1:dim
|
---|
55 | box(i,k)=pointer(k)+step(k)*mod(floor((i-1)/jump(k)),num_of_points);
|
---|
56 | end
|
---|
57 | end
|
---|
58 |
|
---|
59 | box=(box)*eigvec'+ones(N,1)*meanval;
|
---|
60 | range=ones(dim,1)./(2*range);
|
---|
61 | zero=box(1,:);
|
---|
62 | end
|
---|