QGIS API Documentation  2.99.0-Master (08c2e66)
MathUtils.h
Go to the documentation of this file.
1 /***************************************************************************
2  MathUtils.h - description
3  -------------------
4  copyright : (C) 2004 by Marco Hugentobler
5  email : [email protected]
6  ***************************************************************************/
7
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16
17 #ifndef MATHUTILS_H
18 #define MATHUTILS_H
19
20 #include <cmath>
21 #include "qgis_analysis.h"
22
23 class Point3D;
24 class Vector3D;
25
26 namespace MathUtils
27 {
29  bool ANALYSIS_EXPORT calcBarycentricCoordinates( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3, Point3D* result );
30  bool ANALYSIS_EXPORT BarycentricToXY( double u, double v, double w, Point3D* p1, Point3D* p2, Point3D* p3, Point3D* result );
32  double ANALYSIS_EXPORT calcBernsteinPoly( int n, int i, double t );
34  double ANALYSIS_EXPORT cFDerBernsteinPoly( int n, int i, double t );
36  double ANALYSIS_EXPORT calcCubicHermitePoly( int n, int i, double t );
38  double ANALYSIS_EXPORT cFDerCubicHermitePoly( int n, int i, double t );
40  bool ANALYSIS_EXPORT circumcenter( Point3D* p1, Point3D* p2, Point3D* p3, Point3D* result );
42  double ANALYSIS_EXPORT distPointFromLine( Point3D* thepoint, Point3D* p1, Point3D* p2 );
44  int ANALYSIS_EXPORT faculty( int n );
46  bool ANALYSIS_EXPORT inCircle( Point3D* testp, Point3D* p1, Point3D* p2, Point3D* p3 );
48  bool ANALYSIS_EXPORT inDiametral( Point3D* p1, Point3D* p2, Point3D* point );
50  double ANALYSIS_EXPORT leftOf( Point3D* thepoint, Point3D* p1, Point3D* p2 );
52  bool ANALYSIS_EXPORT lineIntersection( Point3D* p1, Point3D* p2, Point3D* p3, Point3D* p4 );
54  bool ANALYSIS_EXPORT lineIntersection( Point3D* p1, Point3D* p2, Point3D* p3, Point3D* p4, Point3D* intersection_point );
56  int ANALYSIS_EXPORT lower( int n, int i );
58  double ANALYSIS_EXPORT max( double x, double y );
60  double ANALYSIS_EXPORT min( double x, double y );
62  double ANALYSIS_EXPORT power( double a, int b );//calculates a power b
64  double ANALYSIS_EXPORT triArea( Point3D* pa, Point3D* pb, Point3D* pc );
66  bool ANALYSIS_EXPORT derVec( const Vector3D* v1, const Vector3D* v2, Vector3D* result, double x, double y );
68  double ANALYSIS_EXPORT crossVec( Point3D* first, Vector3D* vec1, Point3D* second, Vector3D* vec2 );
70  bool ANALYSIS_EXPORT normalLeft( Vector3D* v1, Vector3D* result, double length );
72  bool ANALYSIS_EXPORT normalRight( Vector3D* v1, Vector3D* result, double length );
74  void ANALYSIS_EXPORT normalFromPoints( Point3D* p1, Point3D* p2, Point3D* p3, Vector3D* vec );
76  bool ANALYSIS_EXPORT pointInsideTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 );
78  bool ANALYSIS_EXPORT normalMinDistance( Vector3D* tangent, Vector3D* target, Vector3D* result );
80  double ANALYSIS_EXPORT planeTest( Point3D* test, Point3D* pt1, Point3D* pt2, Point3D* pt3 );
82  double ANALYSIS_EXPORT angle( Point3D* p1, Point3D* p2, Point3D* p3, Point3D* p4 );
83 }
84
85 #endif
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether &#39;thepoint&#39; is left or right of the line from &#39;p1&#39; to &#39;p2&#39;. Negativ values mean left a...
Definition: MathUtils.cc:310
double ANALYSIS_EXPORT power(double a, int b)
Power function for integer coefficients.
Definition: MathUtils.cc:468
bool ANALYSIS_EXPORT normalRight(Vector3D *v1, Vector3D *result, double length)
Assigns the vector &#39;result&#39;, which is normal to the vector &#39;v1&#39;, on the right side of v1 and has leng...
Definition: MathUtils.cc:647
double ANALYSIS_EXPORT cFDerBernsteinPoly(int n, int i, double t)
Calculates the first derivative of a Bernstein polynomial with respect to the parameter t...
Definition: MathUtils.cc:114
bool ANALYSIS_EXPORT lineIntersection(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Returns true, if line1 (p1 to p2) and line2 (p3 to p4) intersect. If the lines have an endpoint in co...
Definition: MathUtils.cc:329
double ANALYSIS_EXPORT distPointFromLine(Point3D *thepoint, Point3D *p1, Point3D *p2)
Calculates the (2 dimensional) distance from &#39;thepoint&#39; to the line defined by p1 and p2...
Definition: MathUtils.cc:204
bool ANALYSIS_EXPORT BarycentricToXY(double u, double v, double w, Point3D *p1, Point3D *p2, Point3D *p3, Point3D *result)
Definition: MathUtils.cc:53
void ANALYSIS_EXPORT normalFromPoints(Point3D *p1, Point3D *p2, Point3D *p3, Vector3D *vec)
Calculates the normal vector of the plane through the points p1, p2 and p3 and assigns the result to ...
Definition: MathUtils.cc:703
double ANALYSIS_EXPORT triArea(Point3D *pa, Point3D *pb, Point3D *pc)
Returns the area of a triangle. If the points are ordered counterclockwise, the value will be positiv...
Definition: MathUtils.cc:490
bool ANALYSIS_EXPORT calcBarycentricCoordinates(double x, double y, Point3D *p1, Point3D *p2, Point3D *p3, Point3D *result)
Calculates the barycentric coordinates of a point (x,y) with respect to p1, p2, p3 and stores the thr...
Definition: MathUtils.cc:24
bool ANALYSIS_EXPORT normalMinDistance(Vector3D *tangent, Vector3D *target, Vector3D *result)
Calculates a Vector orthogonal to &#39;tangent&#39; with length 1 and closest possible to result...
Definition: MathUtils.cc:769
bool ANALYSIS_EXPORT pointInsideTriangle(double x, double y, Point3D *p1, Point3D *p2, Point3D *p3)
Returns true, if the point with coordinates x and y is inside (or at the edge) of the triangle p1...
Definition: MathUtils.cc:751
Point3D is a class to represent a three dimensional point.
Definition: Point3D.h:25
Class Vector3D represents a 3D-Vector, capable to store x-,y- and z-coordinates in double values...
Definition: Vector3D.h:29
bool ANALYSIS_EXPORT normalLeft(Vector3D *v1, Vector3D *result, double length)
Assigns the vector &#39;result&#39;, which is normal to the vector &#39;v1&#39;, on the left side of v1 and has lengt...
Definition: MathUtils.cc:591
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
double ANALYSIS_EXPORT planeTest(Point3D *test, Point3D *pt1, Point3D *pt2, Point3D *pt3)
Tests, if &#39;test&#39; is in the same plane as &#39;p1&#39;, &#39;p2&#39; and &#39;p3&#39; and returns the z-difference from the pl...
Definition: MathUtils.cc:840
bool ANALYSIS_EXPORT circumcenter(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *result)
Calculates the center of the circle passing through p1, p2 and p3. Returns true in case of success an...
Definition: MathUtils.cc:119
bool ANALYSIS_EXPORT inCircle(Point3D *testp, Point3D *p1, Point3D *p2, Point3D *p3)
Tests, whether &#39;testp&#39; is inside the circle through &#39;p1&#39;, &#39;p2&#39; and &#39;p3&#39;.
Definition: MathUtils.cc:244
double ANALYSIS_EXPORT crossVec(Point3D *first, Vector3D *vec1, Point3D *second, Vector3D *vec2)
Calculates the intersection of the two vectors vec1 and vec2, which start at first(vec1) and second(v...
Definition: MathUtils.cc:721
double ANALYSIS_EXPORT calcBernsteinPoly(int n, int i, double t)
Calculates the value of a Bernstein polynomial.
Definition: MathUtils.cc:104
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cc:425
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...
Definition: MathUtils.cc:537
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cc:857
double ANALYSIS_EXPORT calcCubicHermitePoly(int n, int i, double t)
Calculates the value of a cubic Hermite polynomial.
Definition: MathUtils.cc:504
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 &#39;x&#39; and &#39;y&#39;which is in the same tangent plane...
Definition: MathUtils.cc:576
bool ANALYSIS_EXPORT inDiametral(Point3D *p1, Point3D *p2, Point3D *point)
Tests, whether &#39;point&#39; is inside the diametral circle through &#39;p1&#39; and &#39;p2&#39;.
Definition: MathUtils.cc:284
int ANALYSIS_EXPORT faculty(int n)
Faculty function.
Definition: MathUtils.cc:224