-
Notifications
You must be signed in to change notification settings - Fork 1
/
tri2pts.m
71 lines (62 loc) · 2.01 KB
/
tri2pts.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [uxy,tn,a12,a13] = tri2pts( p, t, u, tn, a12, a13 )
% TRI2PTS - interpolate a scalar field defined on a triangular grid at some
% points not necessarily on a grid.
%
% Usage: [uxy,tn,a12,a13] = tri2pts( p, t, u, x, y )
% uxy = tri2pts( p, t, u, tn, a12, a13 )
%
% Arguments and functioning are similar to tri2grid except that x and y
% need not define a grid. x and y should be matrices of the same size.
%
% p and t should define a triangular grid as generated by initmesh, pdetool,
% etc. u is a scalar field defined on that grid. u can also be a matrix
% with multiple columns, in which case, each column is a scalar field.
%
% If x is a vector, uxy will have interesting dimensions of PxN, where p
% is the length of x and N is the number of columns in u. If x is a
% matrix, then uxy will have dimensions of P1xP2...xN, where Pi are the
% dimensions of x.
%
% Note that pdeintrp_arbitrary now basically depends on this function for
% interpolating scalars.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: tri2pts.m 70 2007-02-22 02:24:34Z dmk $
%
% Copyright (C) 2005 David M. Kaplan
% Licence: GPL (Gnu Public License)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make a column vector if given a row vector. Leave alone otherwise.
if prod(size(u)) == max(size(u))
u = u(:);
end
if nargin == 5
% Need to find enclosing triangles.
x = tn;
y = a12;
[tn,a12,a13] = tsearch_arbitrary( p, t, x, y );
end
s = size(tn);
tn = tn(:);
a12 = a12(:);
a13 = a13(:);
ii = find( ~isnan(tn) );
uxy = repmat( NaN, [ length(tn), size(u,2) ] );
% Get interpolation.
oo = ones( 1, size(u,2) );
uxy(ii,:) = ( 1 - a12(ii,oo) - a13(ii,oo) ) .* u(t(1,tn(ii)),:) + ...
a12(ii,oo) .* u(t(2,tn(ii)),:) + ...
a13(ii,oo) .* u(t(3,tn(ii)),:);
% Reshape appropriately
ss = s;
if ss(end)==1, ss = ss(1:end-1); end
uxy = reshape( uxy, [ ss, size(u,2) ] );
if nargout > 1
tn = reshape(tn,s);
a12 = reshape(a12(:,1),s);
a13 = reshape(a13(:,1),s);
else
clear tn a12 13
end