Class: QgsTriangle¶
-
class
qgis.core.
QgsTriangle
¶ Bases:
qgis._core.QgsPolygon
QgsTriangle(p1: QgsPoint, p2: QgsPoint, p3: QgsPoint) Construct a QgsTriangle from three
QgsPointV2
.- Parameters
p1 – first point
p2 – second point
p3 – third point
QgsTriangle(p1: QgsPointXY, p2: QgsPointXY, p3: QgsPointXY) Construct a QgsTriangle from three
QgsPoint
.- Parameters
p1 – first point
p2 – second point
p3 – third point
QgsTriangle(p1: Union[QPointF, QPoint], p2: Union[QPointF, QPoint], p3: Union[QPointF, QPoint]) Construct a QgsTriangle from three QPointF.
- Parameters
p1 – first point
p2 – second point
p3 – third point
QgsTriangle(QgsTriangle)
Triangle geometry type.
New in version 3.0: Enums
Methods
Inherited method not used.
An altitude is a segment (defined by a
QgsLineString
) from a vertex to the opposite side (or, if necessary, to the extension of the opposite side).Returns the three angles of the triangle.
The segment (defined by a
QgsLineString
) returned bisect the angle of a vertex to the opposite side.Center of the circumscribed circle of the triangle.
Circumscribed circle of the triangle.
Radius of the circumscribed circle of the triangle.
Inherited method not used.
Center of the inscribed circle of the triangle.
Inscribed circle of the triangle.
Radius of the inscribed circle of the triangle.
Inherited method not used.
Convenient method checking if the geometry is degenerate (have duplicate or colinear point(s)).
Is the triangle equilateral (three sides with the same length)?
Is the triangle isocele (two sides with the same length)?
Is the triangle right-angled?
Is the triangle scalene (all sides have different lengths)?
Returns the three lengths of the triangle.
Medial (or midpoint) triangle of a triangle ABC is the triangle with vertices at the midpoints of the triangle’s sides.
A median is a segment (defined by a
QgsLineString
) from a vertex to the midpoint of the opposite side.An orthocenter is the point of intersection of the altitudes of a triangle.
Returns coordinates of a vertex.
Signals
Attributes
-
addInteriorRing
(self, ring: QgsCurve)¶ Inherited method not used. You cannot add an interior ring into a triangle.
-
altitudes
(self) → List[QgsLineString]¶ An altitude is a segment (defined by a
QgsLineString
) from a vertex to the opposite side (or, if necessary, to the extension of the opposite side).- Returns
Three altitudes from this triangle. An empty list is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) [alt.asWkt() for alt in tri.altitudes()] # ['LineString (0 0, 0 5)', 'LineString (0 5, 2.5 2.5)', 'LineString (5 5, 0 5)'] QgsTriangle().altitudes() # []
-
angles
(self) → List[float]¶ Returns the three angles of the triangle.
- Returns
Angles in radians of triangle ABC where angle BAC is at 0, angle ABC is at 1, angle BCA is at 2. An empty list is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) [math.degrees(i) for i in tri.angles()] # [45.0, 90.0, 45.0] QgsTriangle().angles() # []
-
asGml3
(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement¶
-
bisectors
(self, lengthTolerance: float = 0.0001) → List[QgsLineString]¶ The segment (defined by a
QgsLineString
) returned bisect the angle of a vertex to the opposite side.- Parameters
lengthTolerance – The tolerance to use.
- Returns
Three angle bisector from this triangle. An empty list is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) [bis.asWkt() for bis in tri.bisectors()] # ['LineString (0 0, 2.07106781186547462 5)', 'LineString (0 5, 2.5 2.5)', 'LineString (5 5, 0 2.92893218813452538)'] QgsTriangle().bisectors() # []
-
boundary
(self) → QgsCurve¶
-
calculateBoundingBox
()¶
-
childCount
()¶
-
childGeometry
()¶
-
childPoint
()¶
-
circumscribedCenter
(self) → QgsPoint¶ Center of the circumscribed circle of the triangle.
- Returns
The center of the circumscribed circle of the triangle. An empty point is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.circumscribedCenter().asWkt() # 'Point (2.5 2.5)' QgsTriangle().circumscribedCenter().asWkt() # 'Point (0 0)'
-
circumscribedCircle
(self) → QgsCircle¶ Circumscribed circle of the triangle.
- Returns
The circumbscribed of the triangle with a
QgsCircle
. An empty circle is returned for empty triangle. Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.circumscribedCircle() # QgsCircle(Point (2.5 2.5), 3.5355339059327378, 0) QgsTriangle().circumscribedCircle() # QgsCircle()
-
circumscribedRadius
(self) → float¶ Radius of the circumscribed circle of the triangle.
- Returns
The radius of the circumscribed circle of the triangle. 0.0 is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.circumscribedRadius() # 3.5355339059327378 QgsTriangle().circumscribedRadius() # 0.0
-
clear
(self)¶
-
clearCache
()¶
-
clone
(self) → QgsTriangle¶
-
createEmptyWithSameType
(self) → QgsTriangle¶
-
deleteVertex
(self, position: QgsVertexId) → bool¶ Inherited method not used. You cannot delete or insert a vertex directly. Returns always
False
.
-
fromWkb
(self, wkbPtr: QgsConstWkbPtr) → bool¶
-
fromWkt
(self, wkt: str) → bool¶
-
geometryType
(self) → str¶
-
hasChildGeometries
()¶
-
inscribedCenter
(self) → QgsPoint¶ Center of the inscribed circle of the triangle. Z dimension is supported and is retrieved from the first 3D point amongst vertices.
- Returns
The center of the inscribed circle of the triangle. An empty point is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.inscribedCenter().asWkt() # 'Point (1.46446609406726225 3.53553390593273775)' QgsTriangle().inscribedCenter().asWkt() # 'Point (0 0)'
-
inscribedCircle
(self) → QgsCircle¶ Inscribed circle of the triangle.
- Returns
The inscribed of the triangle with a
QgsCircle
. An empty circle is returned for empty triangle. Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.inscribedCircle() # QgsCircle(Point (1.46446609406726225 3.53553390593273775), 1.4644660940672622, 0) QgsTriangle().inscribedCircle() # QgsCircle()
-
inscribedRadius
(self) → float¶ Radius of the inscribed circle of the triangle.
- Returns
The radius of the inscribed circle of the triangle. 0.0 is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.inscribedRadius() # 1.4644660940672622 QgsTriangle().inscribedRadius() # 0.0
-
insertVertex
(self, position: QgsVertexId, vertex: QgsPoint) → bool¶ Inherited method not used. You cannot delete or insert a vertex directly. Returns always
False
.
-
isDegenerate
(self) → bool¶ Convenient method checking if the geometry is degenerate (have duplicate or colinear point(s)).
- Returns
True
if the triangle is degenerate or empty, otherwiseFalse
. Example:
tri = QgsTriangle() tri.isDegenerate() # True tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.isDegenerate() # False tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ) tri.isDegenerate() # True tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 5, 5 ) ) tri.isDegenerate() # True
-
isEquilateral
(self, lengthTolerance: float = 0.0001) → bool¶ Is the triangle equilateral (three sides with the same length)?
- Parameters
lengthTolerance – The tolerance to use
- Returns
True
orFalse
. AlwaysFalse
for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 10, 10 ), QgsPoint( 16, 10 ), QgsPoint( 13, 15.1962 ) ) tri.lengths() # [6.0, 6.0000412031918575, 6.0000412031918575] tri.isEquilateral() # True # All lengths are close to 6.0 QgsTriangle().isEquilateral() # False
-
isIsocele
(self, lengthTolerance: float = 0.0001) → bool¶ Is the triangle isocele (two sides with the same length)?
- Parameters
lengthTolerance – The tolerance to use
- Returns
True
orFalse
. AlwaysFalse
for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.lengths() # [5.0, 5.0, 7.0710678118654755] tri.isIsocele() # True # length of [AB] == length of [BC] QgsTriangle().isIsocele() # False
-
isRight
(self, angleTolerance: float = 0.0001) → bool¶ Is the triangle right-angled?
- Parameters
angleTolerance – The tolerance to use
- Returns
True
orFalse
. AlwaysFalse
for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) [math.degrees(i) for i in tri.angles()] # [45.0, 90.0, 45.0] tri.isRight() # True # angle of ABC == 90 QgsTriangle().isRight() # False
-
isScalene
(self, lengthTolerance: float = 0.0001) → bool¶ Is the triangle scalene (all sides have different lengths)?
- Parameters
lengthTolerance – The tolerance to use
- Returns
True
orFalse
. AlwaysFalse
for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 7.2825, 4.2368 ), QgsPoint( 13.0058, 3.3218 ), QgsPoint( 9.2145, 6.5242 ) ) tri.lengths() # [5.795980321740233, 4.962793714229921, 2.994131386562721] tri.isScalene() # True # All lengths are different QgsTriangle().isScalene() # False
-
lengths
(self) → List[float]¶ Returns the three lengths of the triangle.
- Returns
Lengths of triangle ABC where [AB] is at 0, [BC] is at 1, [CA] is at 2. An empty list is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.lengths() # [5.0, 5.0, 7.0710678118654755] QgsTriangle().lengths() # []
-
medial
(self) → QgsTriangle¶ Medial (or midpoint) triangle of a triangle ABC is the triangle with vertices at the midpoints of the triangle’s sides.
- Returns
The medial from this triangle. An empty triangle is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.medial().asWkt() # 'Triangle ((0 2.5, 2.5 5, 2.5 2.5, 0 2.5))' QgsTriangle().medial().asWkt() # 'Triangle ( )'
-
medians
(self) → List[QgsLineString]¶ A median is a segment (defined by a
QgsLineString
) from a vertex to the midpoint of the opposite side.- Returns
Three medians from this triangle. An empty list is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) [med.asWkt() for med in tri.medians()] # ['LineString (0 0, 2.5 5)', 'LineString (0 5, 2.5 2.5)', 'LineString (5 5, 0 2.5)'] QgsTriangle().medians() # []
-
moveVertex
(self, vId: QgsVertexId, newPos: QgsPoint) → bool¶
-
orthocenter
(self, lengthTolerance: float = 0.0001) → QgsPoint¶ An orthocenter is the point of intersection of the altitudes of a triangle.
- Parameters
lengthTolerance – The tolerance to use
- Returns
The orthocenter of the triangle. An empty point is returned for empty triangle. * Example:
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) ) tri.orthocenter().asWkt() # 'Point (0 5)' QgsTriangle().orthocenter().asWkt() # 'Point (0 0)'
-
setExteriorRing
(self, ring: QgsCurve)¶
-
setZMTypeFromSubGeometry
()¶
-
surfaceToPolygon
(self) → QgsPolygon¶
-
toCurveType
(self) → QgsCurvePolygon¶
-
vertexAt
(self, atVertex: int) → QgsPoint¶ Returns coordinates of a vertex.
- Parameters
atVertex – index of the vertex
- Returns
Coordinates of the vertex or QgsPoint(0,0) on error (
atVertex
< 0 or > 3).