Created
June 11, 2020 15:23
-
-
Save asahidari/48a09b76000dca35f89eb8613f158169 to your computer and use it in GitHub Desktop.
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
""" | |
in n1_dimension s d=2 n=2 | |
in n2_dimension s d=2 n=2 | |
in a_radian s d=0.4 n=2 | |
in x_dim s d=20 n=2 | |
in y_dim s d=20 n=2 | |
out verts v | |
out edges s | |
out faces s | |
""" | |
import cmath | |
import numpy as np | |
from math import sin, cos, sinh, cosh, pi | |
from mathutils import Vector | |
from animation_nodes.data_structures import Vector3DList, EdgeIndicesList, PolygonIndicesList | |
def calcZ1(x, y, k, n): | |
return cmath.exp(1j*(2*cmath.pi*k/n)) * (cmath.cosh(x+y*1j))**(2/n) | |
def calcZ2(x, y, k, n): | |
return cmath.exp(1j*(2*cmath.pi*k/n)) * (1 / 1j) * (cmath.sinh(x+y*1j))**(2/n) | |
def calcZ1Real(x, y, k, n): | |
return (calcZ1(x, y, k, n)).real | |
def calcZ2Real(x, y, k, n): | |
return (calcZ2(x, y, k, n)).real | |
def calcZ(x, y, k1_, k2_, n1_, n2_, a_): | |
z1 = calcZ1(x, y, k1, n1_) | |
z2 = calcZ2(x, y, k2, n2_) | |
return z1.imag * cos(a_) + z2.imag*sin(a_) | |
# x = np.linspace(0, pi/2, x_dim) | |
x = np.linspace(-1, 1, x_dim) | |
y = np.linspace(0, pi/2, y_dim) | |
x, y = np.meshgrid(x, y) | |
verts = Vector3DList() | |
edges = EdgeIndicesList() | |
edge_set = [] | |
faces = PolygonIndicesList() | |
face_set = [] | |
for i in range(n1*n2): | |
edge_set.append(set()) | |
face_set.append(set()) | |
count = 0 | |
for k1 in range(n1): | |
for k2 in range(n2): | |
# calc X, Y, Z values | |
X = np.frompyfunc(calcZ1Real, 4, 1)(x, y, k1, n1).astype('float32') | |
Y = np.frompyfunc(calcZ2Real, 4, 1)(x, y, k2, n2).astype('float32') | |
Z = np.frompyfunc(calcZ, 7, 1)(x, y, k1, k2, n1, n2, a_radian).astype('float32') | |
X_ = X.flatten() | |
Y_ = Y.flatten() | |
Z_ = Z.flatten() | |
v = [] | |
for x1, y1, z1 in zip(X_, Y_, Z_): | |
v.append(Vector((float(x1), float(y1), float(z1)))) | |
verts.extend(v) | |
for i in range(x_dim * y_dim): | |
y_index = i / y_dim | |
x_index = i % y_dim | |
j = i + count * x_dim * y_dim | |
if (y_index < y_dim - 1) and (x_index < x_dim - 1): | |
edge_set[count].add(tuple(sorted([j, j+y_dim]))) | |
edge_set[count].add(tuple(sorted([j+y_dim, j+y_dim+1]))) | |
edge_set[count].add(tuple(sorted([j+y_dim+1, j+1]))) | |
edge_set[count].add(tuple(sorted([j+1, j]))) | |
face_set[count].add(tuple(([j, j+y_dim, j+y_dim+1, j+1]))) | |
count += 1 | |
for i in range(n1*n2): | |
edges.extend(list(edge_set[i])) | |
faces.extend(list(face_set[i])) |
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
""" | |
in n1_dimension s d=2 n=2 | |
in n2_dimension s d=2 n=2 | |
in a_radian s d=0.4 n=2 | |
in x_dim s d=20 n=2 | |
in y_dim s d=20 n=2 | |
out verts v | |
out edges s | |
out faces s | |
""" | |
import cmath | |
import numpy as np | |
from math import sin, cos, sinh, cosh, pi | |
from mathutils import Vector | |
from animation_nodes.data_structures import Vector3DList, EdgeIndicesList, PolygonIndicesList | |
def calcZ1(x, y, k, n): | |
return cmath.exp(1j*(2*cmath.pi*k/n)) * (cmath.cosh(x+y*1j))**(2/n) | |
def calcZ2(x, y, k, n): | |
return cmath.exp(1j*(2*cmath.pi*k/n)) * (1 / 1j) * (cmath.sinh(x+y*1j))**(2/n) | |
def calcZ1Real(x, y, k, n): | |
return (calcZ1(x, y, k, n)).real | |
def calcZ2Real(x, y, k, n): | |
return (calcZ2(x, y, k, n)).real | |
def calcZ(x, y, k1_, k2_, n1_, n2_, a_): | |
z1 = calcZ1(x, y, k1, n1_) | |
z2 = calcZ2(x, y, k2, n2_) | |
return z1.imag * cos(a_) + z2.imag*sin(a_) | |
# x = np.linspace(0, pi/2, x_dim) | |
x = np.linspace(-1, 1, x_dim) | |
y = np.linspace(0, pi/2, y_dim) | |
x, y = np.meshgrid(x, y) | |
verts = Vector3DList() | |
edges = EdgeIndicesList() | |
edge_set = [] | |
faces = PolygonIndicesList() | |
face_set = [] | |
for i in range(n1*n2): | |
edge_set.append(set()) | |
face_set.append(set()) | |
count = 0 | |
for k1 in range(n1): | |
for k2 in range(n2): | |
# calc X, Y, Z values | |
X = np.frompyfunc(calcZ1Real, 4, 1)(x, y, k1, n1).astype('float32') | |
Y = np.frompyfunc(calcZ2Real, 4, 1)(x, y, k2, n2).astype('float32') | |
Z = np.frompyfunc(calcZ, 7, 1)(x, y, k1, k2, n1, n2, a_radian).astype('float32') | |
X_ = X.flatten() | |
Y_ = Y.flatten() | |
Z_ = Z.flatten() | |
v = [] | |
for x1, y1, z1 in zip(X_, Y_, Z_): | |
v.append(Vector((float(x1), float(y1), float(z1)))) | |
verts.extend(v) | |
for i in range(x_dim * y_dim): | |
y_index = i / y_dim | |
x_index = i % y_dim | |
j = i + count * x_dim * y_dim | |
if (y_index < y_dim - 1) and (x_index < x_dim - 1): | |
edge_set[count].add(tuple(sorted([j, j+y_dim]))) | |
edge_set[count].add(tuple(sorted([j+y_dim, j+y_dim+1]))) | |
edge_set[count].add(tuple(sorted([j+y_dim+1, j+1]))) | |
edge_set[count].add(tuple(sorted([j+1, j]))) | |
face_set[count].add(tuple(([j, j+y_dim, j+y_dim+1, j+1]))) | |
count += 1 | |
for i in range(n1*n2): | |
edges.extend(list(edge_set[i])) | |
faces.extend(list(face_set[i])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment