Commit 4961681e authored by conmccoid's avatar conmccoid
Browse files

Tetra: driver for intersection of simplices, inelegant

parent e5c0c047
function [Z]=ALGO_simplices_IntersectSimplices_v1_20211216(U,V)
% INTERSECTSIMPLICES calculates the intersection between two simplices of
% arbitrary dimension
% Important note: this version, and the related subfunctions, do not
% include a formal treatment of the signs of each component. A version that
% is in keeping with the principles laid out in the paper would feature an
% in-depth network of connections between signs, as well as tests for the
% same sign of components of previous intersections in the event that the
% m-face of X does not have a maximum number of intersections at a given
% step.
n=length(U); % there are n vertices of U (and V) which means the dimension
% of the space is n-1
%--Change of Coordinates--%
v0=V(:,n); A=V(:,1:n-1)-V(:,n);
X=A \ (U-v0);
X=[X; 1-ones(1,n-1)*X]; % tack on the x*e_0 'coordinates'
%--Vertices of X in Y--%
S=X>=0;
if prod(prod(S,2))==0 % if there is a given coordinate where all X values are negative
disp('Simplices do not intersect') % then there is a hyperplane that entirely divides X and Y
Z=[];
return
end
S=prod(S);
Z=U(:,S==1);
%--Intersections--%
H=cell(1); J=H; T=H;
H{1}=X; J{1}=eye(n); T{1}=zeros(n,1);
for i=1:n-1
[H,J,T]=SUB_simplices_Unfold_v1_20211214(H,J,T,X);
if isempty(H) % if no intersections are calculated for a given step then there are no more intersections to be found
return
end
S=prod(H>=0); Z=[Z,A*H(1:n,S==1)+v0];
end
%--Vertices of Y in X--%
binV=zeros(n,1); indV=binV; % another probably terrible way of doing things... see notes on v1 of Unfold and Orphan for thoughts
while ~isempty(H)
H1=H{1}; T1=T{1};
indT=1:n; indT=indT(T1==0); % at most two values in ind
for i=indT
if indV(i)==0
j=indT(indT~=i);
if sign(max(H1(j,:)))~=sign(min(H1(j,:)))
binV(i)=1;
end
indV(i)=1;
end
end
m=length(T); indT=zeros(m,1);
for i=1:m
if nnz(indV | T{i})==n
indT(i)=1;
end
end
H=H{indT==0}; T=T{indT==0};
end
Z=[Z,V(:,binV)];
\ No newline at end of file
......@@ -20,7 +20,7 @@ function [H_new,J_new,T_new] = SUB_simplices_Unfold_v1_20211214(H_all,J_all,T_al
% - is there not a faster/less involved way to remove dupliate
% combinations?
T=T_all{1}; n=length(T); d=nnz(T); m_max=nchoosek(n,d);
T=T_all{1}; n=length(T); d=nnz(T)+1; m_max=nchoosek(n,d);
H_new=cell(m_max,1); J_new=H_new; T_new=H_new; m_new=0;
while ~isempty(H_all)
H=H_all{1}; J=J_all{1}; T=T_all{1};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment