CloudRunner

... share your algorithms as a web service

Algorithm: Visualize external Approximation of Minkowski-Sum (two ellipsis)

Description:
Visualizes effect of rotation and scale on the minkowski-sum and its outer approximation.

Uses ellipsoid toolbox by Alex Kurzhanskiy for minkowski-sum.
Tags: ellipsoid visualization
Depends On: "Ellipsoidal toolbox essentials" by florian.pfaff (latest version)
Usage: Algorithm is public.
Viewed 3691 times, called 97 times
Upload:
Empty star Empty star Empty star Empty star Empty star
0 votes
Florian Pfaff
02/10/2013 8:29 p.m. (version #2)

Select Version

Version #2: 02/10/2013 8:29 p.m.
Changelog:
Now uses ellipsoidal toolbox essentials as a dependency instead of including it.

Version #1: 06/27/2012 1:38 a.m.
No changelog available

Run Algorithm

: Allow cached result?
Close

Please Wait

Computation is running...

Plots

showing plot # of

Result Value(s)


		

Resource Usage

Execution of the algorithm took seconds.
Peak memory usage for running the algorithm was kilobytes (total usage: kilobytes).

Run ID / Link

ID of this run:
Link:

Result from Cache

Result has been delivered from cache and computed on (UTC).

Matlab log

(show)

		

Error

Using this algorithm in your local MATLAB environment is easy: Click here for instructions!

Usage Instructions for CloudRunner Client

  1. Download the CloudRunner Client by clicking here and place the downloaded file in your MATLAB working directory.

  2. Inside MATLAB, initialize the CloudRunner Client by calling CloudRunner:
    >> CloudRunner

    A login dialog will prompt for your CloudRunner mail address and password. For a start, you can leave the dialog empty and just click "Connect".

    Alternatively, you can provide the login credentials (or empty strings to skip login) as a parameter and hence skip the login dialog. This is useful when using CloudRunner in non-interactive scripts.
    >> CloudRunner('mail@example.com', 'password')

  3. Select this algorithm by its URL. Selecting an algorithm creates the lambda function that proxies calls to the algorithm to the server for execution:
    >> CloudRunnerSelect('http://www.cloudrunner.eu/algorithm/51/visualize-external-approximation-of-minkowski-sum-two-ellipsis/version/2/')

    For the sake of convenience, you can also use the algorithm ID instead of its URL for public algorithms.

  4. Call functions from the algorithm like any regular local function.

Note: You can find further information on the help page.

Source Code

File:

 1 function testRotationTwoEllipsis
 2 % Visualizing the influence of rotation and scaling on the approximation of the minkowski-sum of two ellipsoids
 3 %
 4 % @author Florian Pfaff
 5 % @date 2011
 6 
 7     X1=diag([1,10]);
 8     X2=diag([1,10]);
 9 
10     opt.show_all=1;
11     figure(1),clf,shg,set(gcf,'Color',[1,1,1])
12 
13     for angle=0:(2*pi/120):pi%2*pi
14         cla,hold on,axis([-7,7,-7,7])
15         X2curr=[cos(angle),-sin(angle);sin(angle),cos(angle)]*X2*[cos(angle),-sin(angle);sin(angle),cos(angle)]';
16         
17         minksum([ellipsoid([0;0],X1),ellipsoid([0;0],X2curr)],opt);
18         plot(ellipsoid([0;0],minkExternalApprox(X1,X2curr)),'g');
19         %plot(ellipsoid([0;0],minkExternalApprox(X1,X2curr,'vol')),'c');
20         
21         set((get(gca,'Children')),'LineWidth',3)
22         axis off
23         drawnow
24     end
25     for scale=[1:-0.03:0,0:0.03:1]
26         cla,hold on,axis([-7,7,-7,7])
27         X2curr=X2.*diag([1,scale]);
28         
29         minksum([ellipsoid([0;0],X1),ellipsoid([0;0],X2curr)],opt);
30         plot(ellipsoid([0;0],minkExternalApprox(X1,X2curr)),'g');
31         %plot(ellipsoid([0;0],minkExternalApprox(X1,X2curr,'vol')),'c');
32         
33         set((get(gca,'Children')),'LineWidth',3)
34         axis off
35         drawnow
36     end
37     for scale=[1:-0.03:0,0:0.03:1]
38         cla,hold on,axis([-7,7,-7,7])
39         X2curr=X2.*diag([scale,scale]);
40         
41         minksum([ellipsoid([0;0],X1),ellipsoid([0;0],X2curr)],opt);
42         plot(ellipsoid([0;0],minkExternalApprox(X1,X2curr)),'g');
43         %plot(ellipsoid([0;0],minkExternalApprox(X1,X2curr,'vol')),'c');
44         
45         set((get(gca,'Children')),'LineWidth',3)
46         axis off
47         drawnow        
48     end
49 end
 1 function Xresult=minkExternalApprox(varargin)
 2 % Returns an external approximatization with (among those that can be
 3 % created using the formula) minizes a certain criterion (optimality is
 4 % not always guaranteed)
 5 % Syntax minkExternalApprox(Q1,Q2,...Qn,'trace',weight)
 6 %
 7 % @author Florian Pfaff
 8 % @date 2011
 9     
10     %test if weighting and criterion was passed
11     if nargin>2 && ischar(varargin{end-1})
12             criterion=varargin{end-1};
13             weighting=varargin{end};
14             varargin=varargin(1:end-2);
15     %test if only criterion was passed
16     elseif ischar(varargin{end})
17         criterion=varargin{end};
18         varargin=varargin(1:end-1);
19         weighting=eye(size(varargin{1}));
20     else
21         criterion='trace';
22         weighting=eye(size(varargin{1}));
23 %         criterion='volume';
24     end
25     %remove empty to prevent div / 0!
26     notEmpty=cellfun(@(X)max(max(X))~=0,varargin);
27     varargin=varargin(notEmpty);
28     %if only single matrix do not approx
29     if length(varargin)<=1
30         warning('ELLIPSOIDAPPROX:TOOFEW','At most one nonzero Matrix passed.')
31         Xresult=varargin{1};
32         return;
33     end
34     
35     if strncmpi(criterion,'trace',3)||strncmpi(criterion,'spur',3)
36         q_i=(ones(length(varargin))-eye(length(varargin)))*cellfun(@(X)sqrt(trace(weighting*X*weighting')),varargin)'./(cellfun(@(X)sqrt(trace(weighting*X*weighting')),varargin)');
37         Xresult=sum(reshape(cell2mat(arrayfun(@(i){(1+q_i(i))*varargin{i}},1:length(varargin))),[size(varargin{1}),length(varargin)]),3);
38     elseif strncmpi(criterion,'volume',3)
39         if length(varargin)>2
40             error('Volume formula currently supports only 2 at a time');
41         end
42         %solution using syms
43         syms lambda real
44         lambdas=solve(det(varargin{1}-lambda*varargin{2}));
45         disp(real(double(lambdas)));
46         syms p positive        
47         pmin=real(double(solve(sum(1./(lambdas+p))-2/(p*(p+1)),'Real',true)));
48         Xresult=(pmin^-1+1)*varargin{1}+(pmin+1)*varargin{2};
49         
50     else
51         error('Unknown mode');
52     end
53         
54     %guarantee symmetric matrix
55     Xresult=triu(Xresult)+triu(Xresult)'-diag(diag(Xresult));
56    
57  end
Download algorithm (2 files) as ZIP

Comments

Please login to post a comment.