Polynom getLinearInterpolation(QPointF *p) { Polynom result; double a, b, c, d; d = determinant( p[0].x(), p[0].y(), 1, p[1].x(), p[1].y(), 1, p[2].x(), p[2].y(), 1 ); a = determinant( function(p[0].x(), p[0].y()), p[0].y(), 1, function(p[1].x(), p[1].y()), p[1].y(), 1, function(p[2].x(), p[2].y()), p[2].y(), 1 ) / d; b = determinant( p[0].x(), function(p[0].x(), p[0].y()), 1, p[1].x(), function(p[1].x(), p[1].y()), 1, p[2].x(), function(p[2].x(), p[2].y()), 1 ) / d; c = determinant( p[0].x(), p[0].y(), function(p[0].x(), p[0].y()), p[1].x(), p[1].y(), function(p[1].x(), p[1].y()), p[2].x(), p[2].y(), function(p[2].x(), p[2].y()) ) / d; addToPolynom(result, 1, 0, a); addToPolynom(result, 0, 1, b); addToPolynom(result, 0, 0, c); return result; }
Polynom polynomPower(const Polynom &p, quint32 power) { Polynom result; if (!power) { addToPolynom(result, 0, 0, 1); return result; } result = p; for (quint32 i = 0; i < power - 1; ++i) result = polynomMultiply(result, p); return result; }
Polynom polynomMultiply(const Polynom &p1, const Polynom &p2) { Polynom result; int i, j; Monom m; for (i = 0; i < p1.size(); ++i) for (j = 0; j < p2.size(); ++j) { m.xPow = p1.at(i).xPow + p2.at(j).xPow; m.yPow = p1.at(i).yPow + p2.at(j).yPow; m.c = p1.at(i).c * p2.at(j).c; addToPolynom(result, m); } return result; }
Polynom psiFunctionPolynom(const Triangle &triangle, short n) { double u1, u2, v1, v2; QPointF a = triangle[0], b = triangle[1], c = triangle[2]; Polynom result; if (n == 0) { u1 = b.x(); v1 = b.y(); } else { u1 = a.x(); v1 = a.y(); } if (n == 2) { u2 = b.x(); v2 = b.y(); } else { u2 = c.x(); v2 = c.y(); } addToPolynom(result, 1, 0, v2 - v1); addToPolynom(result, 0, 1, u1 - u2); addToPolynom(result, 0, 0, u2 * v1 - v2 * u1); return result; }
qreal getIntegralForGoodTriangle(QPointF * const triangle, const Polynom &polynom) { qreal transform[4]; transformateTriangle(triangle, transform); qreal newcx = transform[0] * triangle[2].x() + transform[2]; Polynom newPolynom, polynomPart1, polynomPart2, polynomBase; int i, j; for (i = 0; i < polynom.size(); ++i) { polynomPart1.clear(); polynomBase.clear(); addToPolynom(polynomBase, 1, 0, 1 / transform[0]); addToPolynom(polynomBase, 0, 0, -transform[2] / transform[0]); polynomPart1 = polynomPower(polynomBase, polynom.at(i).xPow); polynomPart2.clear(); polynomBase.clear(); addToPolynom(polynomBase, 0, 1, 1 / transform[1]); addToPolynom(polynomBase, 0, 0, -transform[3] / transform[1]); polynomPart2 = polynomPower(polynomBase, polynom.at(i).yPow); for (j = 0; j < polynomPart2.size(); ++j) polynomPart2[j].c *= polynom.at(i).c; newPolynom = polynomAdd(newPolynom, polynomMultiply(polynomPart1, polynomPart2)); } qreal result = 0; for (i = 0; i < newPolynom.size(); ++i) { polynomBase.clear(); addToPolynom(polynomBase, 0, 0, 1); addToPolynom(polynomBase, 0, 1, newcx - 1); polynomBase = polynomPower(polynomBase, newPolynom.at(i).xPow + 1); addToPolynom(polynomBase, 0, newPolynom.at(i).xPow + 1, qPow(newcx, newPolynom.at(i).xPow + 1)); for (j = 0; j < polynomBase.size(); ++j) { polynomBase[j].c /= newPolynom.at(i).xPow + 1; polynomBase[j].yPow += newPolynom.at(i).yPow; } result += newPolynom.at(i).c * polynomIntegral(polynomBase) / qAbs(transform[0] * transform[1]); } return result; }
Polynom polynomAdd(const Polynom &p1, const Polynom &p2) { Polynom result = p1; for (int i = 0; i < p2.size(); ++i) addToPolynom(result, p2.at(i)); return result; }