QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
QgsGeometryUtilsBase Class Reference

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 calculateArcLength (double centerX, double centerY, double radius, double x1, double y1, double x2, double y2, double x3, double y3, int fromVertex, int toVertex)
 Calculates the precise arc length between two vertices on a circular arc.
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 &centerX, double &centerY)
 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 bool createChamfer (const double segment1StartX, const double segment1StartY, const double segment1EndX, const double segment1EndY, const double segment2StartX, const double segment2StartY, const double segment2EndX, const double segment2EndY, const double distance1, const double distance2, double &chamferStartX, double &chamferStartY, double &chamferEndX, double &chamferEndY, double *trim1StartX=nullptr, double *trim1StartY=nullptr, double *trim1EndX=nullptr, double *trim1EndY=nullptr, double *trim2StartX=nullptr, double *trim2StartY=nullptr, double *trim2EndX=nullptr, double *trim2EndY=nullptr, const double epsilon=1e-8)
 Creates a chamfer (angled corner) between two line segments.
static bool createFillet (const double segment1StartX, const double segment1StartY, const double segment1EndX, const double segment1EndY, const double segment2StartX, const double segment2StartY, const double segment2EndX, const double segment2EndY, const double radius, double *filletPointsX, double *filletPointsY, double *trim1StartX=nullptr, double *trim1StartY=nullptr, double *trim1EndX=nullptr, double *trim1EndY=nullptr, double *trim2StartX=nullptr, double *trim2StartY=nullptr, double *trim2EndX=nullptr, double *trim2EndY=nullptr, const double epsilon=1e-8)
 Creates a fillet (rounded corner) between two line segments.
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, z1) and (x2, y2, 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 maxFilletRadius (const double segment1StartX, const double segment1StartY, const double segment1EndX, const double segment1EndY, const double segment2StartX, const double segment2StartY, const double segment2EndX, const double segment2EndY, double epsilon=1e-8)
 Calculates the maximum allowed fillet radius for the given segment configuration.
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 points3DAreCollinear (double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double epsilon)
 Given the points (x1, y1, z1), (x2, y2, z2) and (x3, y3, z3) returns true if these points can be considered collinear with a specified tolerance epsilon.
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, z1) and (x2, y2, 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).

Detailed Description

Convenience functions for geometry utils.

Since
QGIS 3.34

Definition at line 31 of file qgsgeometryutils_base.h.

Member Function Documentation

◆ angleBetweenThreePoints()

double QgsGeometryUtilsBase::angleBetweenThreePoints ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3 )
static

Calculates the angle between the lines AB and BC, where AB and BC described by points a, b and b, c.

Parameters
x1x-coordinate of point a
y1y-coordinate of point a
x2x-coordinate of point b
y2y-coordinate of point b
x3x-coordinate of point c
y3y-coordinate of point c
Returns
angle between lines in radians. Returned value is undefined if two or more points are equal.

Definition at line 457 of file qgsgeometryutils_base.cpp.

◆ angleBisector()

bool QgsGeometryUtilsBase::angleBisector ( double aX,
double aY,
double bX,
double bY,
double cX,
double cY,
double dX,
double dY,
double & pointX,
double & pointY,
double & angle )
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)

Parameters
aXx-coordinate of first vertex of the segment ab
aYy-coordinate of first vertex of the segment ab
bXx-coordinate of second vertex of the segment ab
bYy-coordinate of second vertex of the segment ab
cXx-coordinate of first vertex of the segment cd
cYy-coordinate of first vertex of the segment cd
dXx-coordinate of second vertex of the segment cd
dYy-coordinate of second vertex of the segment cd
pointXx-coordinate of generated point
pointYy-coordinate of generated point
angleangle of the bisector from pointX, pointY origin on [ab-cd]
Returns
true if the bisector exists (A B and C D are not collinear)
Since
QGIS 3.18

Definition at line 773 of file qgsgeometryutils_base.cpp.

◆ angleOnCircle()

bool QgsGeometryUtilsBase::angleOnCircle ( double angle,
double angle1,
double angle2,
double angle3 )
static

Returns true if an angle is between angle1 and angle3 on a circle described by angle1, angle2 and angle3.

Definition at line 168 of file qgsgeometryutils_base.cpp.

◆ averageAngle() [1/2]

double QgsGeometryUtilsBase::averageAngle ( double a1,
double a2 )
static

Averages two angles, correctly handling negative angles and ensuring the result is between 0 and 2 pi.

Parameters
a1first angle (in radians)
a2second angle (in radians)
Returns
average angle (in radians)

Definition at line 479 of file qgsgeometryutils_base.cpp.

◆ averageAngle() [2/2]

double QgsGeometryUtilsBase::averageAngle ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3 )
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 471 of file qgsgeometryutils_base.cpp.

◆ azimuth()

double QgsGeometryUtilsBase::azimuth ( double x1,
double y1,
double x2,
double y2 )
static

Calculates Cartesian azimuth between points (x1, y1) and (x2, y2) (clockwise in degree, starting from north).

Parameters
x1x-coordinate of the start point
y1y-coordinate of the start point
x2x-coordinate of the end point
y2y-coordinate of the end point
Since
QGIS 3.34

Definition at line 766 of file qgsgeometryutils_base.cpp.

◆ bisector()

bool QgsGeometryUtilsBase::bisector ( double aX,
double aY,
double bX,
double bY,
double cX,
double cY,
double & pointX,
double & pointY )
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)

Parameters
aXx-coordinate of first vertex in triangle
aYy-coordinate of first vertex in triangle
bXx-coordinate of second vertex in triangle
bYy-coordinate of second vertex in triangle
cXx-coordinate of third vertex in triangle
cYy-coordinate of third vertex in triangle
pointXx-coordinate of generated point
pointYy-coordinate of generated point
Returns
true if the bisector exists (A B and C are not collinear)
Since
QGIS 3.18

Definition at line 809 of file qgsgeometryutils_base.cpp.

◆ calculateArcLength()

double QgsGeometryUtilsBase::calculateArcLength ( double centerX,
double centerY,
double radius,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
int fromVertex,
int toVertex )
static

Calculates the precise arc length between two vertices on a circular arc.

This method calculates the exact distance along the arc between any two vertices on a circle defined by three points. The arc follows the geometric path of the circle.

Parameters
centerXX coordinate of the circle center
centerYY coordinate of the circle center
radiusradius of the circle
x1X coordinate of the first point defining the arc
y1Y coordinate of the first point defining the arc
x2X coordinate of the second point defining the arc
y2Y coordinate of the second point defining the arc
x3X coordinate of the third point defining the arc
y3Y coordinate of the third point defining the arc
fromVertexvertex index to start from (0, 1, or 2)
toVertexvertex index to end at (0, 1, or 2)
Returns
precise arc length between the vertices, or 0 if vertices are the same
Since
QGIS 4.00

Definition at line 226 of file qgsgeometryutils_base.cpp.

◆ ccwAngle()

double QgsGeometryUtilsBase::ccwAngle ( double dy,
double dx )
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 116 of file qgsgeometryutils_base.cpp.

◆ circleAngleBetween()

bool QgsGeometryUtilsBase::circleAngleBetween ( double angle,
double angle1,
double angle2,
bool clockwise )
static

Returns true if, in a circle, angle is between angle1 and angle2.

Definition at line 142 of file qgsgeometryutils_base.cpp.

◆ circleCenterRadius()

void QgsGeometryUtilsBase::circleCenterRadius ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double & radius,
double & centerX,
double & centerY )
static

Returns radius and center of the circle through (x1 y1), (x2 y2), (x3 y3).

Definition at line 174 of file qgsgeometryutils_base.cpp.

◆ circleClockwise()

bool QgsGeometryUtilsBase::circleClockwise ( double angle1,
double angle2,
double angle3 )
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 130 of file qgsgeometryutils_base.cpp.

◆ circleLength()

double QgsGeometryUtilsBase::circleLength ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3 )
static

Length of a circular string segment defined by pt1, pt2, pt3.

Definition at line 212 of file qgsgeometryutils_base.cpp.

◆ closestSideOfRectangle()

int QgsGeometryUtilsBase::closestSideOfRectangle ( double right,
double bottom,
double left,
double top,
double x,
double y )
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:

  1. Point is closest to top side of rectangle
  2. Point is located on the top-right diagonal of rectangle, equally close to the top and right sides
  3. Point is closest to right side of rectangle
  4. Point is located on the bottom-right diagonal of rectangle, equally close to the bottom and right sides
  5. Point is closest to bottom side of rectangle
  6. Point is located on the bottom-left diagonal of rectangle, equally close to the bottom and left sides
  7. Point is closest to left side of rectangle
  8. Point is located on the top-left diagonal of rectangle, equally close to the top and left sides
Note
This method effectively partitions the space outside of the rectangle into Voronoi cells, so a point to the top left of the rectangle may be assigned to the left or top sides based on its position relative to the diagonal line extended from the rectangle's top-left corner.
Since
QGIS 3.20

Definition at line 358 of file qgsgeometryutils_base.cpp.

◆ createChamfer()

bool QgsGeometryUtilsBase::createChamfer ( const double segment1StartX,
const double segment1StartY,
const double segment1EndX,
const double segment1EndY,
const double segment2StartX,
const double segment2StartY,
const double segment2EndX,
const double segment2EndY,
const double distance1,
const double distance2,
double & chamferStartX,
double & chamferStartY,
double & chamferEndX,
double & chamferEndY,
double * trim1StartX = nullptr,
double * trim1StartY = nullptr,
double * trim1EndX = nullptr,
double * trim1EndY = nullptr,
double * trim2StartX = nullptr,
double * trim2StartY = nullptr,
double * trim2EndX = nullptr,
double * trim2EndY = nullptr,
const double epsilon = 1e-8 )
static

Creates a chamfer (angled corner) between two line segments.

This method generates a straight-line chamfer connecting two line segments at their intersection point. The chamfer distances can be specified independently for each segment, allowing for both symmetric and asymmetric chamfers.

Parameters
segment1StartXx-coordinate of first segment start point
segment1StartYy-coordinate of first segment start point
segment1EndXx-coordinate of first segment end point
segment1EndYy-coordinate of first segment end point
segment2StartXx-coordinate of second segment start point
segment2StartYy-coordinate of second segment start point
segment2EndXx-coordinate of second segment end point
segment2EndYy-coordinate of second segment end point
distance1chamfer distance along first segment
distance2chamfer distance along second segment (if < 0, uses distance1)
chamferStartXoutput x-coordinate of chamfer start point
chamferStartYoutput y-coordinate of chamfer start point
chamferEndXoutput x-coordinate of chamfer end point
chamferEndYoutput y-coordinate of chamfer end point
trim1StartXoptional output x-coordinate of trimmed first segment start
trim1StartYoptional output y-coordinate of trimmed first segment start
trim1EndXoptional output x-coordinate of trimmed first segment end
trim1EndYoptional output y-coordinate of trimmed first segment end
trim2StartXoptional output x-coordinate of trimmed second segment start
trim2StartYoptional output y-coordinate of trimmed second segment start
trim2EndXoptional output x-coordinate of trimmed second segment end
trim2EndYoptional output y-coordinate of trimmed second segment end
epsilontolerance for numerical comparisons and intersection detection
Returns
true if chamfer was successfully created
Note
Not available in Python bindings
Since
QGIS 4.0

Definition at line 1074 of file qgsgeometryutils_base.cpp.

◆ createFillet()

bool QgsGeometryUtilsBase::createFillet ( const double segment1StartX,
const double segment1StartY,
const double segment1EndX,
const double segment1EndY,
const double segment2StartX,
const double segment2StartY,
const double segment2EndX,
const double segment2EndY,
const double radius,
double * filletPointsX,
double * filletPointsY,
double * trim1StartX = nullptr,
double * trim1StartY = nullptr,
double * trim1EndX = nullptr,
double * trim1EndY = nullptr,
double * trim2StartX = nullptr,
double * trim2StartY = nullptr,
double * trim2EndX = nullptr,
double * trim2EndY = nullptr,
const double epsilon = 1e-8 )
static

Creates a fillet (rounded corner) between two line segments.

This method generates a circular arc connecting two line segments at their intersection point. The fillet returns exactly 3 points defining a CircularString: start point, middle point, and end point of the arc.

Parameters
segment1StartXx-coordinate of first segment start point
segment1StartYy-coordinate of first segment start point
segment1EndXx-coordinate of first segment end point
segment1EndYy-coordinate of first segment end point
segment2StartXx-coordinate of second segment start point
segment2StartYy-coordinate of second segment start point
segment2EndXx-coordinate of second segment end point
segment2EndYy-coordinate of second segment end point
radiusradius of the fillet arc
filletPointsXoutput array of x-coordinates for 3 fillet points (start, middle, end)
filletPointsYoutput array of y-coordinates for 3 fillet points (start, middle, end)
trim1StartXoptional output x-coordinate of trimmed first segment start
trim1StartYoptional output y-coordinate of trimmed first segment start
trim1EndXoptional output x-coordinate of trimmed first segment end
trim1EndYoptional output y-coordinate of trimmed first segment end
trim2StartXoptional output x-coordinate of trimmed second segment start
trim2StartYoptional output y-coordinate of trimmed second segment start
trim2EndXoptional output x-coordinate of trimmed second segment end
trim2EndYoptional output y-coordinate of trimmed second segment end
epsilontolerance for numerical comparisons and intersection detection
Returns
true if fillet was successfully created
Note
The caller must ensure that filletPointsX and filletPointsY arrays are large enough to hold exactly 3 points defining the CircularString arc.
Not available in Python bindings
Since
QGIS 4.0

Definition at line 906 of file qgsgeometryutils_base.cpp.

◆ distance2D()

double QgsGeometryUtilsBase::distance2D ( double x1,
double y1,
double x2,
double y2 )
inlinestatic

Returns the 2D distance between (x1, y1) and (x2, y2).

Definition at line 59 of file qgsgeometryutils_base.h.

◆ distance3D()

double QgsGeometryUtilsBase::distance3D ( double x1,
double y1,
double z1,
double x2,
double y2,
double z2 )
inlinestatic

Returns the 3D distance between (x1, y1, z1) and (x2, y2, z2).

Warning
No check is done if z contains NaN value. This is the caller's responsibility.
Since
QGIS 3.36

Definition at line 49 of file qgsgeometryutils_base.h.

◆ fuzzyDistanceEqual()

template<typename T, typename... Args>
bool QgsGeometryUtilsBase::fuzzyDistanceEqual ( T epsilon,
const Args &... args )
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).

Template Parameters
TFloating-point type (double or float) for the values to be compared.
ArgsType of arguments for the values to be compared.
Parameters
epsilonThe range within which the differences are checked.
argsVariadic 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, ...
Returns
true if the squares of differences between pairs of values sum up to less than epsilon squared, false otherwise.
See also
fuzzyEqual
Since
QGIS 3.36

Definition at line 576 of file qgsgeometryutils_base.h.

◆ fuzzyEqual()

template<typename T, typename... Args>
bool QgsGeometryUtilsBase::fuzzyEqual ( T epsilon,
const Args &... args )
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.

Template Parameters
TFloating-point type (double or float) for the values to be compared.
ArgsType of arguments for the values to be compared.
Parameters
epsilonThe range within which the differences are checked.
argsVariadic 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, ...
Returns
true if all the differences between pairs of values are within epsilon, false otherwise.
See also
fuzzyDistanceEqual
Since
QGIS 3.36

Definition at line 540 of file qgsgeometryutils_base.h.

◆ interpolateArcValue()

double QgsGeometryUtilsBase::interpolateArcValue ( double angle,
double a1,
double a2,
double a3,
double zm1,
double zm2,
double zm3 )
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 324 of file qgsgeometryutils_base.cpp.

◆ leftOfLine()

int QgsGeometryUtilsBase::leftOfLine ( const double x,
const double y,
const double x1,
const double y1,
const double x2,
const double y2 )
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 61 of file qgsgeometryutils_base.cpp.

◆ lineAngle()

double QgsGeometryUtilsBase::lineAngle ( double x1,
double y1,
double x2,
double y2 )
static

Calculates the direction of line joining two points in radians, clockwise from the north direction.

Parameters
x1x-coordinate of line start
y1y-coordinate of line start
x2x-coordinate of line end
y2y-coordinate of line end
Returns
angle in radians. Returned value is undefined if start and end point are the same.

Definition at line 450 of file qgsgeometryutils_base.cpp.

◆ lineIntersection()

bool QgsGeometryUtilsBase::lineIntersection ( double p1x,
double p1y,
QgsVector v1,
double p2x,
double p2y,
QgsVector v2,
double & intersectionX,
double & intersectionY )
static

Computes the intersection between two lines.

Z dimension is supported and is retrieved from the first 3D point amongst p1 and p2.

Parameters
p1xx-coordinate of point on the first line
p1yy-coordinate of point on the first line
v1Direction vector of the first line
p2xx-coordinate of second point on the first line
p2yy-coordinate of second point on the first line
v2Direction vector of the second line
intersectionXx-coordinate of the intersection point
intersectionYy-coordinate of the intersection point
Returns
Whether the lines intersect

Definition at line 560 of file qgsgeometryutils_base.cpp.

◆ linePerpendicularAngle()

double QgsGeometryUtilsBase::linePerpendicularAngle ( double x1,
double y1,
double x2,
double y2 )
static

Calculates the perpendicular angle to a line joining two points.

Returned angle is in radians, clockwise from the north direction.

Parameters
x1x-coordinate of line start
y1y-coordinate of line start
x2x-coordinate of line end
y2y-coordinate of line end
Returns
angle in radians. Returned value is undefined if start and end point are the same.

Definition at line 464 of file qgsgeometryutils_base.cpp.

◆ linesIntersection3D()

bool QgsGeometryUtilsBase::linesIntersection3D ( const QgsVector3D & La1,
const QgsVector3D & La2,
const QgsVector3D & Lb1,
const QgsVector3D & Lb2,
QgsVector3D & intersection )
static

An algorithm to calculate an (approximate) intersection of two lines in 3D.

Parameters
La1is the first point on the first line,
La2is the second point on the first line,
Lb1is the first point on the second line,
Lb2is the second point on the second line,
intersectionis the result intersection, of it can be found.
Returns
true if the intersection can be found, false - otherwise.

Example

# (True, PyQt5.QtGui.QgsVector3D(2.0, 0.0, 0.0))
# (True, PyQt5.QtGui.QgsVector3D(2.0, 0.0, 0.0))
# (True, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
# (True, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
# (False, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
# (False, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
# (True, PyQt5.QtGui.QgsVector3D(3.0, 3.0, 0.0))
# (True, PyQt5.QtGui.QgsVector3D(3.0, 3.0, 0.0))
# (True, PyQt5.QtGui.QgsVector3D(2.5, 2.5, 2.5))
# (True, PyQt5.QtGui.QgsVector3D(2.5, 2.5, 2.5))
# (True, PyQt5.QtGui.QgsVector3D(0.0, 5.0, 5.0))
static Q_DECL_DEPRECATED 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.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:30

Definition at line 646 of file qgsgeometryutils_base.cpp.

◆ maxFilletRadius()

double QgsGeometryUtilsBase::maxFilletRadius ( const double segment1StartX,
const double segment1StartY,
const double segment1EndX,
const double segment1EndY,
const double segment2StartX,
const double segment2StartY,
const double segment2EndX,
const double segment2EndY,
double epsilon = 1e-8 )
static

Calculates the maximum allowed fillet radius for the given segment configuration.

Parameters
segment1StartXx-coordinate of first segment start point
segment1StartYy-coordinate of first segment start point
segment1EndXx-coordinate of first segment end point
segment1EndYy-coordinate of first segment end point
segment2StartXx-coordinate of second segment start point
segment2StartYy-coordinate of second segment start point
segment2EndXx-coordinate of second segment end point
segment2EndYy-coordinate of second segment end point
epsilontolerance for intersection and angle calculations
Returns
Maximum fillet radius that can be applied, or -1.0 if no fillet is possible
Since
QGIS 4.0

Definition at line 823 of file qgsgeometryutils_base.cpp.

◆ normalizedAngle()

double QgsGeometryUtilsBase::normalizedAngle ( double angle)
static

Ensures that an angle is in the range 0 <= angle < 2 pi.

Parameters
angleangle in radians
Returns
equivalent angle within the range [0, 2 pi)

Definition at line 343 of file qgsgeometryutils_base.cpp.

◆ perpendicularCenterSegment()

void QgsGeometryUtilsBase::perpendicularCenterSegment ( double centerPointX,
double centerPointY,
double segmentPoint1x,
double segmentPoint1y,
double segmentPoint2x,
double segmentPoint2y,
double & perpendicularSegmentPoint1x,
double & perpendicularSegmentPoint1y,
double & perpendicularSegmentPoint2x,
double & perpendicularSegmentPoint2y,
double segmentLength = 0 )
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].

Parameters
centerPointXx-coordinate of the point where the center of the perpendicular should be located
centerPointYy-coordinate of the point where the center of the perpendicular should be located
segmentPoint1xx-coordinate of segmentPoint1, the segment's start point
segmentPoint1yy-coordinate of segmentPoint1, the segment's start point
segmentPoint2xx-coordinate of segmentPoint2, the segment's end point
segmentPoint2yy-coordinate of segmentPoint2, the segment's end point
perpendicularSegmentPoint1xx-coordinate of the perpendicularCenterSegment's start point
perpendicularSegmentPoint1yy-coordinate of the perpendicularCenterSegment's start point
perpendicularSegmentPoint2xx-coordinate of the perpendicularCenterSegment's end point
perpendicularSegmentPoint2yy-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.
Since
QGIS 3.24

Definition at line 435 of file qgsgeometryutils_base.cpp.

◆ perpendicularOffsetPointAlongSegment()

void QgsGeometryUtilsBase::perpendicularOffsetPointAlongSegment ( double x1,
double y1,
double x2,
double y2,
double proportion,
double offset,
double * x,
double * y )
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.

Parameters
x1x-coordinate of start of segment
y1y-coordinate of start of segment
x2x-coordinate of end of segment
y2y-coordinate of end of segment
proportionproportion of the segment's length at which to place the point (between 0.0 and 1.0)
offsetperpendicular 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.
xcalculated point x-coordinate
ycalculated point y-coordinate

Example

# Offset point at center of segment by 2 units to the right
# (6.0, 3.0)
# Offset point at center of segment by 2 units to the left
# (6.0, 7.0)
static Q_DECL_DEPRECATED 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,...
Since
QGIS 3.20

Definition at line 99 of file qgsgeometryutils_base.cpp.

◆ pointFractionAlongLine()

double QgsGeometryUtilsBase::pointFractionAlongLine ( double x1,
double y1,
double x2,
double y2,
double px,
double py )
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.

Warning
this method requires that the point definitely lies on the line!
Since
QGIS 3.32

Definition at line 720 of file qgsgeometryutils_base.cpp.

◆ pointOnLineWithDistance()

void QgsGeometryUtilsBase::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 )
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.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 72 of file qgsgeometryutils_base.cpp.

◆ points3DAreCollinear()

bool QgsGeometryUtilsBase::points3DAreCollinear ( double x1,
double y1,
double z1,
double x2,
double y2,
double z2,
double x3,
double y3,
double z3,
double epsilon )
static

Given the points (x1, y1, z1), (x2, y2, z2) and (x3, y3, z3) returns true if these points can be considered collinear with a specified tolerance epsilon.

Since
QGIS 4.0

Definition at line 755 of file qgsgeometryutils_base.cpp.

◆ pointsAreCollinear()

bool QgsGeometryUtilsBase::pointsAreCollinear ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double epsilon )
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.

Since
QGIS 3.32

Definition at line 750 of file qgsgeometryutils_base.cpp.

◆ project()

void QgsGeometryUtilsBase::project ( double aX,
double aY,
double aZ,
double distance,
double azimuth,
double inclination,
double & resultX,
double & resultY,
double & resultZ )
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.

Parameters
aXx-coordinate of the point to project
aYy-coordinate of the point to project
aZz-coordinate of the point to project
distancedistance to project
azimuthangle to project in X Y, clockwise in degrees starting from north
inclinationangle to project in Z (3D). If the point is 2D, the Z value is assumed to be 0.
resultXOutput parameter, x-coordinates of the point projected.
resultYOutput parameter, y-coordinates of the point projected.
resultZOutput parameter, z-coordinates of the point projected.
Since
QGIS 3.34

Definition at line 784 of file qgsgeometryutils_base.cpp.

◆ segmentIntersection()

bool QgsGeometryUtilsBase::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 )
static

Compute the intersection between two segments.

Parameters
p1xx-coordinate of the first segment start point
p1yy-coordinate of the first segment start point
p2xx-coordinate of the first segment end point
p2yy-coordinate of the first segment end point
q1xx-coordinate of the second segment start point
q1yy-coordinate of the second segment start point
q2xx-coordinate of the second segment end point
q2yy-coordinate of the second segment end point
intersectionPointXOutput parameter, x-coordinate of the intersection point
intersectionPointYOutput parameter, y-coordinate of the intersection point
isIntersectionOutput parameter, return true if an intersection is found
toleranceThe tolerance to use
acceptImproperIntersectionBy 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).
Returns
Whether the segments intersect

Definition at line 582 of file qgsgeometryutils_base.cpp.

◆ skewLinesDistance()

double QgsGeometryUtilsBase::skewLinesDistance ( const QgsVector3D & P1,
const QgsVector3D & P12,
const QgsVector3D & P2,
const QgsVector3D & P22 )
static

An algorithm to calculate the shortest distance between two skew lines.

Parameters
P1is the first point of the first line,
P12is the second point on the first line,
P2is the first point on the second line,
P22is the second point on the second line.
Returns
the shortest distance

Definition at line 506 of file qgsgeometryutils_base.cpp.

◆ skewLinesProjection()

bool QgsGeometryUtilsBase::skewLinesProjection ( const QgsVector3D & P1,
const QgsVector3D & P12,
const QgsVector3D & P2,
const QgsVector3D & P22,
QgsVector3D & X1,
double epsilon = 0.0001 )
static

A method to project one skew line onto another.

Parameters
P1is a first point that belonds to first skew line,
P12is the second point that belongs to first skew line,
P2is the first point that belongs to second skew line,
P22is the second point that belongs to second skew line,
X1is the result projection point of line P2P22 onto line P1P12,
epsilonthe tolerance to use.
Returns
true if such point exists, false - otherwise.

Definition at line 518 of file qgsgeometryutils_base.cpp.

◆ sqrDistance2D()

double QgsGeometryUtilsBase::sqrDistance2D ( double x1,
double y1,
double x2,
double y2 )
inlinestatic

Returns the squared 2D distance between (x1, y1) and (x2, y2).

Definition at line 54 of file qgsgeometryutils_base.h.

◆ sqrDistance3D()

double QgsGeometryUtilsBase::sqrDistance3D ( double x1,
double y1,
double z1,
double x2,
double y2,
double z2 )
inlinestatic

Returns the squared 3D distance between (x1, y1, z1) and (x2, y2, z2).

Warning
No check is done if z contains NaN value. This is the caller's responsibility.
Since
QGIS 3.36

Definition at line 41 of file qgsgeometryutils_base.h.

◆ sqrDistToLine()

double QgsGeometryUtilsBase::sqrDistToLine ( double ptX,
double ptY,
double x1,
double y1,
double x2,
double y2,
double & minDistX,
double & minDistY,
double epsilon )
static

Returns the squared distance between a point and a line.

Definition at line 22 of file qgsgeometryutils_base.cpp.

◆ sweepAngle()

double QgsGeometryUtilsBase::sweepAngle ( double centerX,
double centerY,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 )
static

Calculates angle of a circular string part defined by pt1, pt2, pt3.

Definition at line 294 of file qgsgeometryutils_base.cpp.

◆ triangleArea()

double QgsGeometryUtilsBase::triangleArea ( double aX,
double aY,
double bX,
double bY,
double cX,
double cY )
static

Returns the area of the triangle denoted by the points (aX, aY), (bX, bY) and (cX, cY).

Since
QGIS 3.10

Definition at line 715 of file qgsgeometryutils_base.cpp.

◆ weightedPointInTriangle()

void QgsGeometryUtilsBase::weightedPointInTriangle ( double aX,
double aY,
double bX,
double bY,
double cX,
double cY,
double weightB,
double weightC,
double & pointX,
double & pointY )
static

Returns a weighted point inside the triangle denoted by the points (aX, aY), (bX, bY) and (cX, cY).

Parameters
aXx-coordinate of first vertex in triangle
aYy-coordinate of first vertex in triangle
bXx-coordinate of second vertex in triangle
bYy-coordinate of second vertex in triangle
cXx-coordinate of third vertex in triangle
cYy-coordinate of third vertex in triangle
weightBweighting factor along axis A-B (between 0 and 1)
weightCweighting factor along axis A-C (between 0 and 1)
pointXx-coordinate of generated point
pointYy-coordinate of generated point
Since
QGIS 3.10

Definition at line 731 of file qgsgeometryutils_base.cpp.


The documentation for this class was generated from the following files: