function A = genpoints(A,type,varargin) switch type case 'unif', A = unifrnd(-1,1,length(A),3); for i = 1:length(A), while (A(i,1)^2 + A(i,2)^2 + A(i,3)^2) > 1, A(i,:) = unifrnd(-1,1,1,3); end lA = sqrt(A(i,1)^2 + A(i,2)^2 + A(i,3)^2); A(i,:) = A(i,:)/lA; end case 'unifspaced', A = unifrnd(-1,1,length(A),3); i = 1; while i <= length(A), while (A(i,1)^2 + A(i,2)^2 + A(i,3)^2) > 1, A(i,:) = unifrnd(-1,1,1,3); end lA = sqrt(A(i,1)^2 + A(i,2)^2 + A(i,3)^2); A(i,:) = A(i,:)/lA; t = 1; for j = 1:i-1, if dot(A(j,:),A(i,:)) > 0.9 t = 0; end end if (t == 1) i = i + 1; else A(i,:) = unifrnd(-1,1,1,3); end end case 'clusters', T = delaunay3([A(:,1)' 0], [A(:,2)' 0], [A(:,3)' 0]); U = ''; for j = 1:length(T), s = T(j,:); s = s(find((s ~= length(A)+1) .* s)); U = [U; 1-dot(A(s(1),:),A(s(2),:)) s(1) s(2); 1-dot(A(s(1),:),A(s(3),:)) s(1) s(3); 1-dot(A(s(2),:),A(s(3),:)) s(2) s(3)]; end U = sortrows(U,1); B = zeros(length(A)); for j = 1:length(U), if B(U(j,2)) == 0 B(U(j,2)) = 1 - U(j,1); end if B(U(j,3)) == 0 B(U(j,3)) = 1 - U(j,1); end end Ct = ''; for i = 1:length(A), r = acos(B(i))*betarnd(10,2)/2; t = round(r*13.25*(betarnd(3,3)+0.5)); if (t > 2) clear C; for j = 1:t, C(j,:) = [ sin(r)*cos((j-1)*2*pi/t) sin(r)*sin((j-1)*2*pi/t) cos(r)]; end theta = 2*pi*rand; trans = [cos(theta) sin(theta) 0 ; -sin(theta) cos(theta) 0 ; 0 0 1]; C = C*trans; phi = acos(A(i,3)); trans = [cos(phi) 0 -sin(phi) ; 0 1 0 ; sin(phi) 0 cos(phi)]; C = C*trans; theta = atan2(A(i,2),A(i,1)); trans = [cos(theta) sin(theta) 0 ; -sin(theta) cos(theta) 0 ; 0 0 1]; C = C*trans; Ct = [Ct ; C]; else Ct = [Ct ; A(i,:)]; end end A = Ct; case 'minmax', for i = 1:100, T = delaunay3([A(:,1)' 0], [A(:,2)' 0], [A(:,3)' 0]); U = ''; for j = 1:length(T), s = T(j,:); s = sort(s(find((s ~= length(A)+1) .* s))); U = [U; s(1:2) ; s(2:3) ; s(1) s(3)]; end C1 = [1 0 0]; C2 = [-1 0 0]; for j = 1:2:length(U), r = dot(A(U(j,1),:),A(U(j,2),:)); if (r < C1(1)) C1 = [r U(j,:)]; end if (r > C2(1)) C2 = [r U(j,:)]; end end % for loop that increments j D = A(C1(2),:) - A(C1(3),:); D = D/sqrt(dot(D,D)); A(C1(2),:) = A(C1(2),:)-0.01*D; A(C1(2),:) = A(C1(2),:)/sqrt(dot(A(C1(2),:),A(C1(2),:))); A(C1(3),:) = A(C1(3),:)+0.01*D; A(C1(3),:) = A(C1(3),:)/sqrt(dot(A(C1(3),:),A(C1(3),:))); D = A(C2(2),:) - A(C2(3),:); D = D/sqrt(dot(D,D)); A(C2(2),:) = A(C2(2),:)+0.01*D; A(C2(2),:) = A(C2(2),:)/sqrt(dot(A(C2(2),:),A(C2(2),:))); A(C2(3),:) = A(C2(3),:)-0.01*D; A(C2(3),:) = A(C2(3),:)/sqrt(dot(A(C2(3),:),A(C2(3),:))); end % for loop that increments i case 'spiral' a = 1/16; t = linspace(0.1*pi/a,0.9*pi/a,length(A)); A = [cos(t).*sin(a*t); sin(t).*sin(a*t); cos(a*t)]'; case 'spiralspaced' a = 1/16; for i = 1:100000, T = delaunay3([A(:,1)' 0], [A(:,2)' 0], [A(:,3)' 0]); U = ''; for j = 1:length(T), s = T(j,:); s = sort(s(find((s ~= length(A)+1) .* s))); U = [U; s(1:2) ; s(2:3) ; s(1) s(3)]; end % for loop that increments j C1 = [1 0 0]; C2 = [-1 0 0]; for j = 1:2:length(U), r = dot(A(U(j,1),:),A(U(j,2),:)); if (r < C1(1)) C1 = [r U(j,:)]; end if (r > C2(1)) C2 = [r U(j,:)]; end end % for loop that increments j D = A(C1(2),:) - A(C1(3),:); D = D/sqrt(dot(D,D)); A(C1(2),:) = A(C1(2),:)-0.01*D; t = atan2(A(C1(2),2),A(C1(2),1)); if t < 0 t = t + 2*pi; end t2 = acos(A(C1(2),3))/a; for s = 0:1/a-1, if abs(s*2*pi+t - t2) < pi break; end end A(C1(2),:) = [cos(t).*sin(a*(t+2*pi*s)) sin(t).*sin(a*(t+2*pi*s)) cos(a*(t+2*pi*s))]; A(C1(3),:) = A(C1(3),:)+0.01*D; t = atan2(A(C1(3),2),A(C1(3),1)); if t < 0 t = t + 2*pi; end t2 = acos(A(C1(3),3))/a; for s = 0:1/a-1, if abs(s*2*pi+t - t2) < pi break; end end A(C1(3),:) = [cos(t).*sin(a*(t+2*pi*s)) sin(t).*sin(a*(t+2*pi*s)) cos(a*(t+2*pi*s))]; D = A(C2(2),:) - A(C2(3),:); D = D/sqrt(dot(D,D)); A(C2(2),:) = A(C2(2),:)+0.01*D; t = atan2(A(C2(2),2),A(C2(2),1)); if t < 0 t = t + 2*pi; end t2 = acos(A(C2(2),3))/a; for s = 0:1/a-1, if abs(s*2*pi+t - t2) < pi break; end end A(C2(2),:) = [cos(t).*sin(a*(t+2*pi*s)) sin(t).*sin(a*(t+2*pi*s)) cos(a*(t+2*pi*s))]; A(C2(3),:) = A(C2(3),:)-0.01*D; t = atan2(A(C2(3),2),A(C2(3),1)); if t < 0 t = t + 2*pi; end t2 = acos(A(C2(3),3))/a; for s = 0:1/a-1, if abs(s*2*pi+t - t2) < pi break; end end A(C2(3),:) = [cos(t).*sin(a*(t+2*pi*s)) sin(t).*sin(a*(t+2*pi*s)) cos(a*(t+2*pi*s))]; end % for loop that increments i % end of spiral case otherwise, disp unknown end