Important: Please read the installation page for details about how to install the toolboxes. $\newcommand{\dotp}[2]{\langle #1, #2 \rangle}$ $\newcommand{\enscond}[2]{\lbrace #1, #2 \rbrace}$ $\newcommand{\pd}[2]{ \frac{ \partial #1}{\partial #2} }$ $\newcommand{\umin}[1]{\underset{#1}{\min}\;}$ $\newcommand{\umax}[1]{\underset{#1}{\max}\;}$ $\newcommand{\umin}[1]{\underset{#1}{\min}\;}$ $\newcommand{\uargmin}[1]{\underset{#1}{argmin}\;}$ $\newcommand{\norm}[1]{\|#1\|}$ $\newcommand{\abs}[1]{\left|#1\right|}$ $\newcommand{\choice}[1]{ \left\{ \begin{array}{l} #1 \end{array} \right. }$ $\newcommand{\pa}[1]{\left(#1\right)}$ $\newcommand{\diag}[1]{{diag}\left( #1 \right)}$ $\newcommand{\qandq}{\quad\text{and}\quad}$ $\newcommand{\qwhereq}{\quad\text{where}\quad}$ $\newcommand{\qifq}{ \quad \text{if} \quad }$ $\newcommand{\qarrq}{ \quad \Longrightarrow \quad }$ $\newcommand{\ZZ}{\mathbb{Z}}$ $\newcommand{\CC}{\mathbb{C}}$ $\newcommand{\RR}{\mathbb{R}}$ $\newcommand{\EE}{\mathbb{E}}$ $\newcommand{\Zz}{\mathcal{Z}}$ $\newcommand{\Ww}{\mathcal{W}}$ $\newcommand{\Vv}{\mathcal{V}}$ $\newcommand{\Nn}{\mathcal{N}}$ $\newcommand{\NN}{\mathcal{N}}$ $\newcommand{\Hh}{\mathcal{H}}$ $\newcommand{\Bb}{\mathcal{B}}$ $\newcommand{\Ee}{\mathcal{E}}$ $\newcommand{\Cc}{\mathcal{C}}$ $\newcommand{\Gg}{\mathcal{G}}$ $\newcommand{\Ss}{\mathcal{S}}$ $\newcommand{\Pp}{\mathcal{P}}$ $\newcommand{\Ff}{\mathcal{F}}$ $\newcommand{\Xx}{\mathcal{X}}$ $\newcommand{\Mm}{\mathcal{M}}$ $\newcommand{\Ii}{\mathcal{I}}$ $\newcommand{\Dd}{\mathcal{D}}$ $\newcommand{\Ll}{\mathcal{L}}$ $\newcommand{\Tt}{\mathcal{T}}$ $\newcommand{\si}{\sigma}$ $\newcommand{\al}{\alpha}$ $\newcommand{\la}{\lambda}$ $\newcommand{\ga}{\gamma}$ $\newcommand{\Ga}{\Gamma}$ $\newcommand{\La}{\Lambda}$ $\newcommand{\si}{\sigma}$ $\newcommand{\Si}{\Sigma}$ $\newcommand{\be}{\beta}$ $\newcommand{\de}{\delta}$ $\newcommand{\De}{\Delta}$ $\newcommand{\phi}{\varphi}$ $\newcommand{\th}{\theta}$ $\newcommand{\om}{\omega}$ $\newcommand{\Om}{\Omega}$
This tour explores some basics about 2D triangulated mesh (loading, display, manipulations).
from __future__ import division
import nt_toolbox as nt
from nt_solutions import meshproc_1_basics_2d as solutions
%matplotlib inline
%load_ext autoreload
%autoreload 2
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.
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')
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.
subplot(1, 2, 1)
plot_mesh(vertex, faces)
title('Before filering')
subplot(1, 2, 2)
plot_mesh(vertex1, faces1)
title('After filtering')
Exercise 1
Compute several steps of iterative filterings, while ensuring the positions of the fixed points.
solutions.exo1()
## Insert your code here.