## Thursday, July 13, 2017

### general relativity

When you toss a coin, the coin falls down because there is more time at lower altitudes, and time passes slightly more slowly. If we plot altitude against time on a sheet then we expand time horizontally at lower heights, the sheet will splay outwards as shown below. A coin tossed upwards simply follows a locally straight path on this sheet, like an ant walking along it in a straight line.

Space and time don't bend into a third dimension like the sheet, the curvature is just intrinsic to the space and time. You can just think of time as being denser at lower altitudes.

The field equation of relativity holds at all points in space and time and is
where Gij is the Einstein tensor describing the bending of space-time, k is a constant and Tij is the stress-energy tensor which represents the density and pressure of matter at that point.

Gij and Tij are both 4x4 tensors (very similar to matrices) but they are symmetric and this means they represent a scaling along four orthogonal principle axes. For the spatial dimension this can be seen as stretching a sphere into an ellipsoid:

If we work in this principle inertial frame (the rest frame) then the field equation just has diagonal entries, e.g:
ρ is the density of matter and px,y,z are the pressures, which are equal in most idealised cases, such as an idealised fluid.
Scaling by k gives the Einstein tensor Gij, where each diagonal entry represents the scalar curvature of the 3D volume orthogonal to that entry's axis. For example the first entry means the 3D spatial curvature is kρ since the spatial volume is orthogonal to the time axis.

The 3D scalar curvature (or 3D Ricci scalar) is proportional to the difference between the surface area of a small sphere around that point, compared to the expected surface area of a sphere in Euclidean space. A positive scalar curvature (as is the case when mass is positive) has a smaller than expected surface area, and parallel paths converge. In the case of the first entry this means that mass causes space to have spherical curvature, like a 3-sphere.

This is the simplest explanation of General Relativity; the stress-energy tensor represents the scalar curvature of the 3D volume orthogonal to each principle axis.

### A closer look

However, this definition isn't very helpful in telling us how space-time actually distorts, since the scalar curvatures on each axis combine together in their effects. In order to get actual differential equations we expand out the field equation definition to:

where Rij is the Ricci tensor which represents the 4D curvature of space-time and R is the 4D Ricci scalar. Working in the mass's rest frame, the Ricci tensor is just a linear transform of the stress-energy tensor:

This transform can be visualised in 2D when the pressure is equal in all directions:

For any given mass and pressure of a body the blue arrows show the directions of increasing contraction with respect to time and with respect to space. Lets look at this curvature more carefully.

Each element in Rii defines the rate of change of contraction of a small orthogonal 3D volume V with respect to the element's axis.
For R00 this 3D volume is just the spatial volume (written as Vxyz):

\frac{\frac{d^2}{dt^2}V_{xyz}}{V_{xyz}}=-\frac{1}{2}(\rho+p_x+p_y+p_z)
For R11 it is a small time period t multiplied by the perpendicular area yz:
\frac{\frac{d^2}{dx^2}V_{tyz}}{V_{tyz}}=-\frac{1}{2}(\rho+p_x-p_y-p_z)
and equivalently on the other two spatial axes. This is for a volume at rest, otherwise we subtract volume acceleration in flat space from the left hand side. The negative sign is because these are contractions.

So far we have used normalised units where the speed of light is 1, this is equivalent to using light-seconds (300,000 km, or distance to the moon) as the measure of distance. So for standard units the mapping looks more like:
In other words, effects are mostly due to mass density rather than pressure, and this produces mostly spatial volume contraction with respect to time, rather than significant changes over space.

### Example of earth:

Earth's mass is 6e24 kg and volume 1e21 m^3, so its density is: 6,000 kg/m^3
average pressure = 200e9 Pascals

### Example of space above earth:

The Ricci tensor in space is zero. This means no volume Vxyz  acceleration with time, and no time x area (Vtyz) acceleration with distance x. This does not make space Lorentz flat, it can still bend and preserve 3-volume and that is what it does near earth:
- With respect to height, the time period of a volume expands (due to gravitational time dilation) but its width and length contract as horizontal area is slightly contracted at lower altitudes.
- With respect to time an initially static volume's height expands since gravity is slightly stronger closer to earth, but its width and length get shorter, as it moves downward where area is slightly contracted.
In both cases the expansion and contractions cancel out to give zero volume change.

This diagram shows how object move above ground, causing vertical expansion, and below ground, causing vertical contraction. In solids the pressure forces resist the inwards pull. Therefore relative to these straight yellow lines, the ground surface is accelerating upwards.

Spatial curvature is much less pronounced than curvature with time. This bend is irrespective of speed.

TODO:
2. earth is 2mm proper radius (bend) wider than if space was Euclidean
3. sun is 2km wider than if space was Euclidean, which is 6ppm (six earths) larger volume
5. are grav waves due to zero divergance constraint (which pulls 10 dofs down to 6), or due to Levi Vita connection, or the Bianchi identities?

For more details try out my cheat sheet:

## Wednesday, May 24, 2017

### diamond square fractals

I have previously worked on fractal automata which produce animating patterns in 2D and 3D. A special case of this is where only the larger scale affects the smaller scales, giving static images. One shortcoming with these automata and images is that they have square or cubic symmetry, so features are just at right angles, which gets a bit dull, this was one reason I made this cubic modification for 2D images, giving a hexagonal symmetry.

A tweet by someone called R4_Unit showed a different way to achieve a similar goal. Use the diamond-square algorithm which is used for plasma fractals and hilly height fields, but use automata rules rather than random offsets. R4_Unit applied this in 3D, and has since submitted his code here, and a user called Softology has added his own implementation to his Visions of Chaos software. In 2D the diamond-square algorithm gives a pseudo octagonal symmetry, quite similar to automata rule type 7 that I made in the 2nd link above which gave nice results:
But with a rule that is more complicated than diamond-square. The 3D diamond-square is actually cube-irregular_octahedron-octahedron and doesn't have nearly the simple symmetry of diamond-square, so here I investigate what the results look like in 2D.

For 4 parent points there are 2^4 parent combinations and the central point is either black or white for each, giving 2^16 rule sets. However, once you constrain it to square symmetry, this drops down to only 64 rule sets, which I draw using a 4x4 start grid:
0001
0010
0011
1111

And for the symmetric start grid:
0000
0110
0110
0000
five along one up seems like the 'nicest' in both cases.

For more than two colours the number of combinations explodes. One way to contain that is to demand 'bit symmetry' which in the two-colour case means the rule sets acts the same if black and white are swapped. Unfortunately it is not possible to have a two-colour bit symmetric rule with this diamond-square approach, because there are an even number of identical parents. If two parents are white and two are black then there is no child colour that acts the same if black and white are reversed.

The generalised 'bit symmetry' for n colours means the rules are the same if the n colours are permuted in any way. Then for three colours it is possible to have bit symmetric rules, and there are only three of them:
Overall the rule is to choose the most popular colour of the parent. If this is a tie, then choose the least popular. The choice occurs when there are three parent corners of a single colour. Do you choose the colour there is none of, one of or three of among the parents? The above shows each respectively.

The third is the simpler rule (as it is subsumed by the first criteria), and gives more solid results. Here is a close up of the only complex feature it seems to generate:
These teardrop shapes are all identical. While they are polygonal, each protrusion seems to have an infinite number of edges, in fact it is a tree. So each teardrop is a tree.

In fact, these are the only three bit-symmetric rule sets possible for the diamond-square algorithm for any number of colours, and none exist in 3D at all (assuming cubic symmetry), so they are quite unique.

However, a square lattice is not the only scalable lattice, the only other I know is the triangular lattice. And in this lattice bit-symmetric automata occur only with four colours, and there are only two of them:
The rule is the same as for the square lattice case, but the choice is when two of your parents are the same colour, do you choose the colour there is one of or two of? Again, the more solid results come from the latter case. It is quite a wonderful shape, with almost rounded looking blobs that belie its triangular lattice frame. These used a randomised 4x4(ish) start pattern, and here is higher resolution with an 8x8(ish) start pattern:
The rule for this and the teardrop above are incredibly simple, pick the most popular parent colour, if it is a tie then pick the least popular.

Here are three simplest cases:
The apparent fifth colour is a nowhere-dense mix of the four colours and primarily takes the shape of a modified Koch snowflake, by contrast the dense colours are all finite sided polygons.

## Wednesday, April 26, 2017

### New basic fractal curves

The three most well known 2D fractal curves are probably the Von Koch curve, the Levy C curve and the Dragon curve. They are all generated from the same simple replacement rule of one oriented line segment with two in a v-shape:
The angle of the V-shape controls how rough the resulting curve is. At 60 degrees we get:
Levy:
Koch:
Dragon:

What doesn't seem to have been described before is that there are three other fractal curves from this basic construction. In fact, since an oriented line segment can be rotated 180 degrees, reflected around its length, or both, there are four options per child line, so 16 possible fractal curves. However many just give reflected or rotated versions of the same curve, leaving just six unique fractal curves. The remaining three curves look like this, for bend angle 30, 60 and 90 degrees:

new curve 1:

new curve 2:

This has a critical point, just before it starts overlapping, at about 85.5 degrees:
new curve 3:

This last curve is especially interesting because, like the Von Koch curve, it curls into a solid triangle without any overlap, here is is at 85.5 degrees:

## Monday, January 30, 2017

### The Colour of 2D Fractals

In my previous post I began experimenting with structure on 3D fractals. After some reading it seems there are four ways in which the shape of an object can give it colour:
1. variable distance to eye causing interference on incoming coherent light
2. interference of reflected and refracted light on (semi)transparent objects
3. greater scattering of bluer light, causing a Tyndall/Rayleigh type reflected corona on a rough surface
4. if the geometry absorbs some light then the colour that causes more reflections before seeing a diffuse sky will be darker
The first only works on coherent incoming light, which only really happens with a bright sun on a non cloudy day. The second requires a refraction index and so I'll leave this for now. The third is interesting but really represents coloured corona of individual light sources, and doesn't occur on the diffuse light. so I'll focus on the fourth case..

The idea here is that when a wave reflects off some complex geometry, one can 'low pass' the geometry based on the wavelength of the light, that is, one can ignore small bits of geometry below the light's wavelength as it has little effect. An approximation of this idea for simple fractals is to just look at the red and blue light frequencies, which are roughly different by a factor of 2, and use one more fractal iteration for the blue light than the red. The fractal I'm looking at is a simple 2D replacement of one directed line by two of equal length in a v shape:

If the two child lines are pointing along the same way then it produces a Levy curve, if both are flipped around then it produces a Koch curve, and if only one is flipped it produces a dragon curve. In each case the bend angle affects the dimension, which goes from 1D to 2D as the angle approaches 90 degrees. When I talk about the colour of such a 2D fractal, I mean when looking 'side on' to the curve, not from plan view.

#### Reflection Model

I model the surface as having no transparency, and reflecting light exactly. However I include a reflectivity. If the reflectivity is 100% then all the incoming light energy should be reflected back, regardless of the number of 'bounces', and regardless of the wavelength, therefore the curve is white. If the reflectivity is 0% then the curve is black. Firstly, I will look at the case where the reflectivity is very low but the diffuse sky intensity is very high, I therefore can approximate the colour by only looking at one reflection, and not multiple. It is expected that the colour will get paler as the reflectivity increases.

The first reflection model I call the diffuse model. Each vertex of the curve calculates the proportion of sky that is visible from its position, looking only to one side of the curve. It therefore models the reflection as going in all directions (as though from a point).

The second reflection model I call the reflect model, I model each vertex and the two line segments coming from it, as a (circularly) curved mirror. The light heading towards the camera therefore comes from a uniform distribution of directions which I calculate. The light level then represents the proportion of this angular section that is not occluded by the curve.

#### Levy Curve

For each model I show the fractal of dimension 1.2D, with colours as viewed orthogonally from above. Below that I show a map of the 1D view of the fractal as seen from above (horizontal) for increasing dimension 1 to 1.5 (vertical).
diffuse model reflect model

The black areas in the top row are obstructions from the looping sections of the Levy curve, they have no colour as you are seeing the wrong side of the line (with flipped convexity too).

As you can see, the reflect model seems to give a bit stronger colour, but for both models the overall effect of the concave 'inside' of the Levy curve is a warm colour, and the convex 'outside' of the Levy curve is a colder colour, or much more neutral. It suggests concave is brown, convex is (slightly) blue. The result is also pretty much independent of the length of fractal used, or equally the chosen iteration count. It is also invariant to scaling the fractal by powers of two.

#### Koch curve

Because the Koch curve is built from subdivisions that flip direction each iteration, the shape difference at half the wavelength is is either concave or convex depending on the iteration, or equivalently the physical size of the curve. As such, and consistent with the results above, the Koch curve is either brown tinted when the difference is concave, or blue tinted when it is convex. Below I have shown the curve as viewed from above against dimension from 1 to 2 for both 9 (top) and 10 iterations, the double-resolution 10-iteration image is rescaled horizontally, so is the one with half height.
Diffuse model Reflect model

The results for both models are fairly similar, and the results are generally independent of the number of iterations. In all cases the blue Koch curve is a less strong than the brown/red sized curve, this suggests that stochastic curves will have a slightly warm colour.

#### Dragon Curve

This is the simplest case, looking the same on both sides and invariant to doubling the scale. Additionally, the overall colour varies little between the two models. Being 5% extra red at 1.2D and 10% at 1.4D. The lower images span dimension 1 to 2 vertically.
Diffuse model Reflect model

#### Random Curve

Choosing a random bend direction between (-1,1) gives a colour that is slightly red on average, about 5% more red on both models, beyond about 1.4D.
Diffuse model Reflect model

### Conclusion

Both models are very coarse approximations of wave reflection off a fractal curve, but the similarity of results across two lighting models suggests the following results are quite general and probably valid:
1. concave fractals are brown tinted
2. convex fractals are only slightly blue tinted
3. due to the asymmetry of above, random curves and dragon curves are slightly brown tinted
4. Koch curves are brown or slightly blue tinted, flipping each scale factor of two, and flipping when you look from the other side
5. these results are for the extreme case of a bright diffuse sky illuminating a curve with very low reflectance (so that we can ignore secondary reflections). Results will get paler, to white, as the reflectivity increases to 1.
6. One can carry most of these results to 3D surfaces, though I imagine that a 1+k dimensional curve will equate closer to 2+k dimensions in terms of colour.

### Coherent light

A perhaps more accurate simulation is to look at how a coherent directional light source reflects off the fractal, type 1 at the top of this post. Some work has been done on this by Jos Stam, his results indicate that the reflection goes from blue to yellow to white as the fractal roughness increases:
However, his work uses only a fractal height field, which isn't a proper fractal in that it doesn't have a simple fractal dimension. The high roughness results are unlikely to be accurate.

The approach I take is quite simple, I ignore secondary reflections (accurate if the absorption is high), from the view angle perspective, each point along the fractal that is not in shadow from the light incident angle will have a light travel distance l from light to point to eye. Each colour component (red, green, blue) is the magnitude of the sum of exp(ilf) where f is the frequency of that colour. This is simple interference; an approximation of the Kirchhoff integral.
above, the view angle and incident angle are -30 and 30 degrees respectively, and the curve is rotated to the view angle. The visible curve is that seen from the view angle and the black coloured part is in shadow. The light travel length for all the white points is used for the interference.

Unlike Jos Stam's work above, we cannot assume the integration is extended over the full curve as the curve varies everywhere. Instead we have to choose a finite width curve for the interference to act on. This finite size equates to the fact that our eyes can only resolve to a certain resolution (depending on the lens size), and features on the fractal under this 'coherence width' interfere. But this width is an extra parameter. The reflection off a Koch curve therefore has four pertinent parameters, which I map out in the image below. The first two (small coords below) are view angle (y) and incident angle (x). The third coordinate (the 8 rows) is the dimension of the curve, below it varies from 1 (top) to 1.2 (bottom). Notice that the top row is a line along view angle = -incident angle in other words pure reflection of the incoming light.

The fourth coordinate (the 8 columns) show different coherence widths from 6x red wavelength up to 48x red wavelength. In this paper the coherence width (as measured by the slit distance that causes the interfering waves to drop to 50%) is shown to go from about 7x sun's main wavelength in foggy/overcast sky to 80x on a clear day, so this corresponds quite well to the range I used.
There are clearly different colours in the reflected light, which would show themselves as glistening from a sharp light source. However, from a diffuse sky one must also integrate along any pixel row, and the overall colour on average is warm, with roughly 20% more red than blue.

Here we see an equivalent for a random curve. The profiles are a little less clear and asymmetric in the downward diagonal. But it remains the case that the average colour is similarly red-shifted.

Given the diagonal symmetry above for the Koch curve, we don't lose much by looking at just the downward diagonal (view angle = incident angle) and so we can plot the colour against just incident angle (small x) for continuously increasing dimension 1+n^2 for n=0 to 0.5, again each column is for increasing interference width:
Note that in this and the diagram above we only look at the few angles where the ray lengths on a flat surface cover an integer number of wavelengths, this prevents colour biases for these small coherence widths. This explains the small (and growing) width of each column.

As you can see, the reflections are colourful and show vertical lines that represent angles of high reflection where the angle increases with Koch dimension as expected. The lines have two properties, firstly they fade in an out, probably fading in when the continuous high reflection angle best matches the discrete displayed angles; secondly the line colour cycles through the spectrum with increasing fractal dimension, again as you would expect. Lastly the colours cycle more quickly with increasing dimension for the smaller wavelength light (columns to the right), which due to fractals' scale symmetry represents a wider coherent light wave, or more coherent light, and would give a more sensitive speckling.

The vertical lines just to the right of each column give the integration over all incident angles, so the colour of the curve if it were lit by light from all angles. It is less colourful but still varies between warm and cold, however, consistent with above, the average colour is red shifted.

The above images use very few view angles to avoid the colour bias, we can also avoid the colour bias by looking at the curve head-on, and can therefore look at a continuous increase in the colour frequency on the x axis, against increasing dimension downwards on the y axis:
Both images normalise the light wavelength relative to the 'lift height' of the curve for each dimension. The left image shows this directly and you can see the horizontal sinusoidal nature of the reflection intensity with light frequency, naturally this sinusoidal spectral intensity will be seen as a colour of hue that varies with the light frequency (relative to coherence width), on the right this is depicted... one can think of the x axis as now representing an increase in the coherence width (more coherent light).

We can also choose to ignore the colour bias from view angle and just display the continuous view angle (x axis) against increasing light frequency (downwards) for five dimensions from roughly 1 to 2.
Notice that as the dimension increases it tends towards two vertical bars (the separation or view angle difference, increasing with dimension). These bars represent the increasingly flat (high reflectance) sides of the Koch curve that becomes a triangle at dimension 2. Intermediate dimensions show speckled patterns that cause both glimmering and colours. Interestingly these appear quite fractal-like in themselves, probably a polar plot would be less distorted.

All the above were for a single Koch curve patch over the coherence width, which in reality is usually very small. It remains to consider what the macroscopic fractal will look like. We must apply the same interference for all pixels along the width of the macroscopic fractal:

Since we can't limit to integer view angles, we choose a different means to avoid colour biasing due to the finite coherent width (which we make about 2 pixel widths), firstly we weight the light contributions to ramp down at both sides of the light beam (a parabola, see bottom of figure below), secondly we make the higher wavelength light have a proportionally higher coherence width, as shown in the figure below.

Below we show such a fractal lit directly head on (left) and lit one radian from the left side (right). for increasing coherence width (downwards) from 1 pixel to 8 pixels. Each column is increasing dimension from 1 (top).

The result is that the coherence width makes almost no difference to the colour of the fractal. As expected the fractal is more blurry with a larger width and for very small width (hardly any coherence) the colour tends to white. Average colours are shown down the right hand line, and you can see they are very consistent. One can also see that the fractal colour changes greatly with dimension, and varies a little across the length of the fractal.
Above is the average over 20 light angles, so for an ambient white sky. The colour is much less pronounced however you can still see a definite change in the hue with increasing dimension, and the colour strength increases with higher dimension, though the fractal also becomes darker.

Given that the coherence width makes little difference, what if we use a fixed width (say 2 pixels) and increased the scale of the fractal? here's what happens for a point light source, head on (left) and 1 radian from the left side (right):

In both cases we see a hue cycling with curve scale (y axis) and an increase in the cycle density with increasing dimension (lower rows). This matches the result from the first section of this post, where blue vs red tinted Koch curves toggle as the iteration order increments (equivalent to increasing size). The above is just more realistic as it has a more correct frequency ratio between blue and red light (rather than 2) and it includes green light properly.

The ambient white sky (above) also shows this hue cycling, but the colour is more grey, particularly for low dimension curves.

We can also copy this method for the other fractals:
Levy convex (left) and concave (right):

Dragon (left) and random (right):

Here's a spinning Koch snowflake which combines ambient light with a point light source from the right hand side:

and here it is without the point light, so just directional light. Notice that the vertical spectrum flips every 30 degrees, so browns become purple/blue and visa versa. This exactly matches the observation in methods 1 and 2 in the first section of such a flip when viewing the curve from inside compared to outside. This is because a 30 degree turn is equivalent to seeing the curve from the opposite direction. This is a very interesting property of the Koch curve.

and finally, here's another attempt with a wider spot size for a large scale Koch snowflake with a stronger point light, it shows the much more dramatic colouring you get from coherent light sources:
By comparison, here are the gifs for the levy curve and dragon curve respectively, just ambient and lit, click for larger versions:
dragon curve:

#### Conclusions for Coherence Approach

• The first three diagrams seem to confirm the previous general conclusion that a red-shift seems to be the average shift for a Koch curve as well as a random curve.
• The idea that the Koch curve hue cycles with its scale is consistent in all the above examples.
• colour is more prominent as the fractal dimension increases
• colour is more prominent on single point light sources, and less on more spread out light sources.
• In all cases, the hue varies more with curve scale (where it fully cycles) and with increasing dimension, and less so along the length of the Koch curve.
• The last figure shows that colours are stronger in the hollows... this is because the incident light angle range is less, so it is closer to the point light source case. This is consistent with the first section where the concave Levy curve shows stronger colour than the convex one.

## Overall Conclusion

The three versions of light dynamics suggest the following strongly:
1. coloration increases with curve dimension but brightness decreases
2. coloration increases (but brightness decreases) with decreasing reflectivity
3. most fractals of moderate dimension will be quite dark compared to smooth surfaces, so coloration is most likely visible under strong light
4. coloration increases with more pointlike light sources, but is still noticeable for ambient white light. Therefore coloration is stronger in concave areas.
5. coloration is not really effected by coherence width (how wide the area where interference occurs), only reduces for very small width.
6. hue cycles with scale of the Koch curve  (first sections suggest it doesn't really do this for Levy curves)
The code for the latter images is available at: https://github.com/TGlad/FractalColour2D

I'll finish with some more well known fractal curves, now in colour:
Minkowski sausage:
Minkowski mushroom: (I made up the name):
Vicsek fractal: