Class: QgsTriangle

Triangle geometry type.

Class Hierarchy

Inheritance diagram of qgis.core.QgsTriangle

Base classes

QgsPolygon

Polygon geometry type.

QgsCurvePolygon

Curve polygon geometry type.

QgsSurface

Surface geometry type.

QgsAbstractGeometry

Abstract base class for all geometries.

Abstract Methods

deleteVertex

Inherited method not used.

insertVertex

Inherited method not used.

vertexAt

Methods

altitudes

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).

angles

Returns the three angles of the triangle.

bisectors

The segment (defined by a QgsLineString) returned bisect the angle of a vertex to the opposite side.

circumscribedCenter

Center of the circumscribed circle of the triangle.

circumscribedCircle

Circumscribed circle of the triangle.

circumscribedRadius

Radius of the circumscribed circle of the triangle.

inscribedCenter

Center of the inscribed circle of the triangle.

inscribedCircle

Inscribed circle of the triangle.

inscribedRadius

Radius of the inscribed circle of the triangle.

isDegenerate

Convenient method checking if the geometry is degenerate (have duplicate or colinear point(s)).

isEquilateral

Is the triangle equilateral (three sides with the same length)?

isIsocele

Is the triangle isocele (two sides with the same length)?

isRight

Is the triangle right-angled?

isScalene

Is the triangle scalene (all sides have different lengths)?

lengths

Returns the three lengths of the triangle.

medial

Medial (or midpoint) triangle of a triangle ABC is the triangle with vertices at the midpoints of the triangle's sides.

medians

A median is a segment (defined by a QgsLineString) from a vertex to the midpoint of the opposite side.

orthocenter

An orthocenter is the point of intersection of the altitudes of a triangle.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsTriangle. See the FAQ for more details.

addInteriorRing

Inherited method not used.

class qgis.core.QgsTriangle[source]

Bases: QgsPolygon

__init__()

Constructor for an empty triangle geometry.

__init__(p1: QgsPoint, p2: QgsPoint, p3: QgsPoint)

Construct a QgsTriangle from three QgsPoint.

Parameters:
__init__(p1: QgsPointXY, p2: QgsPointXY, p3: QgsPointXY)

Construct a QgsTriangle from three QgsPointXY.

Parameters:
__init__(p1: QPointF | QPoint, p2: QPointF | QPoint, p3: QPointF | QPoint)

Construct a QgsTriangle from three QPointF.

Parameters:
  • p1 (Union[QPointF, QPoint]) – first point

  • p2 (Union[QPointF, QPoint]) – second point

  • p3 (Union[QPointF, QPoint]) – third point

__init__(a0: QgsTriangle)
Parameters:

a0 (QgsTriangle)

virtual addInteriorRing(self, ring: QgsCurve | None)[source]

Inherited method not used. You cannot add an interior ring into a triangle.

Parameters:

ring (Optional[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()
# []
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()
# []
circumscribedCenter(self) QgsPoint[source]

Center of the circumscribed circle of the triangle.

Return type:

QgsPoint

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[source]

Circumscribed circle of the triangle.

Return type:

QgsCircle

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[source]

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
abstract deleteVertex(self, position: QgsVertexId) bool[source]

Inherited method not used. You cannot delete or insert a vertex directly. Returns always False.

Parameters:

position (QgsVertexId)

Return type:

bool

inscribedCenter(self) QgsPoint[source]

Center of the inscribed circle of the triangle. Z dimension is supported and is retrieved from the first 3D point amongst vertices.

Return type:

QgsPoint

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[source]

Inscribed circle of the triangle.

Return type:

QgsCircle

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[source]

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
abstract insertVertex(self, position: QgsVertexId, vertex: QgsPoint) bool[source]

Inherited method not used. You cannot delete or insert a vertex directly. Returns always False.

Parameters:
Return type:

bool

isDegenerate(self) bool[source]

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, otherwise False.

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[source]

Is the triangle equilateral (three sides with the same length)?

Parameters:

lengthTolerance (float = 0.0001) – The tolerance to use

Return type:

bool

Returns:

True or False. Always False 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[source]

Is the triangle isocele (two sides with the same length)?

Parameters:

lengthTolerance (float = 0.0001) – The tolerance to use

Return type:

bool

Returns:

True or False. Always False 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[source]

Is the triangle right-angled?

Parameters:

angleTolerance (float = 0.0001) – The tolerance to use

Return type:

bool

Returns:

True or False. Always False 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[source]

Is the triangle scalene (all sides have different lengths)?

Parameters:

lengthTolerance (float = 0.0001) – The tolerance to use

Return type:

bool

Returns:

True or False. Always False 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[source]

Medial (or midpoint) triangle of a triangle ABC is the triangle with vertices at the midpoints of the triangle’s sides.

Return type:

QgsTriangle

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()
# []
orthocenter(self, lengthTolerance: float = 0.0001) QgsPoint[source]

An orthocenter is the point of intersection of the altitudes of a triangle.

Parameters:

lengthTolerance (float = 0.0001) – The tolerance to use

Return type:

QgsPoint

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)'
abstract vertexAt(self, id: QgsVertexId) QgsPoint[source]
Parameters:

id (QgsVertexId)

Return type:

QgsPoint

abstract vertexAt(self, atVertex: int) QgsPoint[source]

Returns coordinates of a vertex.

Parameters:

atVertex (int) – index of the vertex

Return type:

QgsPoint

Returns:

Coordinates of the vertex or empty QgsPoint on error (atVertex < 0 or > 3).