comparison +grid/old/triang_interp.m @ 0:48b6fb693025

Initial commit.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 17 Sep 2015 10:12:50 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:48b6fb693025
1 classdef triang_interp
2 properties
3 g1, g2 ,g3 % Curves encirling the tirangle in the positive direction.
4 A,B,C % The corners of the triangle
5 Sa, Sb, Sc % Mappings from square with different sides collapsed
6 end
7
8 methods
9 function o = triang_interp(g1,g2,g3)
10 o.g1 = g1;
11 o.g2 = g2;
12 o.g3 = g3;
13 o.A = g1(0);
14 o.B = g2(0);
15 o.C = g3(0);
16 o.Sa = grid.triang_interp.square_to_triangle_interp(g2,g3,g1);
17 o.Sb = grid.triang_interp.square_to_triangle_interp(g3,g1,g2);
18 o.Sc = grid.triang_interp.square_to_triangle_interp(g1,g2,g3);
19 end
20
21
22 function show(o,N)
23 % Show the mapped meridians of the triangle.
24 % Might be used for the barycentric coordinates.
25 ma = @(t)o.Sa(1/2,1-t);
26 mb = @(t)o.Sb(1/2,1-t);
27 mc = @(t)o.Sc(1/2,1-t);
28
29 na = @(t)o.Sa(t,1/2);
30
31 ka = @(t)(o.g1(1-t)+o.g2(t))/2;
32
33 h = grid.plot_curve(ma);
34 h.Color = Color.blue;
35 h = grid.plot_curve(mb);
36 h.Color = Color.blue;
37 h = grid.plot_curve(mc);
38 h.Color = Color.blue;
39
40 h = grid.plot_curve(na);
41 h.Color = Color.red;
42
43 h = grid.plot_curve(ka);
44 h.Color = Color.red;
45
46 [a(1),a(2)] = ma(1/3);
47 [b(1),b(2)] = mb(1/3);
48 [c(1),c(2)] = mc(1/3);
49
50 d = ka(1-1/3);
51
52
53 grid.label_pt(a,b,c,d);
54
55
56 % t = linspace(0,1,N);
57 % for i = 1:N
58 % sa = @(s)o.Sa(s,t(i));
59 % sb = @(s)o.Sb(s,t(i));
60 % sc = @(s)o.Sc(s,t(i));
61
62 % h = grid.plot_curve(sa);
63 % h.Color = Color.blue;
64 % h = grid.plot_curve(sb);
65 % h.Color = Color.blue;
66 % h = grid.plot_curve(sc);
67 % h.Color = Color.blue;
68 % end
69
70 h = grid.plot_curve(o.g1);
71 h.LineWidth = 2;
72 h.Color = Color.red;
73
74 h = grid.plot_curve(o.g2);
75 h.LineWidth = 2;
76 h.Color = Color.red;
77
78 h = grid.plot_curve(o.g3);
79 h.LineWidth = 2;
80 h.Color = Color.red;
81
82 end
83
84
85 end
86
87 methods(Static)
88 % Makes a mapping from the unit square to a triangle by collapsing
89 % one of the sides of the squares to a corner on the triangle
90 % The collapsed side is mapped to the corner oposite to g1.
91 % This is done such that for S(s,t), S(s,1) = g1(s)
92 function S = square_to_triangle_interp(g1,g2,g3)
93 corner = grid.line_segment(g3(0),g3(0));
94 S = grid.transfinite_interp(corner,g3,f(g1),f(g2))
95
96 % Function to flip a curve
97 function h = f(g)
98 h = @(t)g(1-t);
99 end
100 end
101 end
102
103 end
104
105 % % Return a mapping from u.v to x,y of the domain encircled by g1 g2 g3 in the the positive direction. created be using transfinite interpolation.
106 % function S = triang_interp(g1,g2,g3)
107 % A = g1(0)
108 % B = g2(0)
109 % C = g3(0)
110
111 % function [x,y] = S_fun(u,v)
112 % w = sqrt((u-1)^2+v^2)/sqrt(2); % Parameter for g3
113 % v = v*(1-u-v)*g1(u) + u*(1-u-v)*g2(v) + u*v*g3(w) ...
114 % +(1-u)*(1-v)*A+u*(1-v)*B + (1-u)*v*C;
115 % x = v(1);
116 % y = v(2);
117 % end
118 % S = @S_fun;
119 % end
120
121
122
123 % function subsref(obj,S)
124 % if ~all(isnumeric(S.subs{:}))
125 % error('Only supports calling object with number')
126 % end
127 % if numel(S.subs{:}) > 1
128 % disp('You''ve called the object with more than one argument');
129 % else
130 % disp(['You called the object with argument = ',num2str(S.subs{:})]);
131 % end
132 % end