The Conformal Mapping of A Circle Onto A Regular Polygon: Herbert E. M Uller, 2013

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

The conformal mapping of a circle onto a regular

polygon

Herbert E. Müller, 2013


http://herbert-mueller.info/

Abstract

In this article the Schwarz-Christoffel-transformation of the complex number


plane which maps the unit disc into a regular polygon is calculated. The disc and
polygon are both centered at 0, and close to the center, the mapping is the identity.
Then the inverse transformation, which is not of the same form, is calculated.
It can be used to distort a circular image into a polygonal image. The effect is
demonstrated on a drawing by M. C. Escher. A Matlab/Octave-program for this
kind of image distortion is given.

1 Introduction
Analytic functions map the plane of complex numbers onto itself. Such mappings are
conformal, or angle-preserving. Analytic functions are useful e.g. in two-dimensional po-
tential problems in electrostatics and fluid dynamics. A special class of analytic functions
are the Schwarz-Christoffel (SC) transformations. Such a transformation maps a circular
disc or half-plane into a polygonal region. In section 2 we calculate the SC transformation
mapping the unit disc into a regular polygon with K corners (K ≥ 2). In section 3 we
calculate the inverse transformation. In section 4 we use the latter formula to distort a
circular image into a regular polygonal image.

2 Mapping the unit disc onto a regular polygon


The general SC transformation S : w → z = S(w) maps a disc (or half-plane) D in the
w-plane onto a polygonal region E in the z-plane, and the circle (or straight line) ∂D
onto the polygon ∂E. The general formula is
Z
z = S(w) = A dw(w − w1 )−α1 /π (w − w2 )−α2 /π . . . (w − wK )−αK /π (2.1a)
K
X
w1 , w2 . . . wK ∈ ∂D 0 ≤ αk < π αk = 2π (2.1b)
k=1

The points wk lie on the circle ∂D. Their images are the polygon corners zk = S(wk ).
The exterior angle of two polygon sides joining in zk is αk .

1
Figure 1: Action of the Schwarz-Christoffel transformation. Here D is the upper halfplane
of C.

Let w = M (t) ≡ (at + b)/(ct + d) be a Möbius transformation (which is a SC transforma-


tion with K = 1 and α1 /π = 2). Then the combined transformation z = S̃(t) ≡ S ◦ M (t)
is again a SC transformation, i.e.
Z
z = S̃(t) = Ã dt(t − t1 )−α1 /π (t − t2 )−α2 /π . . . (t − tK )−αK /π (2.2a)

tk = M −1 (wk ) t1 , t2 . . . tK ∈ ∂ D̃ D̃ = M −1 (D) (2.2b)

The form-invariance is easily shown by direct calculation. (But don’t jump to conclusions:
while Möbius transformations form a group, SC transformations don’t.)
In my textbook [1] D is the upper half plane =(w) ≥ 0 (see fig. 1). Möbius transfor-
mations map circles onto circles, so clearly a SC transformation can map any disc or
half-plane onto any polygonal region. Given a disc D in the w-plane and a polygonal
region E in the z-plane, the first problem is to find the locations of the wk on ∂D such
that they can be mapped onto zk by a SC transformation, and the second problem is to
perform the integration in (2.1a).
From now on, let D be the unit disc centered at 0 in the w-plane. Since wk = 0 is
excluded, we can write the general SC transformation (1) slightly differently:
Z −αk /π

w
z = S(w) = A + B dwΠK
1−
1 (2.3a)
0 wk
XK
wk = exp(iφk ) 0 ≤ αk < π αk = 2π (2.3b)
k=1

For w  1, the SC transformation reduces to : z ' A + Bw.


Consider now a polygonal region E in the z-plane. Are the parameter values A, B, φk , αk
of the SC-transformation (2.3) uniquely determined by the locations of the corners zk ?
No, they aren’t! If we are given a SC transformation mapping D onto E, we can always
combine it with a Möbius transformation M mapping the unit circle D onto itself. Such
a transformation looks like this:
t+b
M : t → w = exp iθ (2.4)
b̄t + 1

2
The new SC transformation S̃ = S ◦ M still maps D on E, but has different values of
A, B, φk (the αk are unchanged).
The Möbius transformation (2.4) has three real parameters: θ, b0 , b00 . We can choose them
such that A = 0 and =(B) = 0, i.e. B = R, a positive real number. The general SC
transformation is then
Z  −αk /π
K w
z = S(w) = R dwΠ1 1 − (2.5a)
0 wk
XK
wk = exp(iφk ) 0 ≤ αk < π αk = 2π (2.5b)
k=1

For w  1, z ' Rw, ie. w = 0 is mapped onto z = 0, which must be an inside point
of E, and the surrounding of w = 0 is dilated or contracted, but not rotated. Now the
2K parameters R, α1 . . . αK−1 , φ1 . . . φK are uniquely determined by the 2K coordinates
of the polygon corners z1 . . . zK .
From now on let E be a regular polygonal region centered at 0. The exterior angles of
the regular K-gon ∂E are
αk = 2π/K (2.6)
and the polygon corners are at azimuths

φk = β + 2πk/K (2.7)

with 0 ≤ k ≤ K − 1. We can choose the angle β of the “zeroth” corner freely. From
symmetry we expect that the mapping of D onto E can be achieved with the points
wk = S −1 (zk ) at the same azimuths as the polygon corners zk , ie.

wk = exp i(β + 2πk/K) (2.8)

Inserting the wk of (2.8) into (2.5a) and evaluating the product we obtain a surprisingly
simple formula: Z
−2/K
z = R dw 1 − wK exp(−iKβ)

(2.9)
0

Substituting first s = w exp(−iβ) and then t = sK , we obtain


Z w exp(−iβ)
−2/K
z = R exp(iβ) ds 1 − sK (2.10a)
0
Z (w exp(−iβ))K
R
z= exp(iβ) dtt1/K−1 (1 − t)−2/K (2.10b)
K 0

Eqn. (2.10b) contains the incomplete beta function B(z; p, q), see [1]:
 
R K 1 2
z= exp(iβ)B (w exp(−iβ)) ; , 1 − (2.11)
K K K
with Z z
B(z; p, q) = dttp−1 (1 − t)q−1 (2.12)
0

3
One must be careful with eqn. (2.11) because the integration variable t in eqn. (2.10b)
passes through more than one Riemann leaf unless β − π/K < arg(w) ≤ β + π/K.
For the limiting case K = 2 of the “Digon”, eqn. (2.11) becomes

z = R exp(i2β) · artanh(w exp(−iβ)) (2.13)

For general K, the Taylor series of (2.11) is


∞ 
n − 1 + 2/K (w exp(−iβ))nK
X 
z = Rw (2.14)
n=0
n 1 + nK

Setting w = wk = exp i(β + 2πk/K) in eqn. (2.11), we obtain the polygon corners
   −1
R 1 2 −1/K
zk = B ,1 − exp i(β + 2πk/K) = R exp i(β + 2πk/K) (2.15)
K K K 1/K

B(p, q) in the middle is the (complete) beta function, the large parenthesis on the right
is the binomial coefficient ”−1/K choose 1/K”.
In fig. 2, a set of concentric circles in the unit disc is transformed onto the regular
polygons K = 2 − 6 using the series (2.14).

Figure 2: Mapping of the unit disc onto a regular polygon with Schwarz-Christoffel. The
original concentric circles are at the radii 5/15, 9/15, 12/15, 14/15, 15/15.

3 Inversion
In this section we set set for simplicity R = 1.
Let’s first settle the limiting case K = 2 of the “Digon”: the inverse transformation
is
w = exp(iβ)tanh(z exp(−2βi)) (3.1)

Now we attack the more difficult cases K ≥ 3. SC transformations do not form a group,
so the inverse transformation is in general not a SC transformation. Eqn. (2.14) with
R = 1 has the form

z = wf (wK ) = w(1 + a1 wK + a2 w2K + . . .) (3.2)

4
We want the inverse series of the form w = zg(z K ) = z(1 + b1 z K + b2 z 2K + . . .). The
inversion formula is (see [1] p. 367)

X z mK
w=z D0mK [f (wK )]−mK−1 (3.3)
m=0
(mK + 1)!

Here D0l means “derive l times and then set w = 0”. For a “normal” Taylor series
we would set K = 1. But the case K = 2 occurs actually quite often, e.g. in the
trigonometric functions sin(z) and tan(z), and the case K ≥ 3 occurs in our formula
(2.14), so an inversion formula with general K is useful. Evaluating eqn.s (3.2), (3.3)
gives

w = z[1 − a1 z K + (−a2 + (K + 1)a21 )z 2K . . .


+ (−a3 + (3K + 2)(a1 a2 − 21 (K + 1)a31 ))z 3K . . . (3.4)
+ (−a4 + (2K + 1)(2a1 a3 + a22 − (4K + 3)(a21 a2 − 13 (K + 1)a41 )))z 4K . . .]

In eqn. (2.14) we have


 
n − 1 + 2/K exp(−inKβ)
an = (3.5)
n 1 + nK

It is convenient to transfer the factor exp(−iKβ) to z K , ie. we write eqn.s (3.4), (3.5)
as
w = z[1 − a1 (z exp(−iβ))K + (−a2 + (K + 1)a21 )(z exp(−iβ))2K . . .
+ (−a3 + (3K + 2)(a1 a2 − 21 (K + 1)a31 ))(z exp(−iβ))3K . . .
(3.6)
+ (−a4 + (2K + 1)(2a1 a3 + a22 − (4K + 3)(a21 a2 − 31 (K + 1)a41 )))(z exp(−iβ))4K
−1
× 1 + (z exp(−iβ)/zmax )K ]

with  
n − 1 + 2/K 1
an = (3.7)
n 1 + nK
and
zmax = K −1 B(1/K, 1 − 2/K) (3.8)
The last factor in eqn. (3.6) needs an explanation. If you calculate the Taylor coefficients
b0 = 1, b1 = −a1 , b2 = (−a2 + (K + 1)a21 ), b3 = . . ., b4 = . . . in eqn. (3.6) for some K, you
−K
will find that the ratio bn+1 /bn approaches the value −zmax , ie. the series (2.14) becomes
more and more geometric. The factor in question incorporates this observation.
Numerical tests have shown that the precision of (3.6) is very good: the error is one or
two tenths of a percent at worst for all z within the polygon (in fact in the whole disc of
convergence with radius zmax ) and for all K ≥ 3.

4 Image distortion with complex functions


Complex functions z = f (w) can be used to distort digital images: pixels in the w-plane
are shifted to new positions in the z-plane. Given the SC transformation of the last

5
section, the idea is, to select a circular region in the image, and to distort it into a regular
polygonal region. I chose M. C. Escher’s drawing “circle limit IV” to demonstrate the
effect of the transformation. Escher’s drawing is already contained in a circle, and since
it has three-fold symmetry, the mappings into equilateral triangles and regular hexagons
give the nicest effect.

Figure 3: The drawing “circle-limit IV” by M. C. Escher distorted into regular triangles
and hexagons by means of the inverse Schwarz-Christoffel transformation (3.6). In the
triangle corners, the pixels of the original image can be seen.

6
A An alternative transformation formula
The series (2.14) converges badly if w is close to one of the wk . This can be seen in fig. 2:
the transformed unit circle was calculated summing approximately 1000 terms, and yet
the polygon corners are still slightly rounded off. To avoid this problem, we can set
Z w
−2/K
dw0 1 − w0K exp(−iKβ)

z = zk + R (A.1)
wk

Substituting t = (1 − w0K exp(−iKβ))/(1 − wK exp(−iKβ)), we obtain after some calcu-


lation
B(1 − wK exp(−iKβ); 1 − 2/K, 1/K)
 
z = zk 1 − (A.2)
B(1 − 2/K, 1/K)
The Taylor series of this formula is
" ∞   1+n−2/K #
1 X n − 1/K 1 − wK exp(−iKβ)
z = zk 1 − (A.3)
B(1 − 2/K, 1/K) n=0 n 1 + n − 2/K

The arguments of the series (2.14) and (A.3) are t = wK exp(−iKβ) and 1 − t. The discs
of convergence and recommended domains of application of both series are shown in fig.
4.

Figure 4: Discs of convergence of the series (2.14) (left) and (A.3) (right) in t =
wK exp(−iKβ), recommended domains where each series should be used.

B An Octave program for distorting digital images


I created fig. 3 using the free software package GNU Octave (version 3.6.4 for the operat-
ing system Windows) [2]. I gratefully acknowledge the excellent work of the Octave de-
velopment community. Octave is a Matlab clone and therefore Matlab compatible.
Here is the program I wrote. You can use it and distort your own pictures. Enjoy.

7
disp(’Distort a circular image excerpt into a polygonal shape.’);
disp([’The image must be square, the sides must have odd pixel size.’]);

% read original
s=input(’Type "imagename.ext": ’,’s’);
I=imread(s); % original
siz=size(I);
disp([’Image size = ’ int2str(siz)]);

if !(siz(1)==siz(2)) && (rem(siz(1),2)==1) % begin master loop


disp(’Height and width must be equal and odd. ’);
else

% original: W = complex coordinate, w = normalized coordinate


sizW=siz(1); % W size
R=(sizW-1)/2; % W radius
figure(1);clf;imshow(I);
hold on;deg=[2:2:360]/180*pi;
plot(1+R*(1+cos(deg)),1+R*(1+sin(deg)),’r.’);
title(’points at 2 degree intervals’);
K=input(’Number of polygon corners K = ’);
for h=0:K-1
plot(1+R*(1+[0 cos(2*pi*h/K)]),1+R*(1+[0 sin(2*pi*h/K)]),’r’,’linewidth’,1);
end
hh=’n’; while hh==’n’
bet=input([’Polygon rotation in degrees (within +-’ num2str(180/K) ’): ’]);
bet=-bet/180*pi;
clf;imshow(I);hold on;
plot(1+R*(1+cos(deg)),1+R*(1+sin(deg)),’r’,’linewidth’,2);
title(’points at 2 degree intervals’);
for h=0:K-1
phik=bet+2*pi*h/K;
plot(1+R*(1+[0 cos(phik)]),1+R*(1+[0 sin(phik)]),’r’,’linewidth’,1);
end
hh=input(’Figure 1: is the rotation angle okay? (y/n) ’,’s’);
end

% image: Z = complex coordinate, z = normalized coordinate


C=beta(1/K,1-2/K)/K; % abs(zk)
CR=ceil(C*R); % abs(Zk)
sizZ=1+2*CR; % Z size
Z=ones(sizZ,1)*[1:sizZ]+i*[1:sizZ]’*ones(1,sizZ);
z=(Z-(1+i)*(1+CR))/R;
rot=exp(i*bet);
zk=C*rot*exp(i*pi*2/K*[0:K]);
Zk=(1+i)*(1+CR)+R*zk; % corners
co=logical(length(siz)-2);
if co

8
fI=uint8(zeros(sizZ,sizZ,3)); % color image
else
fI=uint8(zeros(sizZ,sizZ)); %gray image
end

% points inside the Z-polygon


selZ=0;
for k=1:K
selZ=selZ+log((zk(k+1)-z)./(zk(k)-z))/(2*pi*i);
end
selZ=uint8(real(selZ));
inZ=find(selZ==1);

% inverse transformation: find W-pixels corresponding to Z-pixels


n=[1:4];
cn=bincoeff(n-1+2/K,n)./(1+n*K); %Series Coefficients
h=(z(inZ)/rot).^K;
w=z(inZ).*( 1-cn(1)*h+(-cn(2)+(K+1)*cn(1)^2)*h.^2+...
(-cn(3)+(3*K+2)*(cn(1)*cn(2)-(K+1)/2*cn(1)^3))*h.^3+...
(-cn(4)+(2*K+1)*(2*cn(1)*cn(3)+cn(2)^2-(4*K+3)*...
(cn(1)^2*cn(2)-(K+1)/3*cn(1)^4)))*h.^4+...
(-cn(5)+(5*K+2)*(cn(1)*cn(4)+cn(2)*cn(3)+(5*K+3)*...
(-.5*cn(1)^2*cn(3)-.5*cn(1)*cn(2)^2+(5*K+4)*...
(cn(1)^3*cn(2)/6-(K+1)*cn(1)^5/24))))*h^5./(1+h/C^K) );
W=R*w+(1+i)*(1+R);
U=uint16(real(W));V=uint16(imag(W));
U=max(U,1);U=min(U,sizW);V=max(V,1);V=min(V,sizW);
inW=sub2ind([sizW sizW],V,U);

% mapping
fI(inZ)=I(inW); % gray or red
if co
fI(inZ+sizZ^2)=I(inW+sizW^2); % green
fI(inZ+2*sizZ^2)=I(inW+2*sizW^2); %blue
end
figure(2);clf;
imshow(fI);hold on;
plot(real(Zk),imag(Zk),’r’,’linewidth’,1);hold off;

% save image
h=input(’Do you want to save the distorted picture as a png? (y/n) ’,’s’);
if strcmp(h,’y’)
imwrite( fI,[s(1:length(s)-4) ’K’ num2str(K) ’.png’] );
disp([’Distorted picture saved as "’ s(1:length(s)-4) ’K’ ...
num2str(K) ’.png".’]);
end

end % end master loop

9
References
[1] Arfken, G., Mathematical Methods for Physicists, 1970, Academic Press, New York,
2nd ed.
[2] GNU Octave, J. W. Eaton, D. Bateman & S. Hauberg, http://www.octave.org.

10

You might also like