An N sided polygen, can be made in thefollowing:
Multiply the vector [x, 0, z] by a suitable function which is ONE in the directions 0, 2PI/N 4PI/N up until 2PI,
and a value greater than one in the middle directions, and clamp to a given radius.
This function can be calculated as:
v = atan2(x,z) (v is the angel from the origin to x,z)
q = mod(v, 2PI/N)
w= cos(q - PI/N)/cos(PI/N) (w is the above function)
The atan2(x,z) function is not implemented in TG2, but if you searh for atan2, you can
see some implementations in TG2.
In case of the pyramid, this can be reduced to:
The vector [x, 0, z] can be rewritten as V = [R*cos(v), 0, R*sin(v)] (R is the distance from origin to the point x,z)
Use symmetri by take the abs vector.
The functions above can then be written as:
v = Arccos(x/R)
q = mod(v, PI/2) = v (since we work in first qudrant, limited by the abs function)
w = cos(q - PI/4)/cos(PI/4) = cos(v-PI/4)/cos(PI/4) = [cos(v)cos(PI/4) + sin(v)sin(PI/4)]/cos(PI/4) = cos(v) + sin(v)
multiply this the Length of V you get: tranformed distance = R*cos(v) + R*sin(v) = x + y = 1*x + 1*y (this is where the dot function come into play)
and clamp this to the wanted radius, and you have an inverted pyramid.