QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
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 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 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 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, 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 30 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 387 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 692 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 166 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 409 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 401 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 685 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 728 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 114 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 140 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 172 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 128 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 210 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 288 of file qgsgeometryutils_base.cpp.

◆ distance2D()

static 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 58 of file qgsgeometryutils_base.h.

◆ distance3D()

static 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 48 of file qgsgeometryutils_base.h.

◆ fuzzyDistanceEqual()

template<typename T , typename... Args>
static bool QgsGeometryUtilsBase::fuzzyDistanceEqual ( 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 542 of file qgsgeometryutils_base.h.

◆ fuzzyEqual()

template<typename T , typename... Args>
static bool QgsGeometryUtilsBase::fuzzyEqual ( 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 506 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 254 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 59 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 380 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 490 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 394 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.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31

Definition at line 576 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 273 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 365 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 97 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 650 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 70 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 680 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 703 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 512 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 436 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 448 of file qgsgeometryutils_base.cpp.

◆ sqrDistance2D()

static 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 53 of file qgsgeometryutils_base.h.

◆ sqrDistance3D()

static 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 40 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 20 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 224 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 645 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 661 of file qgsgeometryutils_base.cpp.


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