Consider the standard equilateral triangle, with nodes labeled using barycentric coordinates:
We can turn this 3 node triangle into a 6 node triangle by adding a new line of 3 vertices (one more than was present on a side of the original 3 node triangle), remove any internal edges (but not internal nodes) and re-normalize the coordinates:
Repeating the process to go from a 6 node triangle to a 10 node triangle, add a line of 4 vertices (again, one more than was present on a side of the original 6 node triangle), remove any internal edges (but not internal nodes) and re-normalize the coordinates:
This process can be repeated indefinitely. The goal of this challenge is given an integer N
representing how many times this process has been performed, output all the nodes for the associated triangle in barycentric coordinates.
Input
Your program/function should take as input a single non-negative integer N
representing how many times this process has been applied. Note that for N=0
, you should output the original triangle with 3 nodes.
The input may come from any source (function parameter, stdio, etc.).
Output
Your program/function should output all the nodes in normalized barycentric coordinates. The order of the nodes does not matter. A number can be specified as a fraction (fraction reduction not required) or a floating point number. You may also output "scaled" vectors to specify a node. For example, all 3 of the following outputs are equivalent and allowed:
0.5,0.5,0
1/2,2/4,0
[1,1,0]/2
If using floating point output, your output should be accurate to within 1%. The output may be to any sink desired (stdio, return value, return parameter, etc.). Note that even though the barycentric coordinates are uniquely determined by only 2 numbers per node, you should output all 3 numbers per node.
Examples
Example cases are formatted as:
N
x0,y0,z0
x1,y1,z1
x2,y2,z2
...
where the first line is the input N
, and all following lines form a node x,y,z
which should be in the output exactly once. All numbers are given as approximate floating point numbers.
0
1,0,0
0,1,0
0,0,1
1
1,0,0
0,1,0
0,0,1
0.5,0,0.5
0.5,0.5,0
0,0.5,0.5
2
1,0,0
0,1,0
0,0,1
0.667,0,0.333
0.667,0.333,0
0.333,0,0.667
0.333,0.333,0.333
0.333,0.667,0
0,0.333,0.667
0,0.667,0.333
3
1,0,0
0.75,0,0.25
0.75,0.25,0
0.5,0,0.5
0.5,0.25,0.25
0.5,0.5,0
0.25,0,0.75
0.25,0.25,0.5
0.25,0.5,0.25
0.25,0.75,0
0,0,1
0,0.25,0.75
0,0.5,0.5
0,0.75,0.25
0,1,0
Scoring
This is code golf; shortest code in bytes wins. Standard loopholes apply. You may use any built-ins desired.
[1,2,3]/6
? \$\endgroup\$