Skip to content

Instantly share code, notes, and snippets.

@asahidari
Created November 6, 2020 05:02
Show Gist options
  • Save asahidari/b4714563570e7ce1c27b1bb61b9a727d to your computer and use it in GitHub Desktop.
Save asahidari/b4714563570e7ce1c27b1bb61b9a727d to your computer and use it in GitHub Desktop.
"""
in p s
in q s
in t s
in verts v
out verts_out v
"""
import numpy as np
import math
from mathutils import Vector
from animation_nodes.data_structures import Vector3DList
cos_pt = math.cos(p*t)
sin_pt = math.sin(p*t)
cos_qt = math.cos(q*t)
sin_qt = math.sin(q*t)
verts_out = Vector3DList()
for v in verts:
x, y, z = v[0], v[1], v[2]
# reverse stereographically project to Riemann hypersphere
xb = 2 * x / (1 + x * x + y * y + z * z)
yb = 2 * y / (1 + x * x + y * y + z * z)
zb = 2 * z / (1 + x * x + y * y + z * z)
wb = (-1 + x * x + y * y + z * z) / (1 + x * x + y * y + z * z)
# now rotate the hypersphere (use p = q = 1 for isoclinic rotations)
# and vary t between 0 and 2*PI
xc = +xb * cos_pt + yb * sin_pt
yc = -xb * sin_pt + yb * cos_pt
# xc = xb
# yc = yb
zc = +zb * cos_qt - wb * sin_qt
wc = +zb * sin_qt + wb * cos_qt
# then project stereographically back to flat 3D
xd = xc / (1 - wc)
yd = yc / (1 - wc)
zd = zc / (1 - wc)
result = np.array([xd, yd, zd])
# verts_out0.append(Vector(result - np.array([x,y,z])))
verts_out.append(Vector(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment