% Input:
% L: Matrix (containing row-wise direction vectors)
% angle: double
% S: function handle (Support function to intersect)
% n: vector
% gamma: scalar
% algo: cell array of strings (dichotomicSearch or optimizedDichotomicSearch)
% ~: cell array

% output: 
% S: function handle (support function of the intersection of S with n*x <=
% gamma)
% result: Matrix (containing the evaluation of the intersecting support
% function in directions L)

% Description:
% Computes the intersection of a Support function with a guard nx = gamma
% using dichotomic search

function [S,results] = dimensionreduction(L,angle,S,n,gamma,algo,~)
results = zeros(size(L,1),1);

L2 = vectorgeneratorEXT(2,angle);    %2dimensional version of L
    
    for i=1:1:size(L,1)
        [Spi,PI] = calcPi(n,L(i,:)',S);
        resultspi = sptotemplatepolyhedra(Spi,L2);

        results(i,1) = feval(algo,Spi,resultspi,L2,gamma,0.0005,50,PI,S);
    end;


function [f_pi,PI] = calcPi(n,l,S)
PI = [n';l'];
f_pi = @(x) S(PI' * x);
