# How can I explicitly construct a *nice* conformal mapping from a triangle to a square in MATLAB?

I know the basics of the Riemann mapping theorem, SC maps, etc. I can look up formulae for the maps from the half-plane to a triangle or rectangle. But I want a particularly nice explicit map--easily implementable in MATLAB--from a triangle with horizontal base to a rectangle aligned with the coordinate axes.* In particular, I want each of the sides of the triangle to map exactly to a side of the rectangle, so that it "unfolds".

I have played with the Schwarz-Christoffel toolbox for MATLAB but after some effort have not been able to get the result I want. The closest I've been able to get is using the command sequence

L = 128;
ell = L/sqrt(12);
p1 = polygon([-L/2-i*ell,L/2-i*ell,i*2*ell]);
p2 = polygon(L/2*[-1-i,1-i,1+i,-1+i]);
f1 = stripmap(p1,[1,2])
f2 = stripmap(p2,[1,2])
f1i = inv(f1)
f2i = inv(f2)
fc = composite(f1i,f2)
n = 100;
s = linspace(-L/2,L/2,n);
t = linspace(-ell,2*ell,n);
[x,y] = meshgrid(s,t);
z = x+i*y;
z = z(find(isinpoly(z,p1)));
w = eval(fc,z);
figure;scatter(real(z),imag(z),5,1:length(z),'filled')
figure;scatter(real(w),imag(w),5,1:length(z),'filled')


...but this has a bizarre asymmetry that's presumably due to numerics, and (of much less concern) it's some nasty sort of involutionish thing away from how I want it. See below for the graphics. Most other variations I've tried have failed miserably.

*For convenience, we can take the triangle to be equilateral, but I really want a right triangle with shortest side aligned with the y-axis and length 1, and the next shortest side aligned with the x-axis and length 2.

-
is your asymmetry coming from t = linspace(-ell,2*ell,n);? This will give you a uniform vector centered around $\frac12 \textrm{ell}$, not $0$. – Emily Jan 22 '14 at 1:11
@Arkamis--I don't think so. That's just the y-limits of the equilateral triangle, which is centered at the origin. – S Huntsman Jan 22 '14 at 1:12
I should also note that I've seen mathfaculty.fullerton.edu/mathews/c2003/… and this (or similar maps) doesn't really solve my problem AFAIK. – S Huntsman Jan 22 '14 at 1:15
Actually, your triangle isn't symmetric about zero. You're going from $-\frac{L}{2}-i\textrm{ell}$ to $+\frac{L}{2}-i\textrm{ell}$. It should be $+ i\textrm{ell}$ in the second argument, if you want it to be equilateral. – Emily Jan 22 '14 at 1:21
Actually, I take that back, magnifying the image does show it to be mostly symmetric. It appears that the re-sized image has some skew on my browser. Weird... – Emily Jan 22 '14 at 1:33