polynomials_on_simplices.geometry.primitives.triangle module

Compute different triangle properties. A triangle is defined by its 3 vertices, given as rows in a matrix.

altitude_feet(vertices)[source]

Compute the foot of each altitude (the point where the altitude vector intersects the base vector).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:3 by n matrix with the altitude feet as rows.
Return type:Numpy array
altitude_vectors(vertices)[source]

Compute the altitude vectors of a triangle.

An altitude vector is a line segment from a vertex to the opposite edge, such that it is perpendicular to the edge. An altitude vector is parallel with the corresponding dual edge vector. But whereas the dual edge vector has the same length as the edge, the length of the altitude vector is the altitude or height of the triangle.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle altitude vectors.
Return type:Numpy array
altitudes(vertices)[source]

Compute the altitudes in a triangle (i.e. the shortest distance from each vertex to the line spanned by the opposite edge).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:Length 3 array of triangle altitudes.
Return type:List[float]
angle(vertices, i)[source]

Compute the angle of triangle at a vertex of the triangle.

Parameters:
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
  • i – Vertex at which we compute the triangle angle.
Returns:

The triangle angle at the supplied vertex.

Return type:

float

area(vertices)[source]

Compute the area of a triangle.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle area.
Return type:float
area_weighted_normal(vertices)[source]

Compute the area weighted normal of a triangle (\(2 A N = (p_1 - p_0) \times (p_2 - p_1)\)), where \(p_0, p_1, p_2\) are the vertices of the triangle.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The area weighted triangle normal.
Return type:Numpy array
barycentric_to_cartesian(bary, vertices)[source]

Compute the Cartesian coordinates of a point with given barycentric coordinates.

Parameters:
  • bary – The barycentric coordinates.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:

The Cartesian coordinates vector.

Return type:

n-dimensional vector

barycentric_to_trilinear(bary, vertices)[source]

Compute the trilinear coordinates (ratios between the distances to the triangle edges) of a point with given barycentric coordinates.

Parameters:
  • bary – The barycentric coordinates.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:

The trilinear coordinates (length 3 array).

Return type:

Numpy array

basis(vertices)[source]

Compute an orthonormal basis \({b_0, b_1}\) in the triangle plane, such that \(b_0 \times b_1 = n\) and \(b_0 || v_0\).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The orthonormal basis.
Return type:Numpy array
cartesian_to_barycentric(cartesian, vertices)[source]

Compute the barycentric coordinates of a point with given Cartesian coordinates.

Parameters:
  • cartesian – The Cartesian coordinates.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:

The barycentric coordinates (length 3 array).

Return type:

Numpy array

centroid(vertices)[source]

Compute the centroid of a triangle (center of gravity).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle centroid.
Return type:n-dimensional vector
circumcenter(vertices)[source]

Compute the circumcenter of a triangle (the center of the circle which passes through all the vertices of the triangle).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle circumcenter.
Return type:n-dimensional vector
circumradius(vertices)[source]

Compute the circumradius of a triangle (the radius of the circle which passes through all the vertices of the triangle). See http://mathworld.wolfram.com/Circumradius.html.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle circumradius.
Return type:float
diameter(vertices)[source]

Return largest distance between two points in a triangle, i.e. the length of the longest triangle edge.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:Triangle diameter.
Return type:float
dual_edges(vertices)[source]

Compute the dual edge vectors of a triangle. Dual edge vectors are normal to the edge vectors and points out of the triangle, \(d_i = v_i \times n\), where \(v_i\) are the triangle edges and \(n\) is the triangle normal.

Parameters:vertices – The triangle vertices (3 by 2 or 3 by 3 matrix with the vertices as rows).
Returns:The triangle dual edge vectors.
Return type:Numpy array
dual_edges_2(vertices)[source]

Compute the dual edge vectors of a triangle, expressed in the triangle plane orthonormal basis.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle dual edge vectors (3 by 2 matrix with the coordinates for edge i in row i).
Return type:Numpy array
edge_lengths(vertices)[source]

Compute the length of each edge in a triangle (i.e. the length of each vector returned by the edges() function.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:Length 3 array of edge lengths.
Return type:List[float]
edges(vertices)[source]

Compute the edge vectors of a triangle. The i:th edge is the edge opposite the i:th vertex.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle edge vectors (3 by n matrix with the edges as rows (where n is the dimension of the space)).
Return type:Numpy array
edges_2(vertices)[source]

Compute the edge vectors of a triangle, expressed in the triangle plane orthonormal basis.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle edge vectors (3 by 2 matrix with the coordinates for edge i in row i).
Return type:Numpy array
in_triangleplane_coords(vertices, v)[source]

Compute the representation of the vector v in the triangle plane orthonormal basis.

Parameters:
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
  • v (n-dimensional vector) – Vector whose coordinates we are interested in.
Returns:

Vector expressed in the triangle plane orthonormal basis (2d array with vector components).

Return type:

Numpy array

incenter(vertices)[source]

Compute the incenter of a triangle (the center of the largest inscribed circle or the intersection of all the angle bisectors).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle incenter.
Return type:n-dimensional vector
inradius(vertices)[source]

Compute the inradius of a triangle (the radius of the of the largest inscribed circle). See http://mathworld.wolfram.com/Inradius.html.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle inradius.
Return type:float
inside_triangle(point, vertices, include_boundary=True)[source]

Check whether or not a point lies inside a triangle.

Parameters:
  • point – Point which we want to check.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
  • include_boundary – Whether or not to consider points on the boundary as inside the triangle.
Returns:

Whether or not the points lies inside the triangle.

Return type:

bool

is_degenerate(vertices, eps=0.0002)[source]

Check if a triangle is degenerate.

A triangle is considered degenerate if any of its angles is smaller than \(\varepsilon\) radians,

\[\min_{i = 1, 2, 3} \alpha_i < \varepsilon.\]
Parameters:
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
  • eps (float) – Triangle angle tolerance in the degeneracy check.
Returns:

Whether or not the triangle is degenerate (has an angle that is too small).

Return type:

bool

medians(vertices)[source]

Compute the median vectors of a triangle, pointing from each vertex into the triangle to the midpoint of the opposite edge.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle median vectors (3 by n matrix with the median vectors as rows).
Return type:Numpy array
medians_2(vertices)[source]

Compute the median vectors of a triangle, pointing from each vertex into the triangle. Expressed in the triangle plane orthonormal basis.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle median vectors (3 by 2 matrix with the median vectors as rows).
Return type:Numpy array
normal(vertices)[source]

Compute the normal of a triangle.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The normalized triangle normal.
Return type:Numpy array
normalize_trilinear_coordinates(trilinear, vertices)[source]

Compute normalized (or exact) trilinear coordinates (ratios between the distances to the triangle edges).

Two trilinear coordinates x:y:z and kx:ky:kz describe the same point. Here normalized means that the three entries in the trilinear coordinates is exactly the distance from the point to the three edges. See http://mathworld.wolfram.com/ExactTrilinearCoordinates.html.

Parameters:
  • trilinear (3d vector) – Trilinear coordinates.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:

Equivalent normalized trilinear coordinates.

Return type:

3d vector

orthocenter(vertices)[source]

Compute the orthocenter of a triangle (the point where all the triangle heights intersect).

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle orthocenter.
Return type:n-dimensional vector
perimeter(vertices)[source]

Compute the perimeter of a triangle.

Parameters:vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:The triangle perimeter.
Return type:float
side_distances_to_trilinear(side_distances)[source]

Compute trilinear coordinates (ratios between the distances to the triangle edges) for a point with given distances to each edge of the triangle.

Parameters:side_distances (3d vector) – Distance from the point to each edge of the triangle.
Returns:Trilinear coordinates.
Return type:3d vector
trilinear_to_barycentric(trilinear, vertices)[source]

Compute the barycentric coordinates of a point with given trilinear coordinates (ratios between the distances to the triangle edges).

Parameters:
  • trilinear (3d vector) – The trilinear coordinates.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:

The barycentric coordinates (length 3 array).

Return type:

Numpy array

trilinear_to_side_distances(trilinear, vertices)[source]

Compute actual distances to the triangle edges for a point with given trilinear coordinates (ratios between the distances to the triangle edges).

Parameters:
  • trilinear (3d vector) – The trilinear coordinates.
  • vertices – The triangle vertices (3 by n matrix with the vertices as rows (where n is the dimension of the space)).
Returns:

Distance from the point to each edge of the triangle (length 3 array).

Return type:

3d vector