rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
get_edges.m
1 function [p0, p1] = get_edges(grid,gid)
2 %function [p0, p1] = get_edges(grid,gid)
3 % method determining the world coordinates of the edges of a single
4 % element with global index 'gid'.
5 %
6 % 'i'-th edge goes from 'p0(:,i)' to 'p1(:,i)'
7 %
8 % parameters:
9 % gid: global index of element for which edge coordinates are requested
10 %
11 % return values:
12 % p0: lowest coordinate of the edge
13 % p1: highest coordinate of the edge
14 %
15 % @note vectorized version for multiple elements not yet implemented
16 
17 % Bernard Haasdonk 27.3.2007
18 
19  dim = grid.dimension;
20 
21 % generate list of local coordinates to be connected
22 % idea: plot n-1 d bottom cube, its shifted top version and the
23 % connecting lines:
24 % dim = 1 => [1 2]
25 % dim = 2 => [1 2; 3,4; 1 3; 2 4]
26 % dim = 3 => [1 2; 3,4; 1 3; 2 4, 5 6; 7,8; 5 7; 6 8; 1 5 ; 2 6 ;
27 % 3 7 ; 4 8]
28 li = [1 2];
29 for i = 2:dim
30  % assume li is local coordinate li of lower n-1 d patch
31  li = [li; li + 2^(i-1)];
32  % now li is local coordinate li of lower and upper n-1 d patch
33  li = [li; (1:2^(i-1))' ,(1:2^(i-1))'+2^(i-1)];
34 end;
35 
36 % get coordinates of elements vertices:
37 vi = grid.vertexindex(gid,:);
38 vertices = grid.vertex(vi,:);
39 
40 p0 = vertices(li(:,1),:)';
41 p1 = vertices(li(:,2),:)';
42 
43 end
44