Implementation of rotation by Mobius transformation

40 Views Asked by At

I've been stuck at implementing the rotation in the form of Mobius transformation (ie., $\frac{a z + b}{c z + d}$). Could somebody point me out where goes wrong??

import numpy as np
from numpy import exp, pi, linspace
import matplotlib.pyplot as plt
import seaborn as sns

sns_colors = sns.color_palette("Set1", 10)

def circle(radius, center):
    theta = linspace(0, 2 * pi, 200)
    return center + radius * exp(1j * theta)

def plot_curves(curves, sing_pt=None, fname="a.jpg"):
    for i, c in enumerate(curves):
        plt.plot(c.real, c.imag, color=sns_colors[i], label=f"{i}")
        plt.scatter(c.real[0], c.imag[0], color=sns_colors[i], marker="^")
        print(c.real[0], c.imag[0])
    if sing_pt is not None:
        plt.scatter(sing_pt.real, sing_pt.imag, color=sns_colors[i + 1], marker="s", label=f"Sing")
    plt.legend(loc="center left", bbox_to_anchor=(1, 0.5))
    plt.gca().set_aspect('equal')
    plt.savefig(fname)
    plt.clf()

def mobius(z, a, b, c, d):
    return (a * z + b)/(c * z + d)

# scale circles
circles = [circle(1, 0), circle(2, 0), circle(2, 6)]
plot_curves(circles, sing_pt=-4/3 + 0.0j, fname="circles.jpg")

# rotate by a degree in radian
_theta = np.radians(90)
a, b, c, d = np.cos(_theta), -np.sin(_theta), np.sin(_theta), np.cos(_theta)
plot_curves([mobius(c, a, 0, 0, 1) for c in circles], fname="circles-rotate.jpg")

# Tried but didn't work
# plot_curves([mobius(c, a, b, c, d) for c in circles], fname="circles-rotate.jpg")

Before transformation

Original circles

After

enter image description here

1

There are 1 best solutions below

0
On

Sorry, it was a simple mistake, I should've computed a as follows;

R = 1
a = R * np.exp(eval(f"{_theta}j"))

Result

enter image description here