26 if ( p1 && p2 && p3 && result )
29 const double area =
triArea( p1, p2, p3 );
34 const double area1 =
triArea( &p, p2, p3 );
35 const double area2 =
triArea( p1, &p, p3 );
36 const double area3 =
triArea( p1, p2, &p );
37 const double u = area1 / area;
38 const double v = area2 / area;
39 const double w = area3 / area;
57 if ( p1 && p2 && p3 && result )
59 const double area =
triArea( p1, p2, p3 );
63 QgsDebugError( QStringLiteral(
"warning, p1, p2 and p3 are in a line" ) );
67 const double denominator = ( ( p2->
y() - p3->
y() ) * ( p1->
x() - p3->
x() ) - ( p3->
y() - p1->
y() ) * ( p3->
x() - p2->
x() ) );
68 if ( denominator != 0 )
70 px = ( 2 * u * area * ( p1->
x() - p3->
x() ) - 2 * v * area * ( p3->
x() - p2->
x() ) - p2->
x() * p3->
y() * ( p1->
x() - p3->
x() ) + p3->
x() * p1->
y() * ( p3->
x() - p2->
x() ) + p3->
x() * p2->
y() * ( p1->
x() - p3->
x() ) - p1->
x() * p3->
y() * ( p3->
x() - p2->
x() ) ) / denominator;
71 if ( ( p3->
x() - p2->
x() ) != 0 )
73 py = ( 2 * u * area - px * ( p2->
y() - p3->
y() ) - p2->
x() * p3->
y() + p3->
x() * p2->
y() ) / ( p3->
x() - p2->
x() );
77 py = ( 2 * v * area - px * ( p3->
y() - p1->
y() ) - p3->
x() * p1->
y() + p1->
x() * p3->
y() ) / ( p1->
x() - p3->
x() );
82 py = ( 2 * u * area * ( p3->
y() - p1->
y() ) - 2 * v * area * ( p2->
y() - p3->
y() ) - p2->
x() * p3->
y() * ( p3->
y() - p1->
y() ) + p3->
x() * p1->
y() * ( p2->
y() - p3->
y() ) + p3->
x() * p2->
y() * ( p3->
y() - p1->
y() ) - p1->
x() * p3->
y() * ( p2->
y() - p3->
y() ) ) / ( ( p3->
x() - p2->
x() ) * ( p3->
y() - p1->
y() ) - ( p1->
x() - p3->
x() ) * ( p2->
y() - p3->
y() ) );
83 if ( ( p2->
y() - p3->
y() ) != 0 )
85 px = ( 2 * u * area - py * ( p3->
x() - p2->
x() ) - p2->
x() * p3->
y() + p3->
x() * p2->
y() ) / ( p2->
y() - p3->
y() );
89 px = ( 2 * v * area - py * ( p1->
x() - p3->
x() ) - p3->
x() * p1->
y() + p1->
x() * p3->
y() ) / ( p3->
y() - p1->
y() );
110 return lower( n, i ) * std::pow( t, i ) * std::pow( ( 1 - t ), ( n - i ) );
120 if ( p1 && p2 && p3 && result )
122 const double distp1p2 = p1->
distance( *p2 );
123 const double distp2p3 = p2->
distance( *p3 );
124 if ( distp1p2 > distp2p3 )
131 const double denominator = -p3->
x() * p2->
y() + p3->
x() * p1->
y() + p1->
x() * p2->
y() + p2->
x() * p3->
y() - p2->
x() * p1->
y() - p1->
x() * p3->
y();
133 if ( denominator == 0 )
135 QgsDebugError( QStringLiteral(
"error: the three points are in a line" ) );
140 result->
setX( 0.5 * ( p1->
x() * p1->
x() * p2->
y() - p1->
x() * p1->
x() * p3->
y() - p3->
x() * p3->
x() * p2->
y() - p1->
y() * p2->
x() * p2->
x() - p1->
y() * p1->
y() * p3->
y() - p3->
y() * p3->
y() * p2->
y() + p1->
y() * p1->
y() * p2->
y() + p3->
y() * p2->
x() * p2->
x() - p1->
y() * p2->
y() * p2->
y() + p1->
y() * p3->
y() * p3->
y() + p1->
y() * p3->
x() * p3->
x() + p3->
y() * p2->
y() * p2->
y() ) / denominator );
141 result->
setY( -0.5 * ( p3->
x() * p2->
x() * p2->
x() + p2->
x() * p1->
y() * p1->
y() + p3->
x() * p2->
y() * p2->
y() - p3->
x() * p1->
x() * p1->
x() + p1->
x() * p3->
y() * p3->
y() - p3->
x() * p1->
y() * p1->
y() - p1->
x() * p2->
x() * p2->
x() - p2->
x() * p3->
y() * p3->
y() - p1->
x() * p2->
y() * p2->
y() - p2->
x() * p3->
x() * p3->
x() + p1->
x() * p3->
x() * p3->
x() + p2->
x() * p1->
x() * p1->
x() ) / denominator );
155 if ( thepoint && p1 && p2 )
158 Vector3D line( p2->
x() - p1->
x(), p2->
y() - p1->
y(), 0 );
160 const double a = normal.
getX();
161 const double b = normal.
getY();
162 const double c = -( normal.
getX() * p2->
x() + normal.
getY() * p2->
y() );
163 const double distance = std::fabs( ( a * thepoint->
x() + b * thepoint->
y() +
c ) / ( std::sqrt( a * a + b * b ) ) );
175 return std::tgamma( n + 1 );
180 const double tolerance = 0.0001;
182 if ( testp && p1 && p2 && p3 )
190 double px = testp->
x();
191 double py = testp->
y();
193 const double xmin = std::min( std::min( ax, px ), std::min( bx, cx ) );
194 const double ymin = std::min( std::min( ay, py ), std::min( by, cy ) );
204 double aValue = ( ax * ax + ay * ay ) *
triArea( p2, p3, testp );
205 aValue = aValue - ( ( bx * bx + by * by ) *
triArea( p1, p3, testp ) );
206 aValue = aValue + ( ( cx * cx + cy * cy ) *
triArea( p1, p2, testp ) );
207 aValue = aValue - ( ( px * px + py * py ) *
triArea( p1, p2, p3 ) );
209 return aValue > tolerance;
220 return angle( p1, point, p2, point ) > 90;
228 const double f1 = thepoint.
x() - p1->
x();
229 const double f2 = p2->
y() - p1->
y();
230 const double f3 = thepoint.
y() - p1->
y();
231 const double f4 = p2->
x() - p1->
x();
232 return f1 * f2 - f3 * f4;
244 if ( p1 && p2 && p3 && p4 )
247 const Vector3D p1p2( p2->
x() - p1->
x(), p2->
y() - p1->
y(), 0 );
248 const Vector3D p3p4( p4->
x() - p3->
x(), p4->
y() - p3->
y(), 0 );
252 t1 = ( p3->
x() - p1->
x() + t2 * p3p4.
getX() ) / p1p2.
getX();
257 t2 = ( p1->
x() + t1 * p1p2.
getX() - p3->
x() ) / p3p4.
getX();
264 if ( t1 > 0 && t1 < 1 && t2 > 0 && t2 < 1 )
266 if ( ( *p1 ) == ( *p3 ) || ( *p1 ) == ( *p4 ) || ( *p2 ) == ( *p3 ) || ( *p2 ) == ( *p4 ) )
287 if ( p1 && p2 && p3 && p4 )
290 const Vector3D p1p2( p2->
x() - p1->
x(), p2->
y() - p1->
y(), 0 );
291 const Vector3D p3p4( p4->
x() - p3->
x(), p4->
y() - p3->
y(), 0 );
295 t1 = ( p3->
x() - p1->
x() + t2 * p3p4.
getX() ) / p1p2.
getX();
300 t2 = ( p1->
x() + t1 * p1p2.
getX() - p3->
x() ) / p3p4.
getX();
304 intersection_point->
setX( 0 );
305 intersection_point->
setY( 0 );
306 intersection_point->
setZ( 0 );
310 if ( t1 > 0 && t1 < 1 && t2 > 0 && t2 < 1 )
312 if ( ( *p1 ) == ( *p3 ) || ( *p1 ) == ( *p4 ) || ( *p2 ) == ( *p3 ) || ( *p2 ) == ( *p4 ) )
314 intersection_point->
setX( 0 );
315 intersection_point->
setY( 0 );
316 intersection_point->
setZ( 0 );
320 intersection_point->
setX( p1->
x() * ( 1 - t1 ) + p2->
x() * t1 );
321 intersection_point->
setY( p1->
y() * ( 1 - t1 ) + p2->
y() * t1 );
322 intersection_point->
setZ( 0 );
340 if ( i >= 0 && i <= n )
352 if ( pa && pb && pc )
354 const double deter = ( pa->
x() * pb->
y() + pb->
x() * pc->
y() + pc->
x() * pa->
y() - pa->
x() * pc->
y() - pb->
x() * pa->
y() - pc->
x() * pb->
y() );
366 if ( n != 3 || i > n )
368 QgsDebugError( QStringLiteral(
"error, can't calculate hermite polynom" ) );
371 if ( n == 3 && i == 0 )
376 if ( n == 3 && i == 1 )
381 if ( n == 3 && i == 2 )
386 if ( n == 3 && i == 3 )
399 if ( n != 3 || i > n )
401 QgsDebugError( QStringLiteral(
"error, can't calculate hermite polynom" ) );
404 if ( n == 3 && i == 0 )
411 if ( n == 3 && i == 1 )
417 if ( n == 3 && i == 2 )
423 if ( n == 3 && i == 3 )
438 if ( v1 && v2 && result )
455 if ( v1->
getY() == 0 )
459 if ( v1->
getX() < 0 )
461 result->
setY( -length );
466 result->
setY( length );
472 const double a = 1 + ( v1->
getX() * v1->
getX() ) / ( v1->
getY() * v1->
getY() );
474 const double c = -( length * length );
475 const double d = b * b - 4 * a *
c;
483 result->
setX( ( -b + std::sqrt( d ) ) / ( 2 * a ) );
490 if ( !(
leftOf( point1, &point2, &point3 ) < 0 ) )
510 if ( v1->
getY() == 0 )
514 if ( v1->
getX() < 0 )
516 result->
setY( length );
521 result->
setY( -length );
527 const double a = 1 + ( v1->
getX() * v1->
getX() ) / ( v1->
getY() * v1->
getY() );
529 const double c = -( length * length );
530 const double d = b * b - 4 * a *
c;
538 result->
setX( ( -b + std::sqrt( d ) ) / ( 2 * a ) );
545 if ( (
leftOf( point1, &point2, &point3 ) < 0 ) )
563 if ( p1 && p2 && p3 && vec )
565 const double ax = p2->
x() - p1->
x();
566 const double ay = p2->
y() - p1->
y();
567 const double az = p2->
z() - p1->
z();
568 const double bx = p3->
x() - p1->
x();
569 const double by = p3->
y() - p1->
y();
570 const double bz = p3->
z() - p1->
z();
572 vec->
setX( ay * bz - az * by );
573 vec->
setY( az * bx - ax * bz );
574 vec->
setZ( ax * by - ay * bx );
580 if ( first && vec1 && second && vec2 )
590 return ( ( first->
x() * vec1->
getY() - first->
y() * vec1->
getX() - second->
x() * vec1->
getY() + second->
y() * vec1->
getX() ) / ( vec2->
getX() * vec1->
getY() - vec2->
getY() * vec1->
getX() ) );
594 QgsDebugError( QStringLiteral(
"warning: vectors are parallel" ) );
627 if ( tangent && target && result )
629 const double xt = tangent->
getX();
630 const double yt = tangent->
getY();
631 const double zt = tangent->
getZ();
633 const double xw = target->
getX();
634 const double yw = target->
getY();
635 const double zw = target->
getZ();
637 double xg1, yg1, zg1;
638 double xg2, yg2, zg2;
641 const double xgalpha1 = 1 / ( 2 * xt * xt * yw * yw * zt * zt - 2 * zt * zt * zt * xt * zw * xw + yt * yt * yt * yt * zw * zw + yt * yt * zw * zw * zt * zt + xt * xt * yt * yt * xw * xw + xt * xt * yw * yw * yt * yt - 2 * xt * xt * xt * zt * zw * xw + yt * yt * yt * yt * xw * xw + yt * yt * yw * yw * zt * zt + 2 * xt * xt * yt * yt * zw * zw - 2 * yt * yt * yt * yw * zt * zw + zt * zt * xt * xt * zw * zw + zt * zt * zt * zt * xw * xw + xt * xt * zt * zt * xw * xw + 2 * zt * zt * xw * xw * yt * yt - 2 * xt * xt * yw * zt * yt * zw - 2 * xt * yt * yt * yt * xw * yw - 2 * xt * xt * xt * yw * yt * xw - 2 * xt * zt * zt * xw * yt * yw - 2 * xt * zt * xw * yt * yt * zw - 2 * yw * zt * zt * zt * yt * zw + xt * xt * xt * xt * yw * yw + yw * yw * zt * zt * zt * zt + xt * xt * xt * xt * zw * zw );
644 QgsDebugError( QStringLiteral(
"warning, only complex solution of xg" ) );
647 xg1 = std::sqrt( xgalpha1 ) * ( -yt * yw * xt + yt * yt * xw + xw * zt * zt - zt * xt * zw );
648 xg2 = -sqrt( xgalpha1 ) * ( -yt * yw * xt + yt * yt * xw + xw * zt * zt - zt * xt * zw );
651 const double ygalpha1 = 1 / ( 2 * xt * xt * yw * yw * zt * zt - 2 * zt * zt * zt * xt * zw * xw + yt * yt * yt * yt * zw * zw + yt * yt * zw * zw * zt * zt + xt * xt * yt * yt * xw * xw + xt * xt * yw * yw * yt * yt - 2 * xt * xt * xt * zt * zw * xw + yt * yt * yt * yt * xw * xw + yt * yt * yw * yw * zt * zt + 2 * xt * xt * yt * yt * zw * zw - 2 * yt * yt * yt * yw * zt * zw + zt * zt * xt * xt * zw * zw + zt * zt * zt * zt * xw * xw + xt * xt * zt * zt * xw * xw + 2 * zt * zt * xw * xw * yt * yt - 2 * xt * xt * yw * zt * yt * zw - 2 * xt * yt * yt * yt * xw * yw - 2 * xt * xt * xt * yw * yt * xw - 2 * xt * zt * zt * xw * yt * yw - 2 * xt * zt * xw * yt * yt * zw - 2 * yw * zt * zt * zt * yt * zw + xt * xt * xt * xt * yw * yw + yw * yw * zt * zt * zt * zt + xt * xt * xt * xt * zw * zw );
654 QgsDebugError( QStringLiteral(
"warning, only complex solution of yg" ) );
657 yg1 = -sqrt( ygalpha1 ) * ( -yw * xt * xt - zt * zt * yw + zt * yt * zw + yt * xw * xt );
658 yg2 = std::sqrt( ygalpha1 ) * ( -yw * xt * xt - zt * zt * yw + zt * yt * zw + yt * xw * xt );
661 const double zgalpha1 = 1 / ( 2 * xt * xt * yw * yw * zt * zt - 2 * zt * zt * zt * xt * zw * xw + yt * yt * yt * yt * zw * zw + yt * yt * zw * zw * zt * zt + xt * xt * yt * yt * xw * xw + xt * xt * yw * yw * yt * yt - 2 * xt * xt * xt * zt * zw * xw + yt * yt * yt * yt * xw * xw + yt * yt * yw * yw * zt * zt + 2 * xt * xt * yt * yt * zw * zw - 2 * yt * yt * yt * yw * zt * zw + zt * zt * xt * xt * zw * zw + zt * zt * zt * zt * xw * xw + xt * xt * zt * zt * xw * xw + 2 * zt * zt * xw * xw * yt * yt - 2 * xt * xt * yw * zt * yt * zw - 2 * xt * yt * yt * yt * xw * yw - 2 * xt * xt * xt * yw * yt * xw - 2 * xt * zt * zt * xw * yt * yw - 2 * xt * zt * xw * yt * yt * zw - 2 * yw * zt * zt * zt * yt * zw + xt * xt * xt * xt * yw * yw + yw * yw * zt * zt * zt * zt + xt * xt * xt * xt * zw * zw );
664 QgsDebugError( QStringLiteral(
"warning, only complex solution of zg" ) );
667 zg1 = -sqrt( zgalpha1 ) * ( yt * yw * zt - yt * yt * zw + xw * zt * xt - xt * xt * zw );
668 zg2 = std::sqrt( zgalpha1 ) * ( yt * yw * zt - yt * yt * zw + xw * zt * xt - xt * xt * zw );
673 if ( distance1 <= distance2 )
698 if ( test && pt1 && pt2 && pt3 )
700 const double a = ( pt1->
z() * ( pt2->
y() - pt3->
y() ) + pt2->
z() * ( pt3->
y() - pt1->
y() ) + pt3->
z() * ( pt1->
y() - pt2->
y() ) ) / ( ( pt1->
x() - pt2->
x() ) * ( pt2->
y() - pt3->
y() ) - ( pt2->
x() - pt3->
x() ) * ( pt1->
y() - pt2->
y() ) );
701 const double b = ( pt1->
z() * ( pt2->
x() - pt3->
x() ) + pt2->
z() * ( pt3->
x() - pt1->
x() ) + pt3->
z() * ( pt1->
x() - pt2->
x() ) ) / ( ( pt1->
y() - pt2->
y() ) * ( pt2->
x() - pt3->
x() ) - ( pt2->
y() - pt3->
y() ) * ( pt1->
x() - pt2->
x() ) );
702 const double c = pt1->
z() - a * pt1->
x() - b * pt1->
y();
703 const double zpredicted = test->
x() * a + test->
y() * b +
c;
704 return ( test->
z() - zpredicted );
715 if ( p1 && p2 && p3 && p4 )
717 const Vector3D v1( p2->
x() - p1->
x(), p2->
y() - p1->
y(), 0 );
718 const Vector3D v2( p4->
x() - p3->
x(), p4->
y() - p3->
y(), 0 );
static double distance2D(double x1, double y1, double x2, double y2)
Returns the 2D distance between (x1, y1) and (x2, y2).
Point geometry type, with support for z-dimension and m-values.
void setY(double y)
Sets the point's y-coordinate.
void setX(double x)
Sets the point's x-coordinate.
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
void setZ(double z)
Sets the point's z-coordinate.
Represents a 3D-Vector, capable of storing x, y and z-coordinates in double values.
void setX(double x)
Sets the x-component of the vector.
double getY() const
Returns the y-component of the vector.
double getX() const
Returns the x-component of the vector.
void setY(double y)
Sets the y-component of the vector.
double getZ() const
Returns the z-component of the vector.
double getLength() const
Returns the length of the vector.
void setZ(double z)
Sets the z-component of the vector.
bool ANALYSIS_EXPORT normalLeft(Vector3D *v1, Vector3D *result, double length)
Assigns the vector 'result', which is normal to the vector 'v1', on the left side of v1 and has lengt...
bool ANALYSIS_EXPORT inDiametral(QgsPoint *p1, QgsPoint *p2, QgsPoint *point)
Tests, whether 'point' is inside the diametral circle through 'p1' and 'p2'.
bool ANALYSIS_EXPORT derVec(const Vector3D *v1, const Vector3D *v2, Vector3D *result, double x, double y)
Calculates the z-component of a vector with coordinates 'x' and 'y'which is in the same tangent plane...
double ANALYSIS_EXPORT calcBernsteinPoly(int n, int i, double t)
Calculates the value of a Bernstein polynomial.
int ANALYSIS_EXPORT faculty(int n)
Faculty function.
bool ANALYSIS_EXPORT BarycentricToXY(double u, double v, double w, QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *result)
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored).
double ANALYSIS_EXPORT triArea(QgsPoint *pa, QgsPoint *pb, QgsPoint *pc)
Returns the area of a triangle. If the points are ordered counterclockwise, the value will be positiv...
bool ANALYSIS_EXPORT pointInsideTriangle(double x, double y, QgsPoint *p1, QgsPoint *p2, QgsPoint *p3)
Returns true, if the point with coordinates x and y is inside (or at the edge) of the triangle p1,...
bool ANALYSIS_EXPORT normalRight(Vector3D *v1, Vector3D *result, double length)
Assigns the vector 'result', which is normal to the vector 'v1', on the right side of v1 and has leng...
double ANALYSIS_EXPORT crossVec(QgsPoint *first, Vector3D *vec1, QgsPoint *second, Vector3D *vec2)
Calculates the intersection of the two vectors vec1 and vec2, which start at first(vec1) and second(v...
bool ANALYSIS_EXPORT lineIntersection(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Returns true, if line1 (p1 to p2) and line2 (p3 to p4) intersect. If the lines have an endpoint in co...
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
double ANALYSIS_EXPORT planeTest(QgsPoint *test, QgsPoint *pt1, QgsPoint *pt2, QgsPoint *pt3)
Tests, if 'test' is in the same plane as 'p1', 'p2' and 'p3' and returns the z-difference from the pl...
bool ANALYSIS_EXPORT circumcenter(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *result)
Calculates the center of the circle passing through p1, p2 and p3. Returns true in case of success an...
double ANALYSIS_EXPORT cFDerBernsteinPoly(int n, int i, double t)
Calculates the first derivative of a Bernstein polynomial with respect to the parameter t.
double ANALYSIS_EXPORT cFDerCubicHermitePoly(int n, int i, double t)
Calculates the first derivative of a cubic Hermite polynomial with respect to the parameter t.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
double ANALYSIS_EXPORT distPointFromLine(QgsPoint *thepoint, QgsPoint *p1, QgsPoint *p2)
Calculates the (2 dimensional) distance from 'thepoint' to the line defined by p1 and p2.
bool ANALYSIS_EXPORT calcBarycentricCoordinates(double x, double y, QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *result)
Calculates the barycentric coordinates of a point (x,y) with respect to p1, p2, p3 and stores the thr...
double ANALYSIS_EXPORT calcCubicHermitePoly(int n, int i, double t)
Calculates the value of a cubic Hermite polynomial.
bool ANALYSIS_EXPORT inCircle(QgsPoint *testp, QgsPoint *p1, QgsPoint *p2, QgsPoint *p3)
Tests, whether 'testp' is inside the circle through 'p1', 'p2' and 'p3'.
void ANALYSIS_EXPORT normalFromPoints(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, Vector3D *vec)
Calculates the normal vector of the plane through the points p1, p2 and p3 and assigns the result to ...
bool ANALYSIS_EXPORT normalMinDistance(Vector3D *tangent, Vector3D *target, Vector3D *result)
Calculates a Vector orthogonal to 'tangent' with length 1 and closest possible to result....
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define QgsDebugError(str)