Triangle

The Triangle class provides functionalities for creating, manipulating, and drawing triangles.

class Triangle

This class represents a triangle with three vertices and a color.

new(vec2_a, vec2_b, vec2_c, color)

Creates a new Triangle instance.

Parameters:
  • vec2_a (table) – The first vertex of the triangle.

  • vec2_b (table) – The second vertex of the triangle.

  • vec2_c (table) – The third vertex of the triangle.

  • color (table) – The color of the triangle.

Returns:

A new instance of Triangle.

draw()

Draws the triangle using the specified vertices and color.

get_vec2s()

Returns the vertices of the triangle.

Returns:

A table containing the vertices of the triangle.

get_vec2_a()
Returns:

The first vertex of the triangle.

get_vec2_b()
Returns:

The second vertex of the triangle.

get_vec2_c()
Returns:

The third vertex of the triangle.

Set_vec2s(...)

Sets the vertices of the triangle.

Set_vec2_a(x, y)

Sets the first vertex of the triangle.

Parameters:
  • x (number) – The x-coordinate.

  • y (number) – The y-coordinate.

Set_vec2_b(x, y)

Sets the second vertex of the triangle.

Parameters:
  • x (number) – The x-coordinate.

  • y (number) – The y-coordinate.

Set_vec2_c(x, y)

Sets the third vertex of the triangle.

Parameters:
  • x (number) – The x-coordinate.

  • y (number) – The y-coordinate.

centroid()

Calculates the centroid of the triangle.

Returns:

The centroid as a Vec2 instance.

area()

Calculates the area of the triangle.

Returns:

The area of the triangle.

perimeter()

Calculates the perimeter of the triangle.

Returns:

The perimeter of the triangle.

type()

Determines the type of the triangle (equilateral, isosceles, or scalene).

Returns:

The type of the triangle as a string.

angle_type()

Determines the angle type of the triangle (right, obtuse, or acute).

Returns:

The angle type of the triangle as a string.

scale(scalar)

Scales the triangle by a specified scalar.

Parameters:

scalar (number) – The scaling factor.

Returns:

A new scaled Triangle instance.

Scale(scalar)

Scales the triangle in place by a specified scalar.

Parameters:

scalar (number) – The scaling factor.

rotate(angle)

Rotates the triangle by a specified angle.

Parameters:

angle (number) – The rotation angle in radians.

Returns:

A new rotated Triangle instance.

Rotate(angle)

Rotates the triangle in place by a specified angle.

Parameters:

angle (number) – The rotation angle in radians.

translate(vec2)

Translates the triangle by a specified vector.

Parameters:

vec2 (table) – The translation vector.

Returns:

A new translated Triangle instance.

Translate(vec2)

Translates the triangle in place by a specified vector.

Parameters:

vec2 (table) – The translation vector.

bounding_box()

Calculates the bounding box of the triangle.

Returns:

The minimum and maximum Vec2 points defining the bounding box.

incircle()

Calculates the incircle of the triangle.

Returns:

The center and radius of the incircle as a Vec2 instance and a number, respectively.

circumcircle()

Calculates the circumcircle of the triangle.

Returns:

The center and radius of the circumcircle as a Vec2 instance and a number, respectively.