-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransform.m
More file actions
53 lines (35 loc) · 1.06 KB
/
transform.m
File metadata and controls
53 lines (35 loc) · 1.06 KB
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
function [ Xp] = transform( X,P0,P1,P2,P3 )
% transform given points (rows of X) which leads in irregular quadrilateral
% (P0, P1, P2, P3) to a rectangle all the other points are dropped
[np k] = size(X);
Pi = [P0 P1 P2 P3];
%%% Compute normalized normals
Ni = zeros(2,4);
Ni(:,1) = Pi(:,1) - Pi(:,4);
nt = Ni(1,1);
Ni(1,1) = -Ni(2,1);
Ni(2,1) = nt;
Ni(:,1) = Ni(:,1)/norm(Ni(:,1));
for i =2:4
Ni(:,i) = Pi(:,i) - Pi(:,i-1);
nt = Ni(1,i);
Ni(1,i) = -Ni(2,i);
Ni(2,i) = nt;
Ni(:,i) = Ni(:,i)/norm(Ni(:,i));
end
%%% Compute local coordinates and drop all which does not lies in chosen
%%% irregular quadrilateral
h = 0;
for j=1:np
P = [X(j,1); X(j,2)];
u = (P - Pi(:,1))' * Ni(:,1) / ( (P - Pi(:,1))' * Ni(:,1) + (P - Pi(:,3))' * Ni(:,3) ) ;
v = (P - Pi(:,1))' * Ni(:,2) / ( (P - Pi(:,1))' * Ni(:,2) + (P - Pi(:,4))' * Ni(:,4) ) ;
if (u >= 0) && (u <= 1) && (v >= 0) && (v <= 1)
h = h+1;
Xp(h,1) = u;
Xp(h,2) = v;
Xp(h,3:4) = X(j,3:4);
Xp(h,5:6) = X(j,1:2);
end
end
end