k.. back to this:
Given I don't understand how your spheric works (explanation?
)
Square part (not whole cube!) that "squares the circle" on the x axis (click to enbiggen):
The rest can be worked out from the
inverse functions page on Wikipedia, or you can do it geometrically with the Pythagorean theorum...
(theta= atan2(y/x) if you're doing the inverse function thing! I can explain it further later, if you want)
...... Continued...................................................>>>>>> UPDATE... a bit of math was wrong.
fixed.. or not.
UPDATE... sheesh.. I deleted the wrong thing in the last update.. anyway. If the math is STILL wrong.. you'll notice.
You can look at the inverse functions on wikipedia, and see how I got from the above to the equations I used, or you can do it geometrically.
tan theta = opposite/adjacent = z/y
You can see in the drawing, that r is the length of the bottom of the right triangle that is r tan(theta) high. The smaller triangle has a height of r sin(theta).
We are interested in the ratio between the 2 triangles, to either stretch from the circle to the square, or stretch from the square to the circle. The ratio of one hypotenuse to the other is the same as the ratio of one side to another, etc. so we use the ratio of tan(theta)/sin(theta)= 1/cos(theta) for our calculations, as long as it is in the correct quadrant!
In the above image, if the tangent is past the corner of the square, you need to flip y and z in your calculations. It actually is a more general formula for creation of polygons from circles, the square one is just the simplest, because you don't have to do more complex rotations. For some reason, I think Knighty did something similar with his cutting formulas.
To make a circle into a triangle, you need to divide it into 3 sections and do basically the same thing....
//combine with tubular
void polygonator (inout vec3 z) {
float rCyz=(atan(z.z,z.y));
float i=1.;
while (rCyz>pi/sides && i<sides) {rCyz-=2.*pi/sides; i++;} //define pi and sides outside.
while (rCyz<-pi/sides && i<sides) {rCyz+=2.*pi/sides;i++;} // sides = 3 for.. triangle.. :D
z.yz*=cos(rCyz);
// if we really want to do this right, we need to pick a part of the fractal with reflective symmetry
// to "divide" from... the above while loops just split it at pi (180 degrees).. which is basically fine
}
void Tubular (inout vec3 z) { //tubular actually transforms a square to a circle, but since I did it on 1 axis of a 3d system...
float rCyz= (z.y*z.y)/(z.z*z.z);
if (rCyz<1.) {rCyz=sqrt(rCyz+1.);} else {rCyz=sqrt(1./rCyz+1.);}
z.yz*=rCyz;
}