:right-sidebar: True Triangle =================================================================== .. currentmodule:: gi.repository.Graphene .. versionadded:: 1.2 .. class:: Triangle(*args, **kwargs) :no-contents-entry: A triangle. Constructors ------------ .. rst-class:: interim-class .. class:: Triangle :no-index: .. classmethod:: alloc() -> ~gi.repository.Graphene.Triangle Allocates a new :obj:`~gi.repository.Graphene.Triangle`\. The contents of the returned structure are undefined. .. versionadded:: 1.2 Methods ------- .. rst-class:: interim-class .. class:: Triangle :no-index: .. method:: contains_point(p: ~gi.repository.Graphene.Point3D) -> bool Checks whether the given triangle ``t`` contains the point ``p``\. .. versionadded:: 1.2 :param p: a :obj:`~gi.repository.Graphene.Point3D` .. method:: equal(b: ~gi.repository.Graphene.Triangle) -> bool Checks whether the two given :obj:`~gi.repository.Graphene.Triangle` are equal. .. versionadded:: 1.2 :param b: a :obj:`~gi.repository.Graphene.Triangle` .. method:: free() -> None Frees the resources allocated by :func:`~gi.repository.Graphene.Triangle.alloc`. .. versionadded:: 1.2 .. method:: get_area() -> float Computes the area of the given :obj:`~gi.repository.Graphene.Triangle`\. .. versionadded:: 1.2 .. method:: get_barycoords(p: ~gi.repository.Graphene.Point3D | None = None) -> ~typing.Tuple[bool, ~gi.repository.Graphene.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: .. image:: /triangle-barycentric.png The returned :obj:`~gi.repository.Graphene.Vec2` contains the following values, in order: - ``res.x = u`` - ``res.y = v`` .. versionadded:: 1.2 :param p: a :obj:`~gi.repository.Graphene.Point3D` .. method:: get_bounding_box() -> ~gi.repository.Graphene.Box Computes the bounding box of the given :obj:`~gi.repository.Graphene.Triangle`\. .. versionadded:: 1.2 .. method:: get_midpoint() -> ~gi.repository.Graphene.Point3D Computes the coordinates of the midpoint of the given :obj:`~gi.repository.Graphene.Triangle`\. The midpoint G is the `centroid `__ of the triangle, i.e. the intersection of its medians. .. versionadded:: 1.2 .. method:: get_normal() -> ~gi.repository.Graphene.Vec3 Computes the normal vector of the given :obj:`~gi.repository.Graphene.Triangle`\. .. versionadded:: 1.2 .. method:: get_plane() -> ~gi.repository.Graphene.Plane Computes the plane based on the vertices of the given :obj:`~gi.repository.Graphene.Triangle`\. .. versionadded:: 1.2 .. method:: get_points() -> ~typing.Tuple[~gi.repository.Graphene.Point3D, ~gi.repository.Graphene.Point3D, ~gi.repository.Graphene.Point3D] Retrieves the three vertices of the given :obj:`~gi.repository.Graphene.Triangle` and returns their coordinates as :obj:`~gi.repository.Graphene.Point3D`\. .. versionadded:: 1.2 .. method:: get_uv(p: ~gi.repository.Graphene.Point3D | None, uv_a: ~gi.repository.Graphene.Vec2, uv_b: ~gi.repository.Graphene.Vec2, uv_c: ~gi.repository.Graphene.Vec2) -> ~typing.Tuple[bool, ~gi.repository.Graphene.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 :const:`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: :func:`~gi.repository.Graphene.Triangle.get_barycoords` .. versionadded:: 1.10 :param p: a :obj:`~gi.repository.Graphene.Point3D` :param uv_a: the UV coordinates of the first point :param uv_b: the UV coordinates of the second point :param uv_c: the UV coordinates of the third point .. method:: get_vertices() -> ~typing.Tuple[~gi.repository.Graphene.Vec3, ~gi.repository.Graphene.Vec3, ~gi.repository.Graphene.Vec3] Retrieves the three vertices of the given :obj:`~gi.repository.Graphene.Triangle`\. .. versionadded:: 1.2 .. method:: init_from_float(a: list[float], b: list[float], c: list[float]) -> ~gi.repository.Graphene.Triangle Initializes a :obj:`~gi.repository.Graphene.Triangle` using the three given arrays of floating point values, each representing the coordinates of a point in 3D space. .. versionadded:: 1.10 :param a: an array of 3 floating point values :param b: an array of 3 floating point values :param c: an array of 3 floating point values .. method:: init_from_point3d(a: ~gi.repository.Graphene.Point3D | None = None, b: ~gi.repository.Graphene.Point3D | None = None, c: ~gi.repository.Graphene.Point3D | None = None) -> ~gi.repository.Graphene.Triangle Initializes a :obj:`~gi.repository.Graphene.Triangle` using the three given 3D points. .. versionadded:: 1.2 :param a: a :obj:`~gi.repository.Graphene.Point3D` :param b: a :obj:`~gi.repository.Graphene.Point3D` :param c: a :obj:`~gi.repository.Graphene.Point3D` .. method:: init_from_vec3(a: ~gi.repository.Graphene.Vec3 | None = None, b: ~gi.repository.Graphene.Vec3 | None = None, c: ~gi.repository.Graphene.Vec3 | None = None) -> ~gi.repository.Graphene.Triangle Initializes a :obj:`~gi.repository.Graphene.Triangle` using the three given vectors. .. versionadded:: 1.2 :param a: a :obj:`~gi.repository.Graphene.Vec3` :param b: a :obj:`~gi.repository.Graphene.Vec3` :param c: a :obj:`~gi.repository.Graphene.Vec3` Fields ------ .. rst-class:: interim-class .. class:: Triangle :no-index: .. attribute:: a .. attribute:: b .. attribute:: c