Skip to content

Commit

Permalink
[API] Add bisector method
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Nov 27, 2020
1 parent ce916ea commit 7a7d4c8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -1717,3 +1717,21 @@ bool QgsGeometryUtils::setZValueFromPoints( const QgsPointSequence &points, QgsP

return rc;
}

bool QgsGeometryUtils::bisector( double aX, double aY, double bX, double bY, double cX, double cY,
double &pointX SIP_OUT, double &pointY SIP_OUT )
{
const QgsPoint pA = QgsPoint( aX, aY );
const QgsPoint pB = QgsPoint( bX, bY );
const QgsPoint pC = QgsPoint( cX, cY );
const double angle = ( pA.azimuth( pB ) + pA.azimuth( pC ) ) / 2.0;

QgsPoint pOut;
bool intersection = false;
QgsGeometryUtils::segmentIntersection( pB, pC, pA, pA.project( 1.0, angle ), pOut, intersection );

pointX = pOut.x();
pointY = pOut.y();

return intersection;
}
19 changes: 19 additions & 0 deletions src/core/geometry/qgsgeometryutils.h
Expand Up @@ -727,6 +727,25 @@ class CORE_EXPORT QgsGeometryUtils
*/
static bool setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point );

/**
* Returns the point (\a pointX, \a pointY) forming the bisector from point (\a aX, \a aY) to the segment (\a bX, \a bY) (\a cX, \a cY).
* The bisector segment of ABC is (A-point)
*
* \param aX x-coordinate of first vertex in triangle
* \param aY y-coordinate of first vertex in triangle
* \param bX x-coordinate of second vertex in triangle
* \param bY y-coordinate of second vertex in triangle
* \param cX x-coordinate of third vertex in triangle
* \param cY y-coordinate of third vertex in triangle
* \param pointX x-coordinate of generated point
* \param pointY y-coordinate of generated point
* \returns TRUE if the bisector exists (A B and C are not collinear)
*
* \since QGIS 3.16
*/
static bool bisector( double aX, double aY, double bX, double bY, double cX, double cY,
double &pointX SIP_OUT, double &pointY SIP_OUT ) SIP_HOLDGIL;

//! \note not available in Python bindings
enum ComponentType SIP_SKIP
{
Expand Down

0 comments on commit 7a7d4c8

Please sign in to comment.