Welcome to Fractal Forums

Fractal Math, Chaos Theory & Research => (new) Theories & Research => Topic started by: Roquen on June 19, 2013, 09:38:42 AM




Title: Do quaternions need revisiting?
Post by: Roquen on June 19, 2013, 09:38:42 AM
This is a split from this THREAD (http://www.fractalforums.com/new-theories-and-research/triplex-math-you-know-what-i-think-of/).

Okay, let me repeat myself: I know pretty much nothing about fractals.  I'm very quickly tossing this together because I'm on vacation at the end of the week and rather throw out something potentially with mistakes and without any deep thought because...well I don't mind proving I'm an awesome dude.  I'm not claiming that any holy grail is contained within quaternions, but from what I've seen...it really seems like they should be revisited.  Oh yeah, I've a thick skin so feel free to mock me if you should feel so inclined. Esp. if all of this is old hat and dead ends.

Quaternions were quickly marginalized for a number of reasons.  The first being that Hamiltion and Tait were mostly interested in the pure mathematics side and didn't focus on applications.  While Gibbs and Heavyside took what they consider to be interesting about quaternions and formulated vectors and stuck to application.  Second is that quaternion notion pretty much sucked, while vector notation was pretty clean.  Then the two camps started the 19th century version of a flame war.  Some fun quotes came out of that, but it certainly didn't help the quaternion camp, who came across as crackpots.  But IMHO the real problem was:  they weren't what people expected.  Complex number have two values, quaternions should have three...what's that all about?  If you directly translate some complex valued function into quaternions...you don't get what you expect.  And that's my point about this seeming aside.  If you take a complex equation simply replace complex with a quaternion...you're probably not getting what you think you are.  Hamilton fell into this trap.  In C a (scaled) rotation about the origin is: p' = rp.  Although Cayley (of linear algebra fame) formulated a generalized unscaled 3D rotation pretty much straight away: p' = rpr-1 and scaled rotations: p' = rpr*..Hamilton resisted these equations for about 10 years.  Jump to today the situation hasn't improved all that much.  Quaternion literature pretty much blow chunks.  The only reasonable paper that comes to mind is an old raytracing new post by Shoemake.  So if there actually is anything of vague interest in here, then I suppose it's because the literature has failed us.

Forgive me in advance for my brain-dump style.  Jumping back to C.  I'll write a complex number as a pair of real values: (x,y)

p' = p2 + c, with c = p0

While this isn't a linear transform globally, it can be viewed as one locally:

p' = rp + t

is a scaled rotation by 'r' followed a translation by 't'.  Where we're simply interpreting 'p' is multiple ways.  So within an infinitesimal region around p we have a linear transform and as we move further way we, speaking loosely, the transform is local feature preserving (I'm not convinced that conformal mapping is required). Expanding things out we have:

p = (x,y), then p' = (x2-y2, 2xy) + p0

which the programmer in me can't help but note that this form leads to catastrophic cancellation and should be reformulated as (probably doesn't make a bit of difference):

p2 = ((x+y)(x-y), 2xy)

Although the explicit representation of complex number is in the form (x,y), it can be viewed to implicitly represent: m(cos(t), sin(t)), where m is the magnitude (m>=0) and t is the torque minimal angle (-pi > t >= pi) with respect to the positive x direction. Other than addition, the action of operators are more clear in this form. Notice that in C a direct represenation of a point and the scaled rotation of (1,0) to that point are identical.

Side-stepping to principle powers, with p = m(cos(t), sin(t)), then:

pr = mr(cos(rt), sin(rt))

Ok, I'm even starting to bore myself so I'll move on.  I saw someone ask: "Isn't this feature mirrored about the x-axis?".  If you use the basic form above, without any extensions this must be true for all points.  Reasoning:  For all points p above the x-axis are a corresponding mirrored points p* and:

(p*p* + c*) = (p2 + c)*

Now for an observation that I haven't seen mentioned:  Folding about the y-axis is related to squaring and can be expressed algebraically as:

(p2)1/2

Of absolutely no interest computationally, but could be useful in reasoning.  And since you can fold about one line, via transforms you can fold about any.  I haven't thought this through, but it seems like this should generalize to any norm-like formulation:

(pr)1/r = m(cos(s), sin(s), where s = (t % (pi/r))

I doubt that there's much use of this since the domain is getting reduced, well for r > 1.  And the root can be dropped for (informally) similar results and I'd guess 'n' way symmetry for integer n.

Back to quaternions and I'll quote myself from the original thread:
Quote
... I can say with a reasonable certainty that all of quaternion based fractals I've seen are based on analytic functions over quaternions.  Regardless the complexity of a given analytic function, the result will be Complex (as in literally) and therefore bound to a plane (and that's a good thing)

I'll write a full quaternion as (s, (x,y,z)) where 's' is the scalar and (x,y,z) is the bivector.  If the scalar is zero, I'll simply write (x,y,z).

In my geometric interpretation of the equation in C we're performing a transform: scaled rotation + translation, where the rotation and translation are both interpretations of the point.  One possible way to construct a similar system in H would be:

p' = qpq* + p0

Notice that p, p' and p0 are all bivectors only (pure quaternions in traditionally speak) so explicitly there are only three components in this formulation.

So the question becomes, what's 'q'?  A first guess could be the quaternion which rotates some unit magnitude point in some reference direction, say r = (1,0,0) into p = (x,y,z). Or:

p = qrq*, so q = sqrt(pr*) = sqrt(x,(0,-z,y)) = sqrt((dot(r,p), cross(r,p))

which reduces to:

p' = qpq*+c = (x2-y2-z2, 2xy, 2xz)+c

compare the form to what we would have got by calling p = (x,(y,z,0)):

p2 = (x2-y2-z2, (2xy, 2xz,0))

Which was my initial purpose.  To translate an equation which generates a surface of revolution (SOR) of the Mandelbrot out of a formulation in C into a logical equivalent in H using geometric operations instead of a direct translation.  So one possible answer the the question "How do we perform the equivalent of squaring in 3D?" in quaternion speak (which extends to say Clifford/Geometric algebras for instance) is:

qpq* where q = sqrt(pr*).

The result squares the magnitude of 'p' and doubles the torque minimal angle with respect to the direction 'r'.

Now there's no reason why 'r' needs to be fixed for all points, nor that it remain fixed across iterations as long the scheme results in sufficient increase of angles globally to get the required folding like effect.  Nor is there any particular reason why the translation couldn't be transformed across iterations and/or pre transformed at the start.  Also instead of directly representing a point it could be implicit and at iteration step the total rotation is the value being updated and the point is simply a temporary.  I'd guess this would be a more promising route...but I'll ignore that and these other additional ideas for the moment.

To not be a SOR requires a non-analytic function..or more simply that all points cannot remain in the complex plane in which they began.  The simplest thing would be just to reflect about an axis through the origin.  So taking the above and toss in a reflection after each rotation:

p' = (x2-y2-z2, 2xy, -2xz)+c

Now this is an obvious thing to try anyway, so I'm sure this isn't too interesting and I'd guess locally it looks like a SOR.  Simply hitting the side with a hammer each turn of the lathe isn't going to change the result all that much.

OK..that's enough garbage to spew in case all of this is old hat.  Oh yeah, and on review for obvious errors I see that my "tone" here sucks and I can't be bothered to rewrite...so really feel free to mock me.

(EDIT: folding stated wrong axis and fixed a couple of spelling mistakes)





Title: Re: Do quaternions need revisiting?
Post by: cKleinhuis on June 19, 2013, 10:46:05 AM
a few comments:

- we have LATeX Installed here, might come in handy for more complex formulations
- nice formulations of the complex multiplication, one thing to add: the scaling/rotation is kommutative, seems obvious, but actually really is ;)
- the whole approach formulating it using transformations, and the correct transformation to Q is reasonable, as far as i understood
you have defined the complex multiplication for quaternions using the transforms, that is nice, have not fully understood it, how you define
the rotation angle/axis for the third component
- furthermore you gave a formulation just using mirroring/folding for the complex multiplication?

so, question is: HOW DOES IT LOOK LIKE ?  :D


Title: Re: Do quaternions need revisiting?
Post by: Roquen on June 19, 2013, 02:47:29 PM
LaTeX: check.

q = m(cos(t), sin(t)U), where U is a unit bivector is a counter-clockwise 2t radian rotation about the line through the origin in direction U and a uniform scaling of m2.  (using qpq*)  Note that like complex, log(q) = (log(m), t U)
and exp reverses, but normal identities don't hold since in general since the product doesn't commute.

WRT: reflection...in quaternions? or complex?

What does it look like?  I don't have the knowledge base to develop anything...I'm just attempt to toss out two possible frameworks which I naively expect to be able to create a variety of results.  When I first looked at mandelbulb I was guessing that it was a reduction of some quaternion based equation.  On second glance it's not obvious what the translation would be..but I haven't thought about it much.  Notice that the quadratic formula from wikipedia matches my expansion above and the cubic a double application of 'q'.

If I had time to experiment I'd try this, with m = \sqrt{x^2+y^2+z^2}

x' = \frac{x^2 \left(3 y (m+y)-z^2\right)-\left(y^2+z^2\right) \left(y (m+y)+z^2\right)}{y(m+y)+x^2+z^2}

y' = -\frac{x \left(x^2-3 y^2+z^2\right)}{m}

z' = \frac{x z \left(4 m y+x^2+5 y^2+z^2\right)}{y (m+y)+x^2+z^2}

The translation needs to be added in.  Which if I didn't screw up (I just spewed it out of mathematica) is simply SOR as above followed by doubling the angle with respect to (0,1,0) but without scaling this time. I just pulled this out of my bum to give some example.

Other thing I'd try would be choosing a reference direction per point.  So a projection and normalizing or choosing the closest direction from some finite set.  It seems like there should be tons of options.



Title: Re: Do quaternions need revisiting?
Post by: Roquen on June 19, 2013, 03:05:11 PM
That equation was dumb...forget I said that.


Title: Re: Do quaternions need revisiting?
Post by: Roquen on June 20, 2013, 10:20:37 AM
Since I've only been looking at equations in Mathematica, I decided to verify the the base of what I was saying was...ya know..correct:

http://glslsandbox.com/e#9541.0

Renders 2D slices of the basic SOR form above.  There's a variable 'center' which does the stupidest thing possible...changes the center of rotation away from the origin.  Nothing interesting can result from this but I figured showing something visual was better than nothing.  SOR-like, but I knew that going in.  Tweek the scale factor and location of center.


Title: Re: Do quaternions need revisiting?
Post by: cKleinhuis on June 20, 2013, 11:51:01 AM
hmm, i cant see a difference when changing the "center" variable


Title: Re: Do quaternions need revisiting?
Post by: Roquen on June 20, 2013, 12:00:03 PM
My guess is that you didn't change the scale (the 0.0) multiplier on the outside.


Title: Re: Do quaternions need revisiting?
Post by: Roquen on June 20, 2013, 05:49:13 PM
Just another SOR, but kinda fun: http://glslsandbox.com/e#9541.1

Like before using the center of rotation is disabled at startup.


Title: Re: Do quaternions need revisiting?
Post by: Roquen on July 11, 2013, 11:17:56 AM
One thing I should have noted is that the quaternion doubling equation (like the complex) should probably be reformulated to avoid cancellation.  So here are the three transforms in positive axial aligned directions expanded out and reformed:

Positive X: (x,y,z) -> ((x+y+z)(x-y-z)+2yz, 2xy, 2xz)
Positive Y: (x,y,z) -> (2xy, (x+y+z)(y-x-z)+2xz, 2yz)
Positive Z: (x,y,z) -> (2xz, 2yz, (x+y+z)(z-x-y)+2xy)

Before I can start goofing around in 3D I need to figure out what framework to use (I'm too lazy to make one from scratch or use one that required me creating an analytic derivative for each formulation).  So I goofed around in complex for fun (aka work-avoidance):



Title: Re: Do quaternions need revisiting?
Post by: kram1032 on July 11, 2013, 11:39:39 AM
Is there supposed to be an image after "work-avoidance):"?
Because I don't see one...


Title: Re: Do quaternions need revisiting?
Post by: Roquen on July 11, 2013, 11:52:49 AM
That's because I cleverly clicked post instead of preview.

WebGL examples.  All of these support zooming and panning via mouse.  Some of the later one can have large extents depending on mouse position so zooming out might be needed.  Change the sample size down to either 1 or .5 depending on your GPU.

1) power-2 mandelbrot with rotation not about origin (c = mouse position) HERE (http://glslsandbox.com/e#9903.0):
p' = (p-c)2 + c + p0 = p2 - 2cp + (c+c2) + p0

expanded out there are 3 logical translation terms, last is classic Mandelbrot, the grouped (c+c*c) is Julia, since 'c' is a constant and finally the -2cp term.

2) Same as (1) plus a constant rotation 'r' per iteration (animated in time):  HERE (http://glslsandbox.com/e#9904.0):
p' = r(p-c)2 + c + p0

3) Doubling with respect to two directions per iteration (animated in time):  HERE (http://glslsandbox.com/e#9915.0)

4) Like (3) but one is not through the center (again mouse position): HERE (http://glslsandbox.com/e#9916.0)

5) Peforms a kaliset like fold (abs of both components) prior to Mandlbrot style: HERE (http://glslsandbox.com/e#9916.1)

6) Like (5) but only performing abs on the x-component: HERE (http://glslsandbox.com/e#9925.0)


Title: Re: Do quaternions need revisiting?
Post by: kram1032 on July 11, 2013, 03:39:17 PM
those are some beautiful examples :)


Title: Re: Do quaternions need revisiting?
Post by: Roquen on July 12, 2013, 03:13:17 PM
Thanks - quickly hacked them to basic orbit coloring.
http://glslsandbox.com/e#9903.1
http://glslsandbox.com/e#9904.1
http://glslsandbox.com/e#9915.1
http://glslsandbox.com/e#9916.2
http://glslsandbox.com/e#9971.0



Title: Re: Do quaternions need revisiting?
Post by: Roquen on August 01, 2014, 03:43:34 PM
I had a fair number of things to say when I started this thread but keep not have enough free time to type them in.  So I guess I'll breaking into yearly installments. ;)

On quaternions I've shown how to formulate the same boring results except that they are now restricted to 3D instead of 4 and are formulated as a generalized rotation.  Boring surface of revolution.  My next intended step was to boringly repeat the same thing under different constructions.  Instead of rotating we scale and manipulate the angle by transforming to a complex plane.  Example double wrt X:  transform P to a complex plane (PX*).  double the angle and square the magnitude by squaring (PX*)2 and transform back to where we started:  (PX*)2X.  Expand this an you get the same results above and likewise for any chosen preferred direction.  Also since quaternion multiplication doesn't commute we can perform the transform/reverse-transform pair on the opposite side, so (PX*)2X = X(X*P)2.

And a third way to do the same thing is to think of the point as being the transform being applied to a point at unit distance in the preferred direction:  PXP* = P*XP is the same as the wrt X doubling above.

Maybe next year I'll type something almost interesting.


Title: Re: Do quaternions need revisiting?
Post by: Alef on August 01, 2014, 06:10:20 PM
Quaternions needs not only need being revisited, quaternions need dissapier :evil1:


Title: Re: Do quaternions need revisiting?
Post by: Roquen on August 01, 2014, 07:28:55 PM
Perhaps so.  Even probably so.  But as far as I can tell nobody's really explored them in any meaningful way.


Title: Re: Do quaternions need revisiting?
Post by: kram1032 on August 04, 2014, 11:07:21 AM
Quaternions were explored plentifully in all kinds of research. However, thus far it was not game-changing research that has gotten a lot of fame, other than the first invention of Quaternions and the initial flood of followup papers.

It doesn't help that they seem to sort of come "out of nowhere". - Until you construct them as a part of R³-Geometric Algebra, representing the three bivectors, which, to me, feels way more natural.
And there has been plenty of reformalization work translating typical Tensor Algebra into Geometric Algebra.
Just, again, not a whole lot of inventive work.
It's a bit of a race: You kind of need to reach the state of the art in both formulations to get to the parts where inventions can actually be done. But meanwhile, the Tensor approach keeps expanding.
Translational work is much faster than inventive work, of course. However, there also are a lot fewer people focusing on that kind of work.
Still, I think, overally, Geometric Algebra is catching up and I expect it to, eventually, become the standard for the geometric part of the description of the physical system.
And with it, as sub-algebra, the Quaternions, however in a way less opaque manner than straight up using Quaternions.

Meanwhile, for the other half of the topology of physics and computer science and even the entirety of all maths ever, we'll probably see a new era as everything is reformulated from the messy, structure-less set-theory into the way more tractable and even computationally automatable homotopy-type-theory. At least if we can find our way past the two or so major problems that are the computational equivalent of the univalence axiom (isomorphisms are isomorphic to equality - currently, we do not know of a way how to automate reasoning with this) and recursive infinities (which would bring us a long way towards formulating HoTT as its own Metalanguage, which is kind of important, if you want to use it as the foundation of all of Mathematics. You want to reason about the foundations within the foundations. Right now, with HoTT, we have to use a different meta language to reason about HoTT itself.)
Once those difficulties are solved, we'll have a full (comparatively) comprehensive formulation of the very foundations of reality, or at least the proper tools to get there.

(Unless, of course, there are some unexpected stumbling blocks in the way, which wouldn't be a first. But we'll see about that)


Title: Re: Do quaternions need revisiting?
Post by: Roquen on August 04, 2014, 11:47:03 AM
My context isn't mathematical exploration but rather application to fractals.  Mathematically, like complex, their treatment in historic context doesn't help understanding. And they're actually frequently discussed in an impossible to understand way as most author punt to using linear algebra.  Taking a Clifford algebra perspective both are certainly much easier to understand.


Title: Re: Do quaternions need revisiting?
Post by: David Makin on August 06, 2014, 12:04:10 AM
The problem with respect to quaternionic fractals is that they lack the main attribute of a true 3D or 4D fractal i.e. the surface of the "Set" is not fractal in all directions, even on the Julias.


Title: Re: Do quaternions need revisiting?
Post by: Roquen on August 06, 2014, 10:56:13 AM
This is exactly what I mean.  All analytic functions are quaternions must be boring as they are all surfaces of revolution since they are really 2D systems embedded in a 4D space.  No projections of an analytic function can be interesting.


Title: Re: Do quaternions need revisiting?
Post by: Roquen on August 07, 2014, 01:07:52 PM
Mandelbulb is an ad-hoc system built on manipulating angles in spherical coordinates.  To construct a spherical coordinate system in 3D you arbitrary choose a reference plane and a direction within that plane.  Say the XY plane through the origin and the X axis.  Then the first angle is the point in question projected into the plane and the angle formed with the X axis (azimuth).  The second angle is the remaining part out of the plane which can be measured in a number of ways, such as with respect to the positive Z axis (zenith angle) or the angle formed with the plane (inclination).  The last part of information is of course the magnitude of the vector to the point.

The two major flavors of Mandelbulb appear to be these:

Code:
vec3 mbulbAI(vec3 p, float m, const float n)
{
  float a = atan(p.y, p.x); // on [-pi, pi]
  float i = asin(p.z/m);    // on [-pi/2, pi/2]
 
  // scale the angles and magnitude by power
  i *= n;
  a *= n;
  m = pow(m, n);
 
  // convert back to Cartesian.
  return m*vec3(cos(i)*cos(a), cos(i)*sin(a), sin(i));
}

Code:
vec3 mbulbAZ(vec3 p, float m, const float n)
{
  float a = atan(p.y, p.x);  // on [-pi, pi]
  float z = acos(p.z/m);     // on [0, pi]
 
  // scale the angles and magnitude by power
  a *= n;
  z *= n;
  m = pow(m, n);
 
  // convert back to Cartesian
  return m*vec3(sin(z)*cos(a), sin(z)*sin(a), cos(z));
}

All spherical coordinates can be also thought as a system which takes a predefined reference position on the unit sphere followed by a pair of rotations in a predefined manner and a uniform scaling.

AI: ref-point {1,0,0}, rotate -Y by i, rotate Z by a, scale
AZ: ref-point {0,0,1}, rotate +Y by z, rotate Z by a, scale

Now it's obvious that these two systems are trivially equivalent, say via trig identities or by observing rotation -Y is same as by Y and negating the angle and moving the reference from in Z to in X by adding pi/2.  Of course these are the same since asin(x)+acos(x)=pi/2.

The above reference point, rotation and scaling view-point hopefully sounds familiar because that's one view point I gave above for quaternion formulations.

Taking AI, the first rotation is ry = sin(i){0,-1,0}+cos(i), rz=sin(a){0,0,1}+cos(a).  These are for rotations of 2i and 2a.  The combined is r = rzry = {sin(a)sin(i), -cos(a)sin(i), cos(i)sin(a)} + cos(a)cos(i)

Okay..enough for now.