1 | %'tps_eval_dxy': calculate the derivatives of thin plate spline (tps) interpolation at a set of points (limited to the 2D case) |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function [DMX,DMY] = tps_eval_dxy(dsites,ctrs) |
---|
4 | %------------------------------------------------------------------------ |
---|
5 | % OUTPUT: |
---|
6 | % DMX: Mx(N+3) matrix representing the contributions to the X |
---|
7 | % derivatives at the M sites from unit sources located at each of the N |
---|
8 | % centers, + 3 columns representing the contribution of the linear gradient part. |
---|
9 | % DMY: idem for Y derivatives |
---|
10 | % |
---|
11 | % INPUT: |
---|
12 | % dsites: M x s matrix of interpolation site coordinates (s=space dimension=2 here) |
---|
13 | % ctrs: N x s matrix of centre coordinates (initial data) |
---|
14 | % |
---|
15 | % RELATED FUNCTIONS: |
---|
16 | % tps_coeff, tps_eval |
---|
17 | % tps_coeff_field, set_subdomains, filter_tps, calc_field |
---|
18 | |
---|
19 | %======================================================================= |
---|
20 | % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
21 | % http://www.legi.grenoble-inp.fr |
---|
22 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
23 | % |
---|
24 | % This file is part of the toolbox UVMAT. |
---|
25 | % |
---|
26 | % UVMAT is free software; you can redistribute it and/or modify |
---|
27 | % it under the terms of the GNU General Public License as published |
---|
28 | % by the Free Software Foundation; either version 2 of the license, |
---|
29 | % or (at your option) any later version. |
---|
30 | % |
---|
31 | % UVMAT is distributed in the hope that it will be useful, |
---|
32 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
33 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
34 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
35 | %======================================================================= |
---|
36 | |
---|
37 | function [DMX,DMY] = tps_eval_dxy(dsites,ctrs) |
---|
38 | %% matrix declarations |
---|
39 | [M,s] = size(dsites); [N,s] = size(ctrs); |
---|
40 | Dsites=zeros(M,N); |
---|
41 | DM = zeros(M,N); |
---|
42 | % DMXY = zeros(M,N+1+s); |
---|
43 | |
---|
44 | %% Accumulate sum of squares of coordinate differences |
---|
45 | % The ndgrid command produces two MxN matrices: |
---|
46 | % Dsites, consisting of N identical columns (each containing |
---|
47 | % the d-th coordinate of the M interpolation sites) |
---|
48 | % Ctrs, consisting of M identical rows (each containing |
---|
49 | % the d-th coordinate of the N centers) |
---|
50 | |
---|
51 | [Dsites,Ctrs] = ndgrid(dsites(:,1),ctrs(:,1));%d coordinates of interpolation points (Dsites) and initial points (Ctrs) |
---|
52 | DX=Dsites-Ctrs;% set of x wise distances between sites and centres |
---|
53 | [Dsites,Ctrs] = ndgrid(dsites(:,2),ctrs(:,2));%d coordinates of interpolation points (Dsites) and initial points (Ctrs) |
---|
54 | DY=Dsites-Ctrs;% set of y wise distances between sites and centres |
---|
55 | DM = DX.*DX + DY.*DY;% add d component squared |
---|
56 | |
---|
57 | %% calculate matrix of tps derivatives |
---|
58 | DM(DM~=0) = log(DM(DM~=0))+1; %=2 log(r)+1 derivative of the tps r^2 log(r) |
---|
59 | |
---|
60 | DMX=[DX.*DM zeros(M,1) ones(M,1) zeros(M,1)];% effect of mean gradient |
---|
61 | DMY=[DY.*DM zeros(M,1) zeros(M,1) ones(M,1)];% effect of mean gradient |
---|
62 | |
---|