Counting the amount of triangles in a picture is a task commonly used in brain tests. You are given a picture that contains shapes consisting of triangles. You then must find all possible triangles in the picture.
Task
You are given a list of lines in a format of your choice. You must then output a list of triangles found in that
Input
You are given a list of lines, each given by four integer coordinates (eg. x1 y1 x2 y2
). You may choose the input format, as long as it is clearly documented. Examples:
0 4 8 1
0 4 9 5
8 1 9 5
2 8 0 4
9 5 2 8
[[0, 4, 8, 1], [0, 4, 9, 5], [8, 1, 9, 5], [2, 8, 0, 4], [9, 5, 2, 8]]
Here's the same input as an image:
Another one, with intersections (only in one format to save space):
[[2, 1, 5, 0], [2, 1, 2, 7], [5, 0, 6, 6], [5, 0, 2, 7], [6, 6, 2, 1], [2, 7, 6, 6]]
Output
You must output a list of all triangles, each given by six floating-point coordinates (eg. x1 y1 x2 y2 x3 y3
), in the picture specified by the input. These might not be integers, since the lines may cross at any point. You may choose the output format, as long as it is clearly documented. Example outputs for the example inputs above:
0 4 8 1 9 5
0 4 9 5 2 8
[[0, 4, 8, 3, 9, 5], [0, 4, 9, 5, 2, 8]]
[[2, 1, 5, 0, 2, 7], [2, 1, 5, 0, 6, 6], [5, 0, 6, 6, 2, 7], [2, 1, 6, 6, 2, 7], [2, 1, 5, 0, 3.674, 3.093], [5, 0, 6, 6, 3.674, 3.093], [6, 6, 2, 7, 3.674, 3.093], [2, 7, 2, 1, 3.674, 3.093]]
You may assume that
there are no edge cases where a line crosses an intersection but not any lines, like
[[0, 9, 1, 8], [1, 8, 2, 9], [2, 9, 3, 8], [3, 8, 4, 9], [4, 9, 0, 9]]
there are no angles over 179 degrees, like
[[0, 0, 0, 1], [0, 1, 0, 2], [0, 2, 0, 0]]
Rules
- You may use any language you want.
- No external resources must be used.
- Standard loopholes apply.
Scoring
This is code-golf, so the shortest answer in bytes wins.
[0,9],[1,8],[2,9],[3,8],[4,9]
is actually a W with a line drawn across the top. Is that no triangles or 2 triangles? \$\endgroup\$[0,0],[1,0],[2,0],[1,2]
A "quadrilateral" with one angle of 180 degrees. No triangles or 1 triangle? \$\endgroup\$