Mathematically, a "distance" is a quantity that obeys certain rules. If d(z) is a distance function, then:
d(z) = sqrt(x*x + y*y), or (x^2 + y^2) ^ (1/2).
This can be generalized by changing the exponent (2 above):
d(z) = (|x|^n + |y|^n) ^ (1/n),
where n is at least 1. The vertical bars mean "absolute value", and are required to keep the x and y parts positive and real. Taking n = 1 gives d = |x| + |y|, the "taxicab" distance, so called because it measures how far you would travel in a taxicab in a city laid out on a rectangular grid. The various distance formulas are called, "metrics", and that's how they are chosen in this routine. The taxicab distance is listed as the "sum" metric in the formula.
Instead of adding |x| and |y|, they can be multiplied. The square root is taken, and this is called the "product" metric. Alternatively, either the minimum of the 2 components, or the maximum can be used. Oddly enough, these are the "minimum" and "maximum" metrics.
There are other ways of viewing geometry besides what Euclid laid down thousands of years ago. Each has its own way of measuring distance. Two of these "non-Euclidean" geometries are "elliptic" and "hyperbolic", and their metrics round out the 7. Elliptic geometry treats points as lying on the surface of a sphere. Hyperbolic takes them as lying inside a circle. In either case, a radius must be specified, which is the radius of the sphere or the circle, depending on the metric.
Be sure that the radius parameter is large enough with the elliptic and hyperbolic metrics. If it isn't, unpredictable things may happen. It should be at least as large as the bailout.
DistanceSample1 { ; copyright Kerry Mitchell 06feb00
;
; sample for "distance to a point" coloring
;
fractal:
title="Distance Sample 1" width=480 height=480 author="Kerry
Mitchell"
created="February 6, 2000" numlayers=2
layer:
method=multipass caption="sum" opacity=100 visible=yes alpha=no
mergemode=difference
mapping:
center=0/1.02 magn=5 angle=0
formula:
filename="Standard.ufm" entry="FastJulia" maxiter=1000 percheck=off
p_Seed=0.275/0 p_Bailout=1000
inside:
filename="lkm.ucl" entry="distance-point" transfer=none
repeat=yes
p_point=0/0 p_metric="Euclidean" p_colorby="minimum" p_power=2
p_r=4
outside:
filename="lkm.ucl" entry="distance-point" transfer=sqrt
repeat=yes
p_point=2/0 p_metric="sum" p_colorby="minimum" p_power=2
p_r=4
gradient:
smooth=yes numnodes=4 index=99 color=4298175 index=200 color=16777215
index=299 color=12544833 index=399 color=0
layer:
method=multipass caption="maximum" opacity=100 visible=yes
alpha=no
mergemode=difference
mapping:
center=0/1.02 magn=5 angle=0
formula:
filename="Standard.ufm" entry="FastJulia" maxiter=1000 percheck=off
p_Seed=0.275/0 p_Bailout=1000
inside:
filename="lkm.ucl" entry="distance-point" transfer=none
repeat=yes
p_point=0/0 p_metric="Euclidean" p_colorby="minimum" p_power=2
p_r=4
outside:
filename="lkm.ucl" entry="distance-point" transfer=sqr repeat=yes
p_point=2/0 p_metric="maximum" p_colorby="minimum" p_power=2
p_r=4
gradient:
smooth=yes numnodes=4 index=0 color=0 index=100 color=8421504
index=200
color=16777215 index=300 color=8421504
}
The next example uses the "elliptic" and "hyperbolic" metrics.
DistanceSample2 { ; copyright Kerry Mitchell 06feb00
;
; sample for "distance to a point" coloring
;
fractal:
title="Distance Sample 2" width=480 height=480 author="Kerry
Mitchell"
created="February 6, 2000" numlayers=2
layer:
method=multipass caption="hyperbolic" opacity=100 visible=yes
alpha=no
mergemode=difference
mapping:
center=0/0 magn=1 angle=0
formula:
filename="Standard.ufm" entry="FastJulia" maxiter=1000 percheck=off
p_Seed=0/1 p_Bailout=8
inside:
filename="lkm.ucl" entry="distance-point" transfer=none
repeat=yes
p_point=0/0 p_metric="Euclidean" p_colorby="minimum" p_power=2
p_r=4
outside:
filename="lkm.ucl" entry="distance-point" transfer=linear
repeat=yes
p_point=1/1 p_metric="hyperbolic" p_colorby="minimum" p_power=2
p_r=12
gradient:
smooth=yes numnodes=4 index=0 color=0 index=100 color=12544833
index=199
color=16777215 index=300 color=4298175
layer:
method=multipass caption="elliptic" opacity=100 visible=yes
alpha=no
mergemode=difference
mapping:
center=0/0 magn=1 angle=0
formula:
filename="Standard.ufm" entry="FastJulia" maxiter=1000 percheck=off
p_Seed=0/1 p_Bailout=8
inside:
filename="lkm.ucl" entry="distance-point" transfer=none
repeat=yes
p_point=0/0 p_metric="Euclidean" p_colorby="minimum" p_power=2
p_r=4
outside:
filename="lkm.ucl" entry="distance-point" transfer=linear
repeat=yes
p_point=-1/-1 p_metric="elliptic" p_colorby="minimum" p_power=2
p_r=12
gradient:
smooth=yes numnodes=4 index=0 color=0 index=100 color=12544833
index=199
color=16777215 index=300 color=4298175
}