Class: QgsTriangle

class qgis.core.QgsTriangle

Bases: 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.

Methods

addInteriorRing

Inherited method not used.

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.

asGml3

param doc

bisectors

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

boundary

rtype

QgsCurve

calculateBoundingBox

childCount

childGeometry

childPoint

circumscribedCenter

Center of the circumscribed circle of the triangle.

circumscribedCircle

Circumscribed circle of the triangle.

circumscribedRadius

Radius of the circumscribed circle of the triangle.

clear

clearCache

clone

rtype

QgsTriangle

createEmptyWithSameType

rtype

QgsTriangle

deleteVertex

Inherited method not used.

fromWkb

param wkbPtr

fromWkt

param wkt

geometryType

rtype

str

hasChildGeometries

inscribedCenter

Center of the inscribed circle of the triangle.

inscribedCircle

Inscribed circle of the triangle.

inscribedRadius

Radius of the inscribed circle of the triangle.

insertVertex

Inherited method not used.

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.

moveVertex

param vId

orthocenter

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

setExteriorRing

param ring

setZMTypeFromSubGeometry

surfaceToPolygon

rtype

QgsPolygon

toCurveType

rtype

QgsCurvePolygon

vertexAt

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()
# []
boundary(self) → QgsCurve
Return type

QgsCurve

calculateBoundingBox()
childCount()
childGeometry()
childPoint()
circumscribedCenter(self) → QgsPoint

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

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

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()
clone(self) → QgsTriangle
Return type

QgsTriangle

createEmptyWithSameType(self) → QgsTriangle
Return type

QgsTriangle

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

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

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

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
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, 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

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

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

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

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

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()
# []
moveVertex(self, vId: QgsVertexId, newPos: QgsPoint) → bool
Parameters
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

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)'
setExteriorRing(self, ring: QgsCurve)
Parameters

ring (QgsCurve) –

setZMTypeFromSubGeometry()
surfaceToPolygon(self) → QgsPolygon
Return type

QgsPolygon

toCurveType(self) → QgsCurvePolygon
Return type

QgsCurvePolygon

vertexAt(self, atVertex: int) → QgsPoint

Returns coordinates of a vertex.

Parameters

atVertex (int) – index of the vertex

Return type

QgsPoint

Returns

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