Created
August 30, 2020 09:02
-
-
Save hakanai/222f687ef394f7430517868b254dc1b6 to your computer and use it in GitHub Desktop.
Blender script to perform conformal mapping from unit square to unit circle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import bpy | |
import bmesh | |
from math import sqrt, floor | |
from bpy import context | |
from scipy.special import ellipj, ellipk | |
Kval = ellipk(0.5) # 1.8540746773013719 | |
def elliptical_map(x, y): | |
return x * sqrt(1.0 - y * y / 2.0), y * sqrt(1.0 - x * x / 2.0) | |
def cn(x, y): | |
"""Jacobi elliptical function cn with parameter 1/2, valid for complex numbers.""" | |
snx, cnx, dnx, phx = ellipj(x, 1 / 2) | |
sny, cny, dny, phy = ellipj(y, 1 / 2) | |
numer = cnx * cny - 1j * snx * dnx * sny * dny | |
denom = (1 - dnx ** 2 * sny ** 2) | |
return numer / denom | |
def conformal_map(x, y): | |
x1 = x / 2 - y / 2 | |
y1 = x / 2 + y / 2 | |
w = cn(Kval * (1 - x1), -Kval * y1) | |
u = (w.real + w.imag) / sqrt(2) | |
v = (-w.real + w.imag) / sqrt(2) | |
return u, v | |
collection = context.collection | |
ob = context.object | |
me = ob.data | |
sk = ob.shape_key_add(name = "Basis") | |
ci1 = ob.shape_key_add(name = "Elliptical") | |
ci2 = ob.shape_key_add(name = "Conformal") | |
for v in me.vertices: | |
ci1.data[v.index].co.xy = elliptical_map(*v.co.xy) | |
ci2.data[v.index].co.xy = conformal_map(*v.co.xy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment