53 const double yDelta_a = pt2.
y() - pt1.
y();
54 const double xDelta_a = pt2.
x() - pt1.
x();
55 const double yDelta_b = pt3.
y() - pt2.
y();
56 const double xDelta_b = pt3.
x() - pt2.
x();
58 if ( ( std::fabs( xDelta_a ) <= epsilon ) && ( std::fabs( yDelta_b ) <= epsilon ) )
63 if ( std::fabs( yDelta_a ) <= epsilon )
67 else if ( std::fabs( yDelta_b ) <= epsilon )
71 else if ( std::fabs( xDelta_a ) <= epsilon )
75 else if ( std::fabs( xDelta_b ) <= epsilon )
88 if ( !isPerpendicular( pt1, pt2, pt3, epsilon ) )
94 else if ( !isPerpendicular( pt1, pt3, pt2, epsilon ) )
100 else if ( !isPerpendicular( pt2, pt1, pt3, epsilon ) )
106 else if ( !isPerpendicular( pt2, pt3, pt1, epsilon ) )
112 else if ( !isPerpendicular( pt3, pt2, pt1, epsilon ) )
118 else if ( !isPerpendicular( pt3, pt1, pt2, epsilon ) )
131 const double yDelta_a = p2.
y() - p1.
y();
132 const double xDelta_a = p2.
x() - p1.
x();
133 const double yDelta_b = p3.
y() - p2.
y();
134 const double xDelta_b = p3.
x() - p2.
x();
141 const double aSlope = yDelta_a / xDelta_a;
142 const double bSlope = yDelta_b / xDelta_b;
147 if ( ( std::fabs( xDelta_a ) <= epsilon ) && ( std::fabs( yDelta_b ) <= epsilon ) )
156 if ( std::fabs( aSlope - bSlope ) <= epsilon )
162 ( aSlope * bSlope * ( p1.
y() - p3.
y() ) +
163 bSlope * ( p1.
x() + p2.
x() ) -
164 aSlope * ( p2.
x() + p3.
x() ) ) /
165 ( 2.0 * ( bSlope - aSlope ) )
168 -1.0 * (
center.
x() - ( p1.
x() + p2.
x() ) / 2.0 ) /
169 aSlope + ( p1.
y() + p2.
y() ) / 2.0
198 QVector<QgsCircle> circles;
200 QgsPoint ptInter_par1line1, ptInter_par2line1;
201 double angle1, angle2;
203 QgsGeometryUtils::angleBisector( pt1_par1.
x(), pt1_par1.
y(), pt2_par1.
x(), pt2_par1.
y(), pt1_line1.
x(), pt1_line1.
y(), pt2_line1.
x(), pt2_line1.
y(), x, y, angle1 );
204 ptInter_par1line1.
setX( x );
205 ptInter_par1line1.
setY( y );
207 QgsGeometryUtils::angleBisector( pt1_par2.
x(), pt1_par2.
y(), pt2_par2.
x(), pt2_par2.
y(), pt1_line1.
x(), pt1_line1.
y(), pt2_line1.
x(), pt2_line1.
y(), x, y, angle2 );
208 ptInter_par2line1.
setX( x );
209 ptInter_par2line1.
setY( y );
219 circles.append(
QgsCircle( center, radius ) );
224 circles.append(
QgsCircle( center, radius ) );
235 circles.append(
QgsCircle( center, radius ) );
240 circles.append(
QgsCircle( center, radius ) );
245 if ( isInter && !circles.contains(
QgsCircle( center, radius ) ) )
251 circles.append(
QgsCircle( center, radius ) );
256 circles.append(
QgsCircle( center, radius ) );
260 if ( isInter && !circles.contains(
QgsCircle( center, radius ) ) )
266 circles.append(
QgsCircle( center, radius ) );
271 circles.append(
QgsCircle( center, radius ) );
281 bool isIntersect_tg1tg2 =
false;
282 bool isIntersect_tg1tg3 =
false;
283 bool isIntersect_tg2tg3 =
false;
288 QVector<QgsCircle> circles;
289 if ( !isIntersect_tg1tg2 && !isIntersect_tg2tg3 )
292 if ( !isIntersect_tg1tg2 )
293 return from2ParallelsLine( pt1_tg1, pt2_tg1, pt1_tg2, pt2_tg2, pt1_tg3, pt2_tg3, pos, epsilon );
294 else if ( !isIntersect_tg1tg3 )
295 return from2ParallelsLine( pt1_tg1, pt2_tg1, pt1_tg3, pt2_tg3, pt1_tg2, pt2_tg2, pos, epsilon );
296 else if ( !isIntersect_tg2tg3 )
297 return from2ParallelsLine( pt1_tg2, pt2_tg2, pt1_tg3, pt2_tg3, pt1_tg1, pt1_tg1, pos, epsilon );
314 circles.append(
QgsTriangle( p1, p2, p3 ).inscribedCircle() );
320 const QVector<QgsCircle> circles =
from3TangentsMulti( pt1_tg1, pt2_tg1, pt1_tg2, pt2_tg2, pt1_tg3, pt2_tg3, epsilon, pos );
321 if ( circles.length() != 1 )
323 return circles.at( 0 );
328 const double l1 = pt2.
distance( pt3 );
329 const double l2 = pt3.
distance( pt1 );
330 const double l3 = pt1.
distance( pt2 );
332 if ( ( l1 * l1 ) - ( l2 * l2 + l3 * l3 ) >= epsilon )
333 return QgsCircle().from2Points( pt2, pt3 );
334 else if ( ( l2 * l2 ) - ( l1 * l1 + l3 * l3 ) >= epsilon )
335 return QgsCircle().from2Points( pt3, pt1 );
336 else if ( ( l3 * l3 ) - ( l1 * l1 + l2 * l2 ) >= epsilon )
337 return QgsCircle().from2Points( pt1, pt2 );
339 return QgsCircle().from3Points( pt1, pt2, pt3, epsilon );
384 const double delta_x = std::fabs( pt1.
x() - pt2.
x() );
385 const double delta_y = std::fabs( pt1.
x() - pt2.
y() );
421 QVector<QgsPoint> quad;
434 QVector<QgsPoint> quad;
443 quad.append( quad.at( 0 ) );
444 for ( QVector<QgsPoint>::const_iterator it = quad.constBegin(); it != quad.constEnd(); ++it )
448 circString->setPoints(
points );
450 return circString.release();
467 rep = QStringLiteral(
"Empty" );
469 rep = QStringLiteral(
"Circle (Center: %1, Radius: %2, Azimuth: %3)" )
482 const QDomElement gml = circularString->asGml2( doc,
precision, ns, axisOrder );
491 QDomElement elemCircle = doc.createElementNS( ns, QStringLiteral(
"Circle" ) );
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
double perimeter() const override SIP_HOLDGIL
The circumference of the ellipse using first approximation of Ramanujan.
int intersections(const QgsCircle &other, QgsPoint &intersection1, QgsPoint &intersection2, bool useZ=false) const
Calculates the intersections points between this circle and an other circle.
double radius() const SIP_HOLDGIL
Returns the radius of the circle.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const
Returns a GML3 representation of the geometry.
int innerTangents(const QgsCircle &other, QgsPointXY &line1P1, QgsPointXY &line1P2, QgsPointXY &line2P1, QgsPointXY &line2P2) const
Calculates the inner tangent points between this circle and an other circle.
int outerTangents(const QgsCircle &other, QgsPointXY &line1P1, QgsPointXY &line1P2, QgsPointXY &line2P1, QgsPointXY &line2P2) const
Calculates the outer tangent points between this circle and an other circle.
static QgsCircle from3Points(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double epsilon=1E-8) SIP_HOLDGIL
Constructs a circle by 3 points on the circle.
void setSemiMinorAxis(double semiMinorAxis) override SIP_HOLDGIL
Inherited method.
QString toString(int pointPrecision=17, int radiusPrecision=17, int azimuthPrecision=2) const override
returns a string representation of the ellipse.
static QgsCircle fromCenterDiameter(const QgsPoint ¢er, double diameter, double azimuth=0) SIP_HOLDGIL
Constructs a circle by a center point and a diameter.
void setSemiMajorAxis(double semiMajorAxis) override SIP_HOLDGIL
Inherited method.
static QgsCircle from2Points(const QgsPoint &pt1, const QgsPoint &pt2) SIP_HOLDGIL
Constructs a circle by 2 points on the circle.
static QVector< QgsCircle > from3TangentsMulti(const QgsPoint &pt1_tg1, const QgsPoint &pt2_tg1, const QgsPoint &pt1_tg2, const QgsPoint &pt2_tg2, const QgsPoint &pt1_tg3, const QgsPoint &pt2_tg3, double epsilon=1E-8, const QgsPoint &pos=QgsPoint()) SIP_HOLDGIL
Returns an array of circle constructed by 3 tangents on the circle (aka inscribed circle of a triangl...
static QgsCircle fromCenterPoint(const QgsPoint ¢er, const QgsPoint &pt1) SIP_HOLDGIL
Constructs a circle by a center point and another point.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the ellipse.
bool contains(const QgsPoint &point, double epsilon=1E-8) const
Returns true if the circle contains the point.
static QgsCircle minimalCircleFrom3Points(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double epsilon=1E-8) SIP_HOLDGIL
Constructs the smallest circle from 3 points.
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const
Returns a GML2 representation of the geometry.
static QgsCircle fromExtent(const QgsPoint &pt1, const QgsPoint &pt2) SIP_HOLDGIL
Constructs a circle by an extent (aka bounding box / QgsRectangle).
QgsCircularString * toCircularString(bool oriented=false) const
Returns a circular string from the circle.
bool tangentToPoint(const QgsPointXY &p, QgsPointXY &pt1, QgsPointXY &pt2) const
Calculates the tangent points between this circle and the point p.
double area() const override SIP_HOLDGIL
The area of the ellipse.
static QgsCircle from3Tangents(const QgsPoint &pt1_tg1, const QgsPoint &pt2_tg1, const QgsPoint &pt1_tg2, const QgsPoint &pt2_tg2, const QgsPoint &pt1_tg3, const QgsPoint &pt2_tg3, double epsilon=1E-8, const QgsPoint &pos=QgsPoint()) SIP_HOLDGIL
Constructs a circle by 3 tangents on the circle (aka inscribed circle of a triangle).
QVector< QgsPoint > northQuadrant() const
The four quadrants of the ellipse.
Circular string geometry type.
QgsPoint center() const SIP_HOLDGIL
Returns the center point.
double semiMinorAxis() const SIP_HOLDGIL
Returns the semi-minor axis.
double azimuth() const SIP_HOLDGIL
Returns the azimuth.
virtual QgsPointSequence points(unsigned int segments=36) const
Returns a list of points with segmentation from segments.
virtual bool isEmpty() const SIP_HOLDGIL
An ellipse is empty if axes are equal to 0.
double semiMajorAxis() const SIP_HOLDGIL
Returns the semi-major axis.
virtual QVector< QgsPoint > quadrant() const
The four quadrants of the ellipse.
static QgsPoint midpoint(const QgsPoint &pt1, const QgsPoint &pt2) SIP_HOLDGIL
Returns a middle point between points pt1 and pt2.
static int circleCircleInnerTangents(const QgsPointXY ¢er1, double radius1, const QgsPointXY ¢er2, double radius2, QgsPointXY &line1P1, QgsPointXY &line1P2, QgsPointXY &line2P1, QgsPointXY &line2P2) SIP_HOLDGIL
Calculates the inner tangent points for two circles, centered at center1 and center2 and with radii o...
static bool segmentIntersection(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false) SIP_HOLDGIL
Compute the intersection between two segments.
static double lineAngle(double x1, double y1, double x2, double y2) SIP_HOLDGIL
Calculates the direction of line joining two points in radians, clockwise from the north direction.
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) SIP_HOLDGIL
Returns the point (pointX, pointY) forming the bisector from segment (aX aY) (bX bY) and segment (bX,...
static int circleCircleOuterTangents(const QgsPointXY ¢er1, double radius1, const QgsPointXY ¢er2, double radius2, QgsPointXY &line1P1, QgsPointXY &line1P2, QgsPointXY &line2P1, QgsPointXY &line2P2) SIP_HOLDGIL
Calculates the outer tangent points for two circles, centered at center1 and center2 and with radii o...
static QgsLineString perpendicularSegment(const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2) SIP_HOLDGIL
Create a perpendicular line segment from p to segment [s1, s2].
static int circleCircleIntersections(const QgsPointXY ¢er1, double radius1, const QgsPointXY ¢er2, double radius2, QgsPointXY &intersection1, QgsPointXY &intersection2) SIP_HOLDGIL
Calculates the intersections points between the circle with center center1 and radius radius1 and the...
static bool tangentPointAndCircle(const QgsPointXY ¢er, double radius, const QgsPointXY &p, QgsPointXY &pt1, QgsPointXY &pt2) SIP_HOLDGIL
Calculates the tangent points between the circle with the specified center and radius and the point p...
static bool transferFirstZOrMValueToPoint(Iterator verticesBegin, Iterator verticesEnd, QgsPoint &point)
A Z or M dimension is added to point if one of the points in the list points contains Z or M value.
static QDomElement pointsToGML3(const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY)
Returns a gml::posList DOM element.
static int leftOfLine(const double x, const double y, const double x1, const double y1, const double x2, const double y2) SIP_HOLDGIL
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> (x2, y2).
double length() const override SIP_HOLDGIL
Returns the planar, 2-dimensional length of the geometry.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
double distance(double x, double y) const SIP_HOLDGIL
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
void setX(double x) SIP_HOLDGIL
Sets the point's x-coordinate.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const SIP_HOLDGIL
Returns a new point which corresponds to this point projected by a specified distance with specified ...
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
void setY(double y) SIP_HOLDGIL
Sets the point's y-coordinate.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
A rectangle specified with double values.
static Type dropZ(Type type) SIP_HOLDGIL
Drops the z dimension (if present) for a WKB type and returns the new type.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QVector< QgsPoint > QgsPointSequence