Mike Burr - log

[math][comp] Triangles

Begin with a unit line on the Y axis, centered on the origin.

Your function is passed an index, []. your function is to return rational 3D coordinates. Add two lines from this point: one to each end of the initial unit line.

We now have a triangle.

Now you are standing on the initial unit line looking in the direction of positive X. Positive Z is "up" for you. You therefore have a right (negative Y) and a left (positive Y).

Rotate at your feet, pivoting on the Y axis until the plane of the new triangle is in front of you. First you go left.

Your function is now passed an index of [left] and returns a point with which we make a new triangle using the same steps as before.

We now have two triangles that share a side.

Now you go to your right, passing in [right] and receiving another triangle.

We can also pass [left, left] to your function to get the triangle to the left of the second triangle we created.

Each value in the array represents a unique side in our emerging shape.

Your function walks the index (left/right) array it is passed and emits a new triangle. Internally it can do whatever it wants, but it must return a rational 3-point for each unique index (array value).

If a point produced by your function is the same as a preexisting point, draw the remaining line (if necessary). This ends branches in your left/right tree.

If you provided a cool function, you now have a shape.

Since all values are rational and your function is required to only operate on rational values, there is hope for shapes to close.

This can also be applied to n-gons, using an index instead of left/right.