Welcome to Fractal Forums

Fractal Math, Chaos Theory & Research => Theory => Topic started by: Mircode on February 19, 2010, 12:57:09 PM




Title: Matrix multiplication instead of spherical coordinate system
Post by: Mircode on February 19, 2010, 12:57:09 PM
Hi there!

When I first saw the Mandelbulb I got really fascinated, so I started to read all about it on the page by Daniel White. I found that the idea was pretty cool and I started to think about the formula. Then an idea came to my mind.

When I took a look at this forum here I saw that godzillions of variations already exist but I'm too lazy to look them through to see if someone already had this idea. But on the other hand, I dont want it to be lost, so I'll post it anyway.

Basically I thought that there must be a possibility to get rid of the inhomogeneity of a spherical coordinate system that is taken as a basis here.
I hate the standard spherical coordinate system. If I explained why I'm afraid I'd use mathematical terms like "singularity" wrongly. And I fear that my approach uses this coordinate system, too. In a way. But enough blabla.

So here my idea:

Instead of doubling these angles in a spherical coordinate system like that

double yang = atan2(sqrt(x*x + y*y) , z);
double zang = atan2(y , x);
newx = (r*r) * sin( yang*2 + 0.5*pi ) * cos(zang*2 +pi);
newy = (r*r) * sin( yang*2 + 0.5*pi ) * sin(zang*2 +pi);
newz = (r*r) * cos( yang*2 + 0.5*pi );

we could use rotations in relation to local coordinate systems, best describable by matrix multiplications i guess.

First we go from (1,0,0) to the point we want to rotate (yellow). But we rotate the coordinate system with us. Step one is around the x-axis by phi1, step two is around the new z axis by phi2. See pic1.
Then we do these two steps again to obtain our result. See pic2.
The rest (distance from (0,0,0) and addition of C) is similar to the original idea.

EDIT: Doesnt work exactly the way I painted it, see below.

I don't know whether the resulting fractal is different from the "normal" one in any way, but my feeling tells me it's worth the try.

So I hope that someone finds the time and the motivation to implement it (I lack both) and that it is the pot of gold at the end of the rainbow that everyone looks for.  :yes:

Best wishes,
  Mirko Kunze


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: Paolo Bonzini on February 19, 2010, 03:05:09 PM
we could use rotations in relation to local coordinate systems, best describable by matrix multiplications i guess.

First we go from (1,0,0) to the point we want to rotate (yellow). But we rotate the coordinate system with us. Step one is around the x-axis by phi1, step two is around the new z axis by phi2. See pic1.
Then we do these two steps again to obtain our result. See pic2.
The rest (distance from (0,0,0) and addition of C) is similar to the original idea.

I don't know whether the resulting fractal is different from the "normal" one in any way, but my feeling tells me it's worth the try.

It most likely is.  I worked out the math for something similar using quaternions (which are simpler than matrices when you deal with rotations).  You can try using that as well.  Here is the paper describing my work:

http://github.com/bonzini/mbulb/raw/master/mbulb.pdf

It starts by defining the 2D mandelbrot set using purely-imaginary quaternions (the resulting iteration is v \leftarrow vi\bar v + c and then sees what changes in 3D.


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: twinbee on February 21, 2010, 11:33:57 PM
I might be misunderstanding here, but rotating theta then phi in a global rotation frame is the same as rotating them in reverse when using local rotation frames (i.e. phi before theta). In the end, they both produce the same standard spherical coords system (albeit rotated, or upside down etc.).


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: Mircode on February 22, 2010, 05:52:56 PM
Thanks for the answers!

@ Paolo Bonzini:
I took a quick look on your paper. It looks interesting and I think it includes my idea but I'm not sure yet. I will try to read it more carefully when I have some time.
Can I see the results somewhere?

@ twinbee:
"I might be misunderstanding here, but rotating theta then phi in a global rotation frame is the same as rotating them in reverse when using local rotation frames" I didn't know that but it became obvious when I tinkered around to describe the formula more mathematically and less graphically ;)
Please be clement with me, these "areas" of maths are more like a hobby.

Let me try to point out the difference:

The standard approach for the angles is:
Find R(\theta,\phi) so that (x_n,y_n,z_n)=R(\theta,\phi)(1,0,0)
Then calculate the new point like this: (x_{n+1},y_{n+1},z_{n+1})=R(n\theta,n\phi)(1,0,0)
But I want to suggest this: (x_{n+1},y_{n+1},z_{n+1})=R(\theta,\phi)^n(1,0,0)
(Change of the distance to 0 and addition of C are left aside here)

In MATLAB-code that would be
Code:
phi1 = atan2(x0(3),x0(2));
phi2 = atan2(sqrt(x0(2)^2+x0(3)^2),x0(1));

rotx = [ 1     0          0
         0 cos(phi1) -sin(phi1)
         0 sin(phi1)  cos(phi1) ];
    
rotz = [ cos(phi2) -sin(phi2) 0
         sin(phi2)  cos(phi2) 0
             0          0     1 ];

x1 = (rotx*rotz)^n *[1 0 0]';

EDIT: Its a little wrong, see below. But StarTrek tought me not to mess up the timeline, so I'll leave it like that in this post.


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: Paolo Bonzini on February 24, 2010, 03:45:01 PM
@ Paolo Bonzini:
I took a quick look on your paper. It looks interesting and I think it includes my idea but I'm not sure yet. I will try to read it more carefully when I have some time.
Can I see the results somewhere?

The paper does not propose new fractals, just new math to work with them, so no fancy pictures. :-)  Thanks for looking at it!


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: Mircode on March 11, 2010, 11:18:11 PM
Since noone seemed to do the work for me, I finally started to try it on my own. :P Here is now the code I used. The code I posted before was wrong. (I thought the x-Axis goes through the poles of the spherical coordinate system in the standard bulb but z does)

Code:
rad  = norm(x0);
phiz = atan2(x0(2),x0(1));
phiy = atan2(x0(3),sqrt(x0(1)^2+x0(2)^2));

rotz = [  cos(phiz) -sin(phiz) 0
          sin(phiz)  cos(phiz) 0
              0          0     1 ];

roty = [  cos(phiy) 0 -sin(phiy)
              0     1      0
          sin(phiy) 0  cos(phiy) ];

x1 = (rotz*roty)^powr * [rad^powr 0 0]' + [cx cy cz]';

The only difference to the standard-bulb is the last line.
Code:
(rotz^powr*roty^powr)     % old
(rotz*roty)^powr     % new

I dont know how to render it properly, i created a 3D-Array in MATLAB and imported it in ParaView. But I think it gives a nice first impression.

The first pic shows the fractal with powr=2 and the second one with powr=8.

All in all I'm a little disappointed by the results. I like the shape of the power-2 fractal, but its creamy like quaternion julia fractals.
The thing is, that only 2 of 3 degrees of freedom for R are determined by a point to point rotation. (rotz*roty*rotx) always fullfills that condition with any angle for rotx. I played around with it a little, it twists the whole object in an interesting way but it destroys the classic 2D fractal in the x-y-plane. And it doesnt help against the creamyness.

But still, there are some interesting areas that the resolution I used doesnt... do justice to. If someone could... I mean if someone wanted to...


Still, it was worth the try.

Greetings,
  Mirko


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: kram1032 on March 12, 2010, 12:04:41 AM
The power 2 version looks great :D


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: KRAFTWERK on March 12, 2010, 08:53:29 AM
Yes it does look interesting zoom in zoom in!  O0


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: Mircode on March 12, 2010, 11:27:53 AM
Well, I would like to zoom in. But actually I dont have time for any of this. And I am not familiar with any proper render tool. The way I did it took hours and looks ugly, compared to other 3D fractal pics. If I am right, there is no official program capable of rendering custom fractals and all the mandelbulb pics in here are created with self tinkered programs (Correct me if I'm wrong pls ;) ). I could provide the c-code for my formula, thats no big whoop. Then someone could include it into his program.

Or if there actually is a good and usable! program I could try it with that.

Anyway, thanks for the positive feedback!

Greetings,
  Mirko


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: David Makin on March 12, 2010, 01:01:49 PM
Well, I would like to zoom in. But actually I dont have time for any of this. And I am not familiar with any proper render tool. The way I did it took hours and looks ugly, compared to other 3D fractal pics. If I am right, there is no official program capable of rendering custom fractals and all the mandelbulb pics in here are created with self tinkered programs (Correct me if I'm wrong pls ;) ). I could provide the c-code for my formula, thats no big whoop. Then someone could include it into his program.

Or if there actually is a good and usable! program I could try it with that.

Anyway, thanks for the positive feedback!

Greetings,
  Mirko

*If* you're using Windows *and* you have Ultra Fractal *and* you can follow how the new class-based system for UF works you should be able to take a look at Ron Barnett's (aka reb in UF, aka fractalrebel here) 3D raytracing classes and write your own formula plug-ins for those.


Title: Fi-nal-ly!
Post by: Mircode on March 23, 2010, 02:07:33 PM
Hi there!

I killed all the bugs in my ChaosPro script and here are the results. If someone wants to play around with it, here is the script. I'm still a little disappointed and moping :P

Code:
Mandelbulb_MatRot(QUATERNION) {

parameter real bailout;
parameter quaternion juliac;
parameter int n;
parameter bool juliaMode;

real zx,zy,zz;
real zx_,zy_,zz_;
quaternion c;
real cx,cy,cz;

parameter real phix;
real r,phiy,phiz;
real cphix,sphix;
real cphiy,sphiy;
real cphiz,sphiz;
int i;

void init(void)
{
if (juliaMode) {
z=pixel;
c=juliac;
} else {
c=pixel;
z=c;
}
zx=part_r(z);
zy=part_i(z);
zz=part_j(z);

cx=part_r(c);
cy=part_i(c);
cz=part_j(c);
}

void loop(void)
{
r=sqrt(zx^2+zy^2+zz^2);
phiy=atan2(sqrt(zx^2+zy^2)+flip(zz));
phiz=atan2(zx+flip(zy));

cphix = cos(phix);
sphix = sin(phix);
cphiy = cos(phiy);
sphiy = sin(phiy);
cphiz = cos(phiz);
sphiz = sin(phiz);

for (i=1;i<n;i=i+1)
{
// Rotx
zx_= zx;
zy_= cphix*zy - sphix*zz;
zz_= sphix*zy + cphix*zz;

// Roty
zx = cphiy*zx_ - sphiy*zz_;
zy = zy_;
zz = sphiy*zx_ + cphiy*zz_;

// Rotz
zx_= cphiz*zx - sphiz*zy;
zy_= sphiz*zx + cphiz*zy;
zz_= zz;

zx=zx_*r;
zy=zy_*r;
zz=zz_*r;
}

zx=zx+cx;
zy=zy+cy;
zz=zz+cz;

z=quaternion(zx,zy,zz,0);
}
bool bailout(void)
{
return(zx*zx+zy*zy+zz*zz <bailout);
}

void description(void)
{
this.title = "Mandelbulb - Matrixrotation";

bailout.caption = "Bailout Value (^2)";
bailout.default = 4.0;
bailout.min = 1.0;
bailout.hint = "Defines the bailout radiusē: As soon as a pixel falls outside a circle with this radius, the iteration stops.";

juliac.caption="c";
juliac.default=(0.3,-0.44,-0.57,0.3);
juliac.hint="Parameter for Julia fractal";

juliaMode.caption="Julia Mode";
juliaMode.default=false;
juliaMode.hint="If checked, Julia mode is enabled, otherwise Mandelbrot mode";

n.caption="Power";
n.default=3;
n.min=2;
n.hint="Power";

phix.caption="Modification rotx";
phix.default=0;
phix.hint="Defines the x-angle of the rotation matrix";

}
}

But I already have another idea :)

Greetings,
  Mirko


Title: Re: Matrix multiplication instead of spherical coordinate system
Post by: Mircode on March 23, 2010, 02:39:06 PM
Here a Julia pic