Class: QgsTriangle¶
- class qgis.core.QgsTriangle¶
Bases:
QgsPolygon
Triangle geometry type.
New in version 3.0.
QgsTriangle() Constructor for an empty triangle geometry.
QgsTriangle(p1:
QgsPoint
, p2:QgsPoint
, p3:QgsPoint
) Construct aQgsTriangle
from threeQgsPoint
.- Parameters:
p1 – first point
p2 – second point
p3 – third point
QgsTriangle(p1:
QgsPointXY
, p2:QgsPointXY
, p3:QgsPointXY
) Construct aQgsTriangle
from threeQgsPointXY
.- 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
)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.
- param doc:
The segment (defined by a
QgsLineString
) returned bisect the angle of a vertex to the opposite side.- rtype:
QgsCurve
Default calculator for the minimal bounding box for the geometry.
Returns point at index (for geometries without child geometries - i.e. curve / point).
Center of the circumscribed circle of the triangle.
Circumscribed circle of the triangle.
Radius of the circumscribed circle of the triangle.
- rtype:
QgsTriangle
- rtype:
QgsTriangle
Inherited method not used.
- param wkbPtr:
- param wkt:
- rtype:
str
Returns whether the geometry has any child geometries (
False
for point / curve,True
otherwise)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.- param vId:
An orthocenter is the point of intersection of the altitudes of a triangle.
- param ring:
Updates the geometry type based on whether sub geometries contain z or m values.
Returns the sort index for the geometry, used in the
compareTo()
method to compare geometries of different types.- rtype:
QgsPolygon
- rtype:
QgsCurvePolygon
Returns coordinates of a vertex.
- addInteriorRing(self, ring: QgsCurve)¶
Inherited method not used. You cannot add an interior ring into a triangle.
- Parameters:
ring (QgsCurve) –
- 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).- Return type:
List[QgsLineString]
- 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.
- Return type:
List[float]
- 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 ¶
- Parameters:
doc (QDomDocument) –
precision (int = 17) –
ns (str = '') –
axisOrder (QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) –
- Return type:
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 (float = 0.0001) – The tolerance to use.
- Return type:
List[QgsLineString]
- 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() # []
- calculateBoundingBox(self) QgsRectangle ¶
Default calculator for the minimal bounding box for the geometry. Derived classes should override this method if a more efficient bounding box calculation is available.
- childCount(self) int ¶
- childGeometry(self, index: int) QgsAbstractGeometry ¶
- childPoint(self, index: int) QgsPoint ¶
Returns point at index (for geometries without child geometries - i.e. curve / point)
Note
used for vertex_iterator implementation
New in version 3.0.
- circumscribedCenter(self) QgsPoint ¶
Center of the circumscribed circle of the triangle.
- Return type:
- 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.
- Return type:
- 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.
- Return type:
float
- 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(self)¶
- clone(self) QgsTriangle ¶
- Return type:
- compareToSameClass(self, other: QgsAbstractGeometry) int ¶
- createEmptyWithSameType(self) QgsTriangle ¶
- Return type:
- deleteVertex(self, position: QgsVertexId) bool ¶
Inherited method not used. You cannot delete or insert a vertex directly. Returns always
False
.- Parameters:
position (QgsVertexId) –
- Return type:
bool
- fromWkb(self, wkbPtr: QgsConstWkbPtr) bool ¶
- Parameters:
wkbPtr (QgsConstWkbPtr) –
- Return type:
bool
- fromWkt(self, wkt: str) bool ¶
- Parameters:
wkt (str) –
- Return type:
bool
- geometryType(self) str ¶
- Return type:
str
- hasChildGeometries(self) bool ¶
Returns whether the geometry has any child geometries (
False
for point / curve,True
otherwise)Note
used for vertex_iterator implementation
New in version 3.0.
- 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.
- Return type:
- 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.
- Return type:
- 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.
- Return type:
float
- 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
.- Parameters:
position (QgsVertexId) –
vertex (QgsPoint) –
- Return type:
bool
- isDegenerate(self) bool ¶
Convenient method checking if the geometry is degenerate (have duplicate or colinear point(s)).
- Return type:
bool
- 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 (float = 0.0001) – The tolerance to use
- Return type:
bool
- 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 (float = 0.0001) – The tolerance to use
- Return type:
bool
- 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 (float = 0.0001) – The tolerance to use
- Return type:
bool
- 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 (float = 0.0001) – The tolerance to use
- Return type:
bool
- 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.
- Return type:
List[float]
- 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.
- Return type:
- 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.- Return type:
List[QgsLineString]
- 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 ¶
- Parameters:
vId (QgsVertexId) –
newPos (QgsPoint) –
- Return type:
bool
- orthocenter(self, lengthTolerance: float = 0.0001) QgsPoint ¶
An orthocenter is the point of intersection of the altitudes of a triangle.
- Parameters:
lengthTolerance (float = 0.0001) – The tolerance to use
- Return type:
- 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)'
- setZMTypeFromSubGeometry(self, subggeom: QgsAbstractGeometry, baseGeomType: Qgis.WkbType)¶
Updates the geometry type based on whether sub geometries contain z or m values.
- sortIndex(self) int ¶
Returns the sort index for the geometry, used in the
compareTo()
method to compare geometries of different types.New in version 3.20.
- surfaceToPolygon(self) QgsPolygon ¶
- Return type:
- toCurveType(self) QgsCurvePolygon ¶
- Return type: