8 Triangle triangle(Point p1, Point p2, Point p3)
10 const Triangle result = {
19 Triangle equilateral_triangle(void)
21 const float d = PI_2 / 3.0f;
23 const Triangle result = {
24 .p1 = vec(cosf(0.0f), sinf(0.0f)),
25 .p2 = vec(cosf(d), sinf(d)),
26 .p3 = vec(cosf(2.0f * d), sinf(2.0f * d))
32 Triangle random_triangle(float radius)
35 vec_from_polar(rand_float(2 * PI), rand_float(radius)),
36 vec_from_polar(rand_float(2 * PI), rand_float(radius)),
37 vec_from_polar(rand_float(2 * PI), rand_float(radius)));
40 static void swap_points(Point *p1, Point *p2)
47 Triangle triangle_sorted_by_y(Triangle t)
49 if (t.p1.y > t.p2.y) { swap_points(&t.p1, &t.p2); }
50 if (t.p2.y > t.p3.y) { swap_points(&t.p2, &t.p3); }
51 if (t.p1.y > t.p2.y) { swap_points(&t.p1, &t.p2); }
56 void rect_as_triangles(Rect rect, Triangle triangles[2])
59 .p1 = { .x = rect.x, .y = rect.y },
60 .p2 = { .x = rect.x + rect.w, .y = rect.y },
61 .p3 = { .x = rect.x, .y = rect.y + rect.h }
65 .p1 = { .x = rect.x + rect.w, .y = rect.y },
66 .p2 = { .x = rect.x, .y = rect.y + rect.h },
67 .p3 = { .x = rect.x + rect.w, .y = rect.y + rect.h }
74 Triangle triangle_mat3x3_product(Triangle t, mat3x3 m)
77 .p1 = point_mat3x3_product(t.p1, m),
78 .p2 = point_mat3x3_product(t.p2, m),
79 .p3 = point_mat3x3_product(t.p3, m)