20#ifndef _KIS_PERSPECTVE_MATH_H_
21#define _KIS_PERSPECTVE_MATH_H_
27class KisPerspectiveMath {
29 KisPerspectiveMath() { }
31 static double* computeMatrixTransfo( const KisPoint& topLeft1, const KisPoint& topRight1, const KisPoint& bottomLeft1, const KisPoint& bottomRight1 , const KisPoint& topLeft2, const KisPoint& topRight2, const KisPoint& bottomLeft2, const KisPoint& bottomRight2);
32 static double* computeMatrixTransfoToPerspective( const KisPoint& topLeft, const KisPoint& topRight, const KisPoint& bottomLeft, const KisPoint& bottomRight, const TQRect& r);
33 static double* computeMatrixTransfoFromPerspective( const TQRect& r, const KisPoint& topLeft, const KisPoint& topRight, const KisPoint& bottomLeft, const KisPoint& bottomRight);
39 inline static KisPoint matProd( const double (&m)[3][3], const KisPoint& p)
41 double s = ( p.x() * m[2][0] + p.y() * m[2][1] + 1.0);
42 s = (s == 0.) ? 1. : 1./s;
43 return KisPoint( (p.x() * m[0][0] + p.y() * m[0][1] + m[0][2] ) * s,
44 (p.x() * m[1][0] + p.y() * m[1][1] + m[1][2] ) * s );
46 static inline LineEquation computeLineEquation( const KisPoint* p1, const KisPoint* p2)
49 double x1 = p1->x(); double x2 = p2->x();
50 if( fabs(x1 - x2) < 0.000001 )
54 eq.a = (p2->y() - p1->y()) / (double)( x2 - x1 );
55 eq.b = -eq.a * x1 + p1->y();
58 static inline KisPoint computeIntersection( const LineEquation& d1, const LineEquation& d2)
60 double a1 = d1.a; double a2 = d2.a;
61 if( fabs(a1 - a2) < 0.000001 )
65 double x = (d1.b - d2.b) / (a2 - a1);
66 return KisPoint(x, a2 * x + d2.b);
|