QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
|
Convenience functions for geometry utils. More...
#include <qgsgeometryutils_base.h>
Static Public Member Functions | |
static double | angleBetweenThreePoints (double x1, double y1, double x2, double y2, double x3, double y3) |
Calculates the angle between the lines AB and BC, where AB and BC described by points a, b and b, c. | |
static bool | angleBisector (double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY, double &pointX, double &pointY, double &angle) |
Returns the point (pointX, pointY) forming the bisector from segment (aX aY) (bX bY) and segment (bX, bY) (dX, dY). | |
static bool | angleOnCircle (double angle, double angle1, double angle2, double angle3) |
Returns true if an angle is between angle1 and angle3 on a circle described by angle1, angle2 and angle3. | |
static double | averageAngle (double a1, double a2) |
Averages two angles, correctly handling negative angles and ensuring the result is between 0 and 2 pi. | |
static double | averageAngle (double x1, double y1, double x2, double y2, double x3, double y3) |
Calculates the average angle (in radians) between the two linear segments from (x1, y1) to (x2, y2) and (x2, y2) to (x3, y3). | |
static double | azimuth (double x1, double y1, double x2, double y2) |
Calculates Cartesian azimuth between points (x1, y1) and (x2, y2) (clockwise in degree, starting from north) | |
static bool | bisector (double aX, double aY, double bX, double bY, double cX, double cY, double &pointX, double &pointY) |
Returns the point (pointX, pointY) forming the bisector from point (aX, aY) to the segment (bX, bY) (cX, cY). | |
static double | ccwAngle (double dy, double dx) |
Returns the counter clockwise angle between a line with components dx, dy and the line with dx > 0 and dy = 0. | |
static bool | circleAngleBetween (double angle, double angle1, double angle2, bool clockwise) |
Returns true if, in a circle, angle is between angle1 and angle2. | |
static void | circleCenterRadius (double x1, double y1, double x2, double y2, double x3, double y3, double &radius, double ¢erX, double ¢erY) |
Returns radius and center of the circle through (x1 y1), (x2 y2), (x3 y3) | |
static bool | circleClockwise (double angle1, double angle2, double angle3) |
Returns true if the circle defined by three angles is ordered clockwise. | |
static double | circleLength (double x1, double y1, double x2, double y2, double x3, double y3) |
Length of a circular string segment defined by pt1, pt2, pt3. | |
static int | closestSideOfRectangle (double right, double bottom, double left, double top, double x, double y) |
Returns a number representing the closest side of a rectangle defined by /a right, bottom, left, top to the point at (x, y), where the point may be in the interior of the rectangle or outside it. | |
static double | distance2D (double x1, double y1, double x2, double y2) |
Returns the 2D distance between (x1, y1) and (x2, y2). | |
static double | distance3D (double x1, double y1, double z1, double x2, double y2, double z2) |
Returns the 3D distance between (x1, y1), (x2, y2) and (z2, z2). | |
template<typename T , typename... Args> | |
static bool | fuzzyDistanceEqual (T epsilon, const Args &... args) noexcept |
Compare equality between multiple pairs of values with a specified epsilon. | |
template<typename T , typename... Args> | |
static bool | fuzzyEqual (T epsilon, const Args &... args) noexcept |
Performs fuzzy comparison between pairs of values within a specified epsilon. | |
static double | interpolateArcValue (double angle, double a1, double a2, double a3, double zm1, double zm2, double zm3) |
Interpolate a value at given angle on circular arc given values (zm1, zm2, zm3) at three different angles (a1, a2, a3). | |
static int | leftOfLine (const double x, const double y, const double x1, const double y1, const double x2, const double y2) |
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> (x2, y2). | |
static double | lineAngle (double x1, double y1, double x2, double y2) |
Calculates the direction of line joining two points in radians, clockwise from the north direction. | |
static bool | lineIntersection (double p1x, double p1y, QgsVector v1, double p2x, double p2y, QgsVector v2, double &intersectionX, double &intersectionY) |
Computes the intersection between two lines. | |
static double | linePerpendicularAngle (double x1, double y1, double x2, double y2) |
Calculates the perpendicular angle to a line joining two points. | |
static bool | linesIntersection3D (const QgsVector3D &La1, const QgsVector3D &La2, const QgsVector3D &Lb1, const QgsVector3D &Lb2, QgsVector3D &intersection) |
An algorithm to calculate an (approximate) intersection of two lines in 3D. | |
static double | normalizedAngle (double angle) |
Ensures that an angle is in the range 0 <= angle < 2 pi. | |
static void | perpendicularCenterSegment (double centerPointX, double centerPointY, double segmentPoint1x, double segmentPoint1y, double segmentPoint2x, double segmentPoint2y, double &perpendicularSegmentPoint1x, double &perpendicularSegmentPoint1y, double &perpendicularSegmentPoint2x, double &perpendicularSegmentPoint2y, double segmentLength=0) |
Create a perpendicular line segment to a given segment [segmentPoint1,segmentPoint2] with its center at centerPoint. | |
static void | perpendicularOffsetPointAlongSegment (double x1, double y1, double x2, double y2, double proportion, double offset, double *x, double *y) |
Calculates a point a certain proportion of the way along the segment from (x1, y1) to (x2, y2), offset from the segment by the specified offset amount. | |
static double | pointFractionAlongLine (double x1, double y1, double x2, double y2, double px, double py) |
Given the line (x1, y1) to (x2, y2) and a point (px, py) returns the fraction of the line length at which the point lies. | |
static void | pointOnLineWithDistance (double x1, double y1, double x2, double y2, double distance, double &x, double &y, double *z1=nullptr, double *z2=nullptr, double *z=nullptr, double *m1=nullptr, double *m2=nullptr, double *m=nullptr) |
Calculates the point a specified distance from (x1, y1) toward a second point (x2, y2). | |
static bool | pointsAreCollinear (double x1, double y1, double x2, double y2, double x3, double y3, double epsilon) |
Given the points (x1, y1), (x2, y2) and (x3, y3) returns true if these points can be considered collinear with a specified tolerance epsilon. | |
static void | project (double aX, double aY, double aZ, double distance, double azimuth, double inclination, double &resultX, double &resultY, double &resultZ) |
Returns coordinates of a point which corresponds to this point projected by a specified distance with specified angles (azimuth and inclination), using Cartesian mathematics. | |
static bool | segmentIntersection (double p1x, double p1y, double p2x, double p2y, double q1x, double q1y, double q2x, double q2y, double &intersectionPointX, double &intersectionPointY, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false) |
Compute the intersection between two segments. | |
static double | skewLinesDistance (const QgsVector3D &P1, const QgsVector3D &P12, const QgsVector3D &P2, const QgsVector3D &P22) |
An algorithm to calculate the shortest distance between two skew lines. | |
static bool | skewLinesProjection (const QgsVector3D &P1, const QgsVector3D &P12, const QgsVector3D &P2, const QgsVector3D &P22, QgsVector3D &X1, double epsilon=0.0001) |
A method to project one skew line onto another. | |
static double | sqrDistance2D (double x1, double y1, double x2, double y2) |
Returns the squared 2D distance between (x1, y1) and (x2, y2). | |
static double | sqrDistance3D (double x1, double y1, double z1, double x2, double y2, double z2) |
Returns the squared 3D distance between (x1, y1), (x2, y2) and (z2, z2). | |
static double | sqrDistToLine (double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon) |
Returns the squared distance between a point and a line. | |
static double | sweepAngle (double centerX, double centerY, double x1, double y1, double x2, double y2, double x3, double y3) |
Calculates angle of a circular string part defined by pt1, pt2, pt3. | |
static double | triangleArea (double aX, double aY, double bX, double bY, double cX, double cY) |
Returns the area of the triangle denoted by the points (aX, aY), (bX, bY) and (cX, cY). | |
static void | weightedPointInTriangle (double aX, double aY, double bX, double bY, double cX, double cY, double weightB, double weightC, double &pointX, double &pointY) |
Returns a weighted point inside the triangle denoted by the points (aX, aY), (bX, bY) and (cX, cY). | |
Convenience functions for geometry utils.
Definition at line 30 of file qgsgeometryutils_base.h.
|
static |
Calculates the angle between the lines AB and BC, where AB and BC described by points a, b and b, c.
x1 | x-coordinate of point a |
y1 | y-coordinate of point a |
x2 | x-coordinate of point b |
y2 | y-coordinate of point b |
x3 | x-coordinate of point c |
y3 | y-coordinate of point c |
Definition at line 387 of file qgsgeometryutils_base.cpp.
|
static |
Returns the point (pointX, pointY) forming the bisector from segment (aX aY) (bX bY) and segment (bX, bY) (dX, dY).
The bisector segment of AB-CD is (point, projection of point by angle)
aX | x-coordinate of first vertex of the segment ab |
aY | y-coordinate of first vertex of the segment ab |
bX | x-coordinate of second vertex of the segment ab |
bY | y-coordinate of second vertex of the segment ab |
cX | x-coordinate of first vertex of the segment cd |
cY | y-coordinate of first vertex of the segment cd |
dX | x-coordinate of second vertex of the segment cd |
dY | y-coordinate of second vertex of the segment cd |
pointX | x-coordinate of generated point |
pointY | y-coordinate of generated point |
angle | angle of the bisector from pointX, pointY origin on [ab-cd] |
true
if the bisector exists (A B and C D are not collinear)Definition at line 692 of file qgsgeometryutils_base.cpp.
|
static |
Returns true
if an angle is between angle1 and angle3 on a circle described by angle1, angle2 and angle3.
Definition at line 166 of file qgsgeometryutils_base.cpp.
|
static |
Averages two angles, correctly handling negative angles and ensuring the result is between 0 and 2 pi.
a1 | first angle (in radians) |
a2 | second angle (in radians) |
Definition at line 409 of file qgsgeometryutils_base.cpp.
|
static |
Calculates the average angle (in radians) between the two linear segments from (x1, y1) to (x2, y2) and (x2, y2) to (x3, y3).
Definition at line 401 of file qgsgeometryutils_base.cpp.
|
static |
Calculates Cartesian azimuth between points (x1, y1) and (x2, y2) (clockwise in degree, starting from north)
x1 | x-coordinate of the start point |
y1 | y-coordinate of the start point |
x2 | x-coordinate of the end point |
y2 | y-coordinate of the end point |
Definition at line 685 of file qgsgeometryutils_base.cpp.
|
static |
Returns the point (pointX, pointY) forming the bisector from point (aX, aY) to the segment (bX, bY) (cX, cY).
The bisector segment of ABC is (A-point)
aX | x-coordinate of first vertex in triangle |
aY | y-coordinate of first vertex in triangle |
bX | x-coordinate of second vertex in triangle |
bY | y-coordinate of second vertex in triangle |
cX | x-coordinate of third vertex in triangle |
cY | y-coordinate of third vertex in triangle |
pointX | x-coordinate of generated point |
pointY | y-coordinate of generated point |
true
if the bisector exists (A B and C are not collinear)Definition at line 728 of file qgsgeometryutils_base.cpp.
|
static |
Returns the counter clockwise angle between a line with components dx, dy and the line with dx > 0 and dy = 0.
Definition at line 114 of file qgsgeometryutils_base.cpp.
|
static |
Returns true
if, in a circle, angle is between angle1 and angle2.
Definition at line 140 of file qgsgeometryutils_base.cpp.
|
static |
Returns radius and center of the circle through (x1 y1), (x2 y2), (x3 y3)
Definition at line 172 of file qgsgeometryutils_base.cpp.
|
static |
Returns true
if the circle defined by three angles is ordered clockwise.
The angles are defined counter-clockwise from the origin, i.e. using Euclidean angles as opposed to geographic "North up" angles.
Definition at line 128 of file qgsgeometryutils_base.cpp.
|
static |
Length of a circular string segment defined by pt1, pt2, pt3.
Definition at line 210 of file qgsgeometryutils_base.cpp.
|
static |
Returns a number representing the closest side of a rectangle defined by /a right, bottom, left, top to the point at (x, y), where the point may be in the interior of the rectangle or outside it.
The returned value may be:
Definition at line 288 of file qgsgeometryutils_base.cpp.
|
inlinestatic |
Returns the 2D distance between (x1, y1) and (x2, y2).
Definition at line 58 of file qgsgeometryutils_base.h.
|
inlinestatic |
Returns the 3D distance between (x1, y1), (x2, y2) and (z2, z2).
Definition at line 48 of file qgsgeometryutils_base.h.
|
inlinestaticnoexcept |
Compare equality between multiple pairs of values with a specified epsilon.
Traditionally, the comparison is done by examining the specific values (such as x and y) that define the location of points. It focuses on the numerical differences or relationships between these values. On the other hand, comparing distances between points considers the actual spatial separation or length between the points, regardless of their coordinate values. This comparison involves measuring the distance between two points using formulas like the distance formula. Here, it's the "distance comparison" (fuzzyDistanceEqual).
T | Floating-point type (double or float) for the values to be compared. |
Args | Type of arguments for the values to be compared. |
epsilon | The range within which the differences are checked. |
args | Variadic list of values to be compared in pairs. The number of arguments must be greater than or equal to 4. It must follow the pattern: x1, y1, x2, y2, or x1, y1, z1, x2, y2, z2, ... |
Definition at line 542 of file qgsgeometryutils_base.h.
|
inlinestaticnoexcept |
Performs fuzzy comparison between pairs of values within a specified epsilon.
This function compares a variable number of pairs of values to check if their differences fall within a specified epsilon range using qgsNumberNear. It returns true if all the differences are within the given epsilon range; otherwise, it returns false.
T | Floating-point type (double or float) for the values to be compared. |
Args | Type of arguments for the values to be compared. |
epsilon | The range within which the differences are checked. |
args | Variadic list of values to be compared in pairs. The number of arguments must be greater than 0 and even. It must follow the pattern: x1, y1, x2, y2, or x1, y1, z1, x2, y2, z2, ... |
Definition at line 506 of file qgsgeometryutils_base.h.
|
static |
Interpolate a value at given angle on circular arc given values (zm1, zm2, zm3) at three different angles (a1, a2, a3).
Definition at line 254 of file qgsgeometryutils_base.cpp.
|
static |
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> (x2, y2).
A positive return value indicates the point is to the right of the line.
If the return value is 0, then the test was unsuccessful (e.g. due to testing a point exactly on the line, or exactly in line with the segment) and the result is undefined.
Definition at line 59 of file qgsgeometryutils_base.cpp.
|
static |
Calculates the direction of line joining two points in radians, clockwise from the north direction.
x1 | x-coordinate of line start |
y1 | y-coordinate of line start |
x2 | x-coordinate of line end |
y2 | y-coordinate of line end |
Definition at line 380 of file qgsgeometryutils_base.cpp.
|
static |
Computes the intersection between two lines.
Z dimension is supported and is retrieved from the first 3D point amongst p1 and p2.
p1x | x-coordinate of point on the first line |
p1y | y-coordinate of point on the first line |
v1 | Direction vector of the first line |
p2x | x-coordinate of second point on the first line |
p2y | y-coordinate of second point on the first line |
v2 | Direction vector of the second line |
intersectionX | x-coordinate of the intersection point |
intersectionY | y-coordinate of the intersection point |
Definition at line 490 of file qgsgeometryutils_base.cpp.
|
static |
Calculates the perpendicular angle to a line joining two points.
Returned angle is in radians, clockwise from the north direction.
x1 | x-coordinate of line start |
y1 | y-coordinate of line start |
x2 | x-coordinate of line end |
y2 | y-coordinate of line end |
Definition at line 394 of file qgsgeometryutils_base.cpp.
|
static |
An algorithm to calculate an (approximate) intersection of two lines in 3D.
La1 | is the first point on the first line, |
La2 | is the second point on the first line, |
Lb1 | is the first point on the second line, |
Lb2 | is the second point on the second line, |
intersection | is the result intersection, of it can be found. |
true
if the intersection can be found, false
- otherwise.Definition at line 576 of file qgsgeometryutils_base.cpp.
|
static |
Ensures that an angle is in the range 0 <= angle < 2 pi.
angle | angle in radians |
Definition at line 273 of file qgsgeometryutils_base.cpp.
|
static |
Create a perpendicular line segment to a given segment [segmentPoint1,segmentPoint2] with its center at centerPoint.
May be used to split geometries. Unless segmentLength is specified the new centered perpendicular line segment will have double the length of the input segment.
The result is a line (segment) centered in point p and perpendicular to segment [segmentPoint1, segmentPoint2].
centerPointX | x-coordinate of the point where the center of the perpendicular should be located |
centerPointY | y-coordinate of the point where the center of the perpendicular should be located |
segmentPoint1x | x-coordinate of segmentPoint1, the segment's start point |
segmentPoint1y | y-coordinate of segmentPoint1, the segment's start point |
segmentPoint2x | x-coordinate of segmentPoint2, the segment's end point |
segmentPoint2y | y-coordinate of segmentPoint2, the segment's end point |
perpendicularSegmentPoint1x | x-coordinate of the perpendicularCenterSegment's start point |
perpendicularSegmentPoint1y | y-coordinate of the perpendicularCenterSegment's start point |
perpendicularSegmentPoint2x | x-coordinate of the perpendicularCenterSegment's end point |
perpendicularSegmentPoint2y | y-coordinate of the perpendicularCenterSegment's end point |
segmentLength | (optional) Trims to given length. A segmentLength value of 0 refers to the default length which is double the length of the input segment. Set to 1 for a normalized length. |
Definition at line 365 of file qgsgeometryutils_base.cpp.
|
static |
Calculates a point a certain proportion of the way along the segment from (x1, y1) to (x2, y2), offset from the segment by the specified offset amount.
x1 | x-coordinate of start of segment |
y1 | y-coordinate of start of segment |
x2 | x-coordinate of end of segment |
y2 | y-coordinate of end of segment |
proportion | proportion of the segment's length at which to place the point (between 0.0 and 1.0) |
offset | perpendicular offset from segment to apply to point. A negative offset shifts the point to the left of the segment, while a positive offset will shift it to the right of the segment. |
x | calculated point x-coordinate |
y | calculated point y-coordinate |
Definition at line 97 of file qgsgeometryutils_base.cpp.
|
static |
Given the line (x1, y1) to (x2, y2) and a point (px, py) returns the fraction of the line length at which the point lies.
Definition at line 650 of file qgsgeometryutils_base.cpp.
|
static |
Calculates the point a specified distance from (x1, y1) toward a second point (x2, y2).
Optionally, interpolated z and m values can be obtained by specifying the z1, z2 and z arguments and/or the m1, m2, m arguments.
Definition at line 70 of file qgsgeometryutils_base.cpp.
|
static |
Given the points (x1, y1), (x2, y2) and (x3, y3) returns true
if these points can be considered collinear with a specified tolerance epsilon.
Definition at line 680 of file qgsgeometryutils_base.cpp.
|
static |
Returns coordinates of a point which corresponds to this point projected by a specified distance with specified angles (azimuth and inclination), using Cartesian mathematics.
M value is preserved. resultX, resultY, resultZ are coordinates of the point projected. If a 2D point is projected a 3D point will be returned except if inclination is 90. A 3D point is always returned if a 3D point is projected.
aX | x-coordinate of the point to project |
aY | y-coordinate of the point to project |
aZ | z-coordinate of the point to project |
distance | distance to project |
azimuth | angle to project in X Y, clockwise in degrees starting from north |
inclination | angle to project in Z (3D). If the point is 2D, the Z value is assumed to be 0. |
resultX | Output parameter, x-coordinates of the point projected. |
resultY | Output parameter, y-coordinates of the point projected. |
resultZ | Output parameter, z-coordinates of the point projected. |
Definition at line 703 of file qgsgeometryutils_base.cpp.
|
static |
Compute the intersection between two segments.
p1x | x-coordinate of the first segment start point |
p1y | y-coordinate of the first segment start point |
p2x | x-coordinate of the first segment end point |
p2y | y-coordinate of the first segment end point |
q1x | x-coordinate of the second segment start point |
q1y | y-coordinate of the second segment start point |
q2x | x-coordinate of the second segment end point |
q2y | y-coordinate of the second segment end point |
intersectionPointX | Output parameter, x-coordinate of the intersection point |
intersectionPointY | Output parameter, y-coordinate of the intersection point |
isIntersection | Output parameter, return true if an intersection is found |
tolerance | The tolerance to use |
acceptImproperIntersection | By default, this method returns true only if segments have proper intersection. If set true, returns also TRUE if segments have improper intersection (end of one segment on other segment ; continuous segments). |
Definition at line 512 of file qgsgeometryutils_base.cpp.
|
static |
An algorithm to calculate the shortest distance between two skew lines.
P1 | is the first point of the first line, |
P12 | is the second point on the first line, |
P2 | is the first point on the second line, |
P22 | is the second point on the second line. |
Definition at line 436 of file qgsgeometryutils_base.cpp.
|
static |
A method to project one skew line onto another.
P1 | is a first point that belonds to first skew line, |
P12 | is the second point that belongs to first skew line, |
P2 | is the first point that belongs to second skew line, |
P22 | is the second point that belongs to second skew line, |
X1 | is the result projection point of line P2P22 onto line P1P12, |
epsilon | the tolerance to use. |
true
if such point exists, false
- otherwise. Definition at line 448 of file qgsgeometryutils_base.cpp.
|
inlinestatic |
Returns the squared 2D distance between (x1, y1) and (x2, y2).
Definition at line 53 of file qgsgeometryutils_base.h.
|
inlinestatic |
Returns the squared 3D distance between (x1, y1), (x2, y2) and (z2, z2).
Definition at line 40 of file qgsgeometryutils_base.h.
|
static |
Returns the squared distance between a point and a line.
Definition at line 20 of file qgsgeometryutils_base.cpp.
|
static |
Calculates angle of a circular string part defined by pt1, pt2, pt3.
Definition at line 224 of file qgsgeometryutils_base.cpp.
|
static |
Returns the area of the triangle denoted by the points (aX, aY), (bX, bY) and (cX, cY).
Definition at line 645 of file qgsgeometryutils_base.cpp.
|
static |
Returns a weighted point inside the triangle denoted by the points (aX, aY), (bX, bY) and (cX, cY).
aX | x-coordinate of first vertex in triangle |
aY | y-coordinate of first vertex in triangle |
bX | x-coordinate of second vertex in triangle |
bY | y-coordinate of second vertex in triangle |
cX | x-coordinate of third vertex in triangle |
cY | y-coordinate of third vertex in triangle |
weightB | weighting factor along axis A-B (between 0 and 1) |
weightC | weighting factor along axis A-C (between 0 and 1) |
pointX | x-coordinate of generated point |
pointY | y-coordinate of generated point |
Definition at line 661 of file qgsgeometryutils_base.cpp.