Triangle

Added in version 1.2.

class Triangle(*args, **kwargs)

A triangle.

Constructors

class Triangle
classmethod alloc() Triangle

Allocates a new Triangle.

The contents of the returned structure are undefined.

Added in version 1.2.

Methods

class Triangle
contains_point(p: Point3D) bool

Checks whether the given triangle t contains the point p.

Added in version 1.2.

Parameters:

p – a Point3D

equal(b: Triangle) bool

Checks whether the two given Triangle are equal.

Added in version 1.2.

Parameters:

b – a Triangle

free() None

Frees the resources allocated by alloc().

Added in version 1.2.

get_area() float

Computes the area of the given Triangle.

Added in version 1.2.

get_barycoords(p: Point3D | None = None) tuple[bool, Vec2]

Computes the barycentric coordinates of the given point p.

The point p must lie on the same plane as the triangle t; if the point is not coplanar, the result of this function is undefined.

If we place the origin in the coordinates of the triangle’s A point, the barycentric coordinates are u, which is on the AC vector; and v which is on the AB vector:

triangle-barycentric.png

The returned Vec2 contains the following values, in order:

  • res.x = u

  • res.y = v

Added in version 1.2.

Parameters:

p – a Point3D

get_bounding_box() Box

Computes the bounding box of the given Triangle.

Added in version 1.2.

get_midpoint() Point3D

Computes the coordinates of the midpoint of the given Triangle.

The midpoint G is the centroid of the triangle, i.e. the intersection of its medians.

Added in version 1.2.

get_normal() Vec3

Computes the normal vector of the given Triangle.

Added in version 1.2.

get_plane() Plane

Computes the plane based on the vertices of the given Triangle.

Added in version 1.2.

get_points() tuple[Point3D, Point3D, Point3D]

Retrieves the three vertices of the given Triangle and returns their coordinates as Point3D.

Added in version 1.2.

get_uv(p: Point3D | None, uv_a: Vec2, uv_b: Vec2, uv_c: Vec2) tuple[bool, Vec2]

Computes the UV coordinates of the given point p.

The point p must lie on the same plane as the triangle t; if the point is not coplanar, the result of this function is undefined. If p is None, the point will be set in (0, 0, 0).

The UV coordinates will be placed in the res vector:

  • res.x = u

  • res.y = v

See also: get_barycoords()

Added in version 1.10.

Parameters:
  • p – a Point3D

  • uv_a – the UV coordinates of the first point

  • uv_b – the UV coordinates of the second point

  • uv_c – the UV coordinates of the third point

get_vertices() tuple[Vec3, Vec3, Vec3]

Retrieves the three vertices of the given Triangle.

Added in version 1.2.

init_from_float(a: Sequence[float], b: Sequence[float], c: Sequence[float]) Triangle

Initializes a Triangle using the three given arrays of floating point values, each representing the coordinates of a point in 3D space.

Added in version 1.10.

Parameters:
  • a – an array of 3 floating point values

  • b – an array of 3 floating point values

  • c – an array of 3 floating point values

init_from_point3d(a: Point3D | None = None, b: Point3D | None = None, c: Point3D | None = None) Triangle

Initializes a Triangle using the three given 3D points.

Added in version 1.2.

Parameters:
init_from_vec3(a: Vec3 | None = None, b: Vec3 | None = None, c: Vec3 | None = None) Triangle

Initializes a Triangle using the three given vectors.

Added in version 1.2.

Parameters:

Fields

class Triangle
a
b
c