GEOS 3.14.0dev
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
geos::geom::Triangle Class Reference

Represents a planar triangle, and provides methods for calculating various properties of triangles. More...

#include <Triangle.h>

Public Member Functions

 Triangle (const CoordinateXY &nP0, const CoordinateXY &nP1, const CoordinateXY &nP2)
 
void inCentre (CoordinateXY &resultPoint)
 The inCentre of a triangle is the point which is equidistant from the sides of the triangle.
 
void circumcentre (CoordinateXY &resultPoint)
 Computes the circumcentre of a triangle.
 
void circumcentreDD (CoordinateXY &resultPoint)
 
double circumradius () const
 
bool isIsoceles ()
 
bool intersects (const CoordinateXY &p)
 
bool isCCW ()
 
bool isAcute ()
 
double length () const
 
double area () const
 

Static Public Member Functions

static const CoordinateXY circumcentre (const CoordinateXY &p0, const CoordinateXY &p1, const CoordinateXY &p2)
 
static double circumradius (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c)
 
static bool isAcute (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c)
 
static bool isCCW (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c)
 
static bool intersects (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c, const CoordinateXY &p)
 
static double longestSideLength (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c)
 
static double length (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c)
 
static double area (const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c)
 

Public Attributes

CoordinateXY p0
 
CoordinateXY p1
 
CoordinateXY p2
 

Detailed Description

Represents a planar triangle, and provides methods for calculating various properties of triangles.

Member Function Documentation

◆ area()

static double geos::geom::Triangle::area ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c 
)
static

Computes the 2D area of a triangle. The area value is always non-negative.

Parameters
avertex of the triangle
bvertex of the triangle
cvertex of the triangle
Returns
the area of the triangle

◆ circumcentre() [1/2]

static const CoordinateXY geos::geom::Triangle::circumcentre ( const CoordinateXY &  p0,
const CoordinateXY &  p1,
const CoordinateXY &  p2 
)
static

Computes the circumcentre of a triangle. The circumcentre is the centre of the circumcircle, the smallest circle which passes through all the triangle vertices. It is also the common intersection point of the perpendicular bisectors of the

Parameters
p0corner of the triangle
p1corner of the triangle
p2corner of the triangle
Returns
the center of the the smallest circle that encloses the triangle

◆ circumcentre() [2/2]

void geos::geom::Triangle::circumcentre ( CoordinateXY &  resultPoint)

Computes the circumcentre of a triangle.

The circumcentre is the centre of the circumcircle, the smallest circle which encloses the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.

The circumcentre does not necessarily lie within the triangle. For example, the circumcentre of an obtuse isoceles triangle lies outside the triangle.

This method uses an algorithm due to J.R.Shewchuk which uses normalization to the origin to improve the accuracy of computation. (See Lecture Notes on Geometric Robustness, Jonathan Richard Shewchuk, 1999).

Parameters
resultPointthe point into which to write the inCentre of the triangle

◆ circumcentreDD()

void geos::geom::Triangle::circumcentreDD ( CoordinateXY &  resultPoint)

Calculates the circumcentre using double precision math

Parameters
resultPointthe point into which to write the inCentre of the triangle

◆ circumradius() [1/2]

double geos::geom::Triangle::circumradius ( ) const
inline

Computes the radius of the circumcircle of a triangle.

Returns
the triangle circumradius

◆ circumradius() [2/2]

static double geos::geom::Triangle::circumradius ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c 
)
static

Computes the radius of the circumcircle of a triangle. Formula is as per https://math.stackexchange.com/a/3610959

Parameters
aa vertex of the triangle
ba vertex of the triangle
ca vertex of the triangle
Returns
the circumradius of the triangle

◆ inCentre()

void geos::geom::Triangle::inCentre ( CoordinateXY &  resultPoint)

The inCentre of a triangle is the point which is equidistant from the sides of the triangle.

This is also the point at which the bisectors of the angles meet.

Parameters
resultPointthe point into which to write the inCentre of the triangle

◆ intersects() [1/2]

static bool geos::geom::Triangle::intersects ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c,
const CoordinateXY &  p 
)
static

Tests whether a triangle intersects a point.

Parameters
aa vertex of the triangle
ba vertex of the triangle
ca vertex of the triangle
pthe point to test
Returns
true if the triangle intersects the point

◆ intersects() [2/2]

bool geos::geom::Triangle::intersects ( const CoordinateXY &  p)
inline

Tests whether a triangle intersects a point.

Parameters
pthe point to test
Returns
true if the triangle intersects the point

References intersects().

Referenced by intersects().

◆ isAcute() [1/2]

bool geos::geom::Triangle::isAcute ( )
inline

Tests whether this triangle is acute.

Returns
true if this triangle is acute

References isAcute().

Referenced by isAcute().

◆ isAcute() [2/2]

static bool geos::geom::Triangle::isAcute ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c 
)
static

Tests whether a triangle is acute. A triangle is acute if all interior angles are acute. This is a strict test - right triangles will return false. A triangle which is not acute is either right or obtuse.

Note: this implementation is not robust for angles very close to 90 degrees.

Parameters
aa vertex of the triangle
ba vertex of the triangle
ca vertex of the triangle
Returns
true if the triangle is acute

◆ isCCW() [1/2]

bool geos::geom::Triangle::isCCW ( )
inline

Tests whether this triangle is oriented counter-clockwise.

Returns
true if the triangle orientation is counter-clockwise

References isCCW().

Referenced by isCCW().

◆ isCCW() [2/2]

static bool geos::geom::Triangle::isCCW ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c 
)
static

Tests whether a triangle is oriented counter-clockwise.

Parameters
aa vertex of the triangle
ba vertex of the triangle
ca vertex of the triangle
Returns
true if the triangle orientation is counter-clockwise

◆ length() [1/2]

double geos::geom::Triangle::length ( ) const

Computes the length of the perimeter of this triangle.

Returns
the length of the perimeter

◆ length() [2/2]

static double geos::geom::Triangle::length ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c 
)
static

Compute the length of the perimeter of a triangle

Parameters
aa vertex of the triangle
ba vertex of the triangle
ca vertex of the triangle
Returns
the length of the triangle perimeter

◆ longestSideLength()

static double geos::geom::Triangle::longestSideLength ( const CoordinateXY &  a,
const CoordinateXY &  b,
const CoordinateXY &  c 
)
static

Computes the length of the longest side of a triangle

Parameters
aa vertex of the triangle
ba vertex of the triangle
ca vertex of the triangle
Returns
the length of the longest side of the triangle

The documentation for this class was generated from the following file: