Logo by mclarekin - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Did you know ? you can use LaTex inside Postings on fractalforums.com!
 
*
Welcome, Guest. Please login or register. January 16, 2019, 04:03:22 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Circle2Square  (Read 886 times)
0 Members and 1 Guest are viewing this topic.
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« on: November 08, 2015, 09:02:19 PM »

k.. back to this:

Given I don't understand how your spheric works (explanation? cheesy )
 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. cheesy  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....

Code:
 //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;  
}
« Last Edit: November 09, 2015, 06:39:33 PM by M Benesi » Logged

DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #1 on: November 08, 2015, 11:56:33 PM »

Now it is very clear
Thanks Matt...
And I reccomend you - always post m3f files in the same thread or I am not finding them. Please... smiley keep the topics separed. Do not force me to move topics all the times. A Beer Cup
Luca
Logged

No sweat, guardian of wisdom!
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #2 on: November 09, 2015, 12:41:08 AM »

Now it is very clear
Thanks Matt...
And I reccomend you - always post m3f files in the same thread or I am not finding them. Please... smiley keep the topics separed. Do not force me to move topics all the times. A Beer Cup
Luca

  Apologies... again.  I am quite scatterbrained at times. 
Logged

mclarekin
Fractal Senior
******
Posts: 1739



« Reply #3 on: November 09, 2015, 04:02:50 AM »

@M.Benesi

Thanks for the detailed explanation, it is interesting to see how you do it smiley afro
Logged
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #4 on: November 09, 2015, 07:34:44 AM »

Thanks.  It's useful for me too.. consolidates ideas.  And I'll forget, and be able to look later. cheesy
Logged

DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #5 on: November 09, 2015, 12:47:57 PM »

Splitted to be more visible  wink A Beer Cup
Logged

No sweat, guardian of wisdom!
mclarekin
Fractal Senior
******
Posts: 1739



« Reply #6 on: November 11, 2015, 08:32:10 AM »

I started coding but then came across this   "z.yz"  which seems not to work in C++.  How is it defined? And what computer language are you using?

Code:
Description:
Warps a cube to a sphere; transform made by M.Benesi, optimized by
Luca.


// spheric code
Cvector3 temp = z;
z *= z;
double rCyz = z.y / z.z;

double rCxy z= (z.y + z.z ) / z.x ;


if (rCyz < 1.0) rCyz = sqrt(rCyz + 1.0);
else rCyz=sqrt( 1.0 / rCyz + 1.0);

if (rCxyz < 1.0) rCxyz =s qrt(rCxyz + 1.0);
else rCxyz=sqrt(1.0/ rCxyz + 1.0);

z.yz *=rCyz;


z *= rCxyz/sr32;
Logged
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #7 on: November 11, 2015, 09:25:17 AM »

In other words multiply y and z by rCyz.
It is glsl smiley
Logged

No sweat, guardian of wisdom!
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #8 on: November 11, 2015, 09:55:18 AM »

@mclarekin you need some vector classes, your math libs should have some, search for vector.h
Fragmentarium-Source/SyntopiaCore/Math/ has vector and matrix classes, Qt provides really nice ones with lots of builtin functions.
iirc there should be one out there for doing GLSL style math in C++
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
mclarekin
Fractal Senior
******
Posts: 1739



« Reply #9 on: November 11, 2015, 10:26:54 AM »

Thanks guys grin

@ DarkBeam, i guessed it might be that, and useful to know.  GLSL looks quite similar to C++, good. smiley

@3dickulus.  Never needed ( or seen ) this type of vector before.  I rely on real programmers (Buddhi and Sebastian)  to do anything more difficult than an  if() statement. LOL

 But I am learning more and more each day, generally though fixing my mistakes.  grin

BTW I now have some comprehension of the massive amount of time and thought that has gone into  creating  and upgrading these programs.   A Beer Cup A Beer Cup A Beer Cup A Beer Cup
Logged
visual.bermarte
Fractal Fertilizer
*****
Posts: 355



« Reply #10 on: November 11, 2015, 02:47:08 PM »

z.x is the first element of z vector, also written as z[0]
z.y is the second element of z vector, also written as z[1]
z.z is the third element of z vector, also written as z[2]

Swizzling is done using the dot operator and it is an handy way to manipulate vectors's elements, for example having
vec4 z = vec4(0.0, 0.9, 0.1, 0.0);
one could write
vec3 j = z.xyz;
and j would be equal to
vec3(0.0, 0.9, 0.1);

j[0] would be float(0.0)
j[1] would be float(0.9)
...
writing j or j.xyz wouldn't be different.
« Last Edit: November 11, 2015, 09:00:20 PM by visual.bermarte » Logged
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #11 on: November 11, 2015, 09:05:07 PM »

@mclarekin google search "GLSL style math in C++" and you will find exactly what you need.
Some of these are "header only" implementations so no binary libs needed to link with your program.
It's as easy as #include somemathlib.h and you will have access to features visual.bermarte describes plus more.
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
mclarekin
Fractal Senior
******
Posts: 1739



« Reply #12 on: November 11, 2015, 09:14:44 PM »

Thank you guys

Swizzling (appropriate name smiley)  is very useful to know about A Beer Cup A Beer Cup A Beer Cup"

I will google "GLSL style math in C++"

Logged
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #13 on: November 11, 2015, 11:32:55 PM »

Offhand, does anyone know what I should scale x by to make the tetrahedron generated by the following regular?  I'm thinking sqrt(2):


Code:
void fullpolytest (inout vec3 z) {  


float  rCyz=(atan(z.z,z.y));
float i=1.;
if (samesides) {   //lock number of sides between this and the other section below- so both use sides2 variable....
while (rCyz>pi/sides2 && i<sides2) {rCyz-=pi2/sides2; i++;}
while (rCyz<-pi/sides2 && i<sides2) {rCyz+=pi2/sides2;i++;}
} else {
while (rCyz>pi/sides && i<sides) {rCyz-=pi2/sides; i++;}
while (rCyz<-pi/sides && i<sides) {rCyz+=pi2/sides;i++;}
}
z.yz*=cos(rCyz);
i=1.;
if (sides2==3) { // for the tetrahedron... it was skewed, need to make it regular  
z.x/=sqrt(2);     // square root of 2 appears correct... and it makes a bit of sense, but I'd like confirmation
// of the math...
}
float  rCxyz= atan(sqrt(z.y*z.y+z.z*z.z),z.x);
i=1.;

while (rCxyz>pi/sides2 && i<sides2) {rCxyz-=pi2/sides2; i++;}
while (rCxyz<-pi/sides2 && i<sides2) {rCxyz+=pi2/sides2;i++;}
z*=cos(rCxyz);
//  this is the spheric part... need it because the above transform is for sphere to polyhedra
rCyz= (z.y*z.y)/(z.z*z.z);
rCxyz= (z.y*z.y+z.z*z.z)/(z.x*z.x);
if (rCyz<1.) {rCyz=sqrt(rCyz+1.);} else {rCyz=sqrt(1./rCyz+1.);}
if (rCxyz<1.) {rCxyz=sqrt(rCxyz+1.);} else {rCxyz=sqrt(1./rCxyz+1.);}

z.yz*=rCyz;  
z*=rCxyz;  
}
Logged

mclarekin
Fractal Senior
******
Posts: 1739



« Reply #14 on: November 12, 2015, 12:50:29 AM »

These examples  use mainly the Benesi cube to sphere transform until bailout.   That is probably not how this will be used best, but demonstrates  that even with a very  heavy influence of this transform, reasonably good image quality can be obtained . Cool.   Images are pure cubeSphere, Menger,  T1 and  PineTree.

Yet another great additional tool for fractal explorers from the Benesi Transform factory grin A Beer Cup A Beer Cup A Beer Cup


* cube to spheric.jpg (236.96 KB, 2367x589 - viewed 211 times.)
Logged
Pages: [1] 2   Go Down
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.103 seconds with 27 queries. (Pretty URLs adds 0.006s, 2q)