# def dist return Math sqrt end def phi return end def count_lin tri v0

 ``` 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87``` ```def dist(a, b) return Math.sqrt(a*a + b*b) end def phi(x) return x * x * x end def count_lin(tri, p) v0 = tri[0] v1 = tri[1] v2 = tri[2] #build A aarr = Array.new(3) { Array.new(3) } aarr[0][0] = 0 aarr[1][1] = 0 aarr[2][2] = 0 aarr[0][1] = phi(dist(v0[0] - v1[0], v0[1] - v1[1])) aarr[1][0] = aarr[0][1] aarr[0][2] = phi(dist(v0[0] - v2[0], v0[1] - v2[1])) aarr[2][0] = aarr[0][2] aarr[1][2] = phi(dist(v1[0] - v2[0], v1[1] - v2[1])) aarr[2][1] = aarr[1][2] varr = Array.new(3) { Array.new(3) } varr[0][0] = 1 varr[0][1] = 1 varr[0][2] = 1 varr[1][0] = v0[0] varr[1][1] = v1[0] varr[1][2] = v2[0] varr[2][0] = v0[1] varr[2][1] = v1[1] varr[2][2] = v2[1] m = Array.new(6) { Array.new(6) } for i in (0 .. 2) for j in (0 .. 2) m[i][j] = aarr[i][j] end end for i in (3 .. 5) for j in (0 .. 2) m[i][j] = varr[i - 3][j] end end for i in (0 .. 2) for j in (3 .. 5) m[i][j] = varr[j - 3][i] end end for i in (3 .. 5) for j in (3 .. 5) m[i][j] = 0 end end matr = Matrix.rows(m) b = Array.new(6) { Array.new(1) } b[0][0] = v0[2] b[1][0] = v1[2] b[2][0] = v2[2] b[3][0] = 0 b[4][0] = 0 b[5][0] = 0 bmatr = Matrix.rows(b) wv = matr.inverse * bmatr warr = Array.new(3) varr = Array.new(3) warr[0] = wv.element(0, 0) warr[1] = wv.element(1, 0) warr[2] = wv.element(2, 0) varr[0] = wv.element(3, 0) varr[1] = wv.element(4, 0) varr[2] = wv.element(5, 0) #count y res = 0.0 res += warr[0] * phi(dist(p[0] - v0[0], p[1] - v0[1])) res += warr[1] * phi(dist(p[0] - v1[0], p[1] - v1[1])) res += warr[2] * phi(dist(p[0] - v2[0], p[1] - v2[1])) res += varr[0] res += varr[1] * p[0] res += varr[2] * p[1] #return height in p return res end ```