Skip to content

Commit

Permalink
[API] Add angleBisector method
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Dec 6, 2020
1 parent b0f5f09 commit fe80965
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/core/auto_generated/geometry/qgsgeometryutils.sip.in
Expand Up @@ -700,6 +700,31 @@ A Z dimension is added to ``point`` if one of the point in the list
.. versionadded:: 3.0
%End


static bool angleBisector( double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY,
double &pointX /Out/, double &pointY /Out/, double &angle /Out/ ) /HoldGIL/;
%Docstring
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``)

:param aX: x-coordinate of first vertex of the segment ab
:param aY: y-coordinate of first vertex of the segment ab
:param bX: x-coordinate of second vertex of the segment ab
:param bY: y-coordinate of second vertex of the segment ab
:param cX: x-coordinate of first vertex of the segment cd
:param cY: y-coordinate of first vertex of the segment cd
:param dX: x-coordinate of second vertex of the segment cd
:param dY: y-coordinate of second vertex of the segment cd

:return: - ``True`` if the bisector exists (A B and C D are not collinear)
- pointX: x-coordinate of generated point
- pointY: y-coordinate of generated point
- angle: angle of the bisector from pointX, pointY origin on [ab-cd]

.. versionadded:: 3.18
%End

static bool bisector( double aX, double aY, double bX, double bY, double cX, double cY,
double &pointX /Out/, double &pointY /Out/ ) /HoldGIL/;
%Docstring
Expand Down
19 changes: 19 additions & 0 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -1718,6 +1718,25 @@ bool QgsGeometryUtils::setZValueFromPoints( const QgsPointSequence &points, QgsP
return rc;
}

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

QgsPoint pOut;
bool intersection = false;
QgsGeometryUtils::segmentIntersection( pA, pB, pC, pD, pOut, intersection );

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

return intersection;
}

bool QgsGeometryUtils::bisector( double aX, double aY, double bX, double bY, double cX, double cY,
double &pointX SIP_OUT, double &pointY SIP_OUT )
{
Expand Down
24 changes: 24 additions & 0 deletions src/core/geometry/qgsgeometryutils.h
Expand Up @@ -727,6 +727,30 @@ class CORE_EXPORT QgsGeometryUtils
*/
static bool setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point );

/**
* Returns the point (\a pointX, \a pointY) forming the bisector from segment (\a aX \a aY) (\a bX \a bY)
* and segment (\a bX, \a bY) (\a dX, \a dY).
* The bisector segment of AB-CD is (point, projection of point by \a angle)
*
* \param aX x-coordinate of first vertex of the segment ab
* \param aY y-coordinate of first vertex of the segment ab
* \param bX x-coordinate of second vertex of the segment ab
* \param bY y-coordinate of second vertex of the segment ab
* \param cX x-coordinate of first vertex of the segment cd
* \param cY y-coordinate of first vertex of the segment cd
* \param dX x-coordinate of second vertex of the segment cd
* \param dY y-coordinate of second vertex of the segment cd
* \param pointX x-coordinate of generated point
* \param pointY y-coordinate of generated point
* \param angle angle 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
*/

static bool angleBisector( double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY,
double &pointX SIP_OUT, double &pointY SIP_OUT, double &angle SIP_OUT ) SIP_HOLDGIL;

/**
* 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)
Expand Down

0 comments on commit fe80965

Please sign in to comment.