
## Installing toolboxes and setting up the path.

You need to download the following files: signal toolbox, general toolbox and graph toolbox.

You need to unzip these toolboxes in your working directory, so that you have toolbox_signal, toolbox_general and toolbox_graph in your directory.

For Scilab user: you must replace the Matlab comment '%' by its Scilab counterpart '//'.

Recommandation: You should create a text file named for instance numericaltour.sce (in Scilab) or numericaltour.m (in Matlab) to write all the Scilab/Matlab command you want to execute. Then, simply run exec('numericaltour.sce'); (in Scilab) or numericaltour; (in Matlab) to run the commands.

Execute this line only if you are using Matlab.

getd = @(p)path(p,path); % scilab users must *not* execute this


Then you can add the toolboxes to the path.

getd('toolbox_signal/');
getd('toolbox_general/');
getd('toolbox_graph/');


## Planar Triangulation

A planar triangulation is a collection of n 2D points, whose coordinates are stored in a (2,n) matrix vertex, and a topological collection of triangle, stored in a (m,2) matrix faces.

Number of points.

n = 200;


Compute randomized points in a square.

vertex = 2*rand(2,n)-1;


A simple way to build a triangulation of the convex hull of the points is to compute the Delaunay triangulation of the points.

faces = delaunay(vertex(1,:),vertex(2,:))';


One can display the triangulation.

clf;
subplot(1,2,1);
hh = plot(vertex(1,:),vertex(2,:), 'k.');
axis('equal'); axis('off');
set(hh,'MarkerSize',10);
title('Points');
subplot(1,2,2);
plot_mesh(vertex,faces);
title('Triangulation');


## Point Modification

It is possible to modify the position of the points like a particles system. The dynamics is govered by the connectivity to enfoce an even distribution. During the modification of the positions, the connectivity is updated.

Fix some points on a disk.

m = 20;
t = linspace(0,2*pi,m+1); t(end) = [];
vertexF = [cos(t);sin(t)];
vertex(:,1:m) = vertexF;
faces = delaunay(vertex(1,:),vertex(2,:))';


Initialize the positions.

vertex1 = vertex;


Compute the delaunay triangulation.

faces1 = delaunay(vertex1(1,:),vertex1(2,:))';


Compute the list of edges.

E = [faces([1 2],:) faces([2 3],:) faces([3 1],:)];
p = size(E,2);


We build the adjacency matrix of the triangulation.

A = sparse( E(1,:), E(2,:), ones(p,1) );


Normalize the adjacency matrix to obtain a smoothing operator.

d = 1./sum(A);
iD = spdiags(d(:), 0, n,n);
W = iD * A;


Apply the filtering.

vertex1 = vertex1*W';


Set of the position of fixed points.

vertex1(:,1:m) = vertexF;


Display the positions before / after.

clf;
subplot(1,2,1);
plot_mesh(vertex,faces);
title('Before filering');
subplot(1,2,2);
plot_mesh(vertex1,faces1);
title('After filtering');


Exercice 1: (check the solution) Compute several steps of iterative filterings, while ensuring the positions of the fixed points.

exo1;