Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/junkiexk.py
Last active May 8, 2020 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/1419b5cf066388c3dc57 to your computer and use it in GitHub Desktop.
Save zeffii/1419b5cf066388c3dc57 to your computer and use it in GitHub Desktop.
import numpy as np
import math
from math import fabs
def sv_main(contour_res=10, num_slices=1, scale=20):
in_sockets = [
['s', 'contour_res', contour_res],
['s', 'num_slices', num_slices],
['s', 'scale', scale]]
bbox = (-2.5, 2.5)
xmin, xmax, ymin, ymax, zmin, zmax = bbox * 3
A = np.linspace(xmin, xmax, contour_res) # resolution of the contour
B = np.linspace(xmin, xmax, num_slices) # number of slices
A1, A2 = np.meshgrid(A, A) # grid on which the contour is plotted
def goursat(x, y, z):
a, b, c = 0.0, -5.0, 11.8
return x**4+y**4+z**4+a*(x**2+y**2+z**2)**2+b*(x**2+y**2+z**2)+c
verts = []
fn = goursat
scale = max(scale, 1)
def add_slices(X, Y, Z, axis_pos, zdir):
for xyz in zip(X, Y, Z):
f = np.vstack(xyz).T
for v in f:
vec = v.tolist()
idx = {'z': 2, 'y': 1, 'x': 0}[zdir]
# vec[idx] = vec[idx]/scale
if fabs(vec[idx] - axis_pos) < 0.08:
verts.append(vec)
for z in B: # plot contours in the XY plane
X, Y = A1, A2
Z = fn(X, Y, z)
add_slices(X, Y, (Z+z), axis_pos=z, zdir='z')
for y in B: # plot contours in the XZ plane
X, Z = A1, A2
Y = fn(X, y, Z)
add_slices(X, (Y+y), Z, axis_pos=y, zdir='y')
for x in B: # plot contours in the YZ plane
Y, Z = A1, A2
X = fn(x, Y, Z)
add_slices((X+x), Y, Z, axis_pos=x, zdir='x')
# out boilerplate
out_sockets = [
['v', 'Vecs', [verts]],
]
return in_sockets, out_sockets
"""
in contour_res s d=10 n=2
in num_slices s d=1 n=2
in scale s d=20 n=2
out verts v
"""
import numpy as np
import math
from math import fabs
def sv_main(contour_res, num_slices, scale):
bbox = (-2.5, 2.5)
xmin, xmax, ymin, ymax, zmin, zmax = bbox * 3
A = np.linspace(xmin, xmax, contour_res) # resolution of the contour
B = np.linspace(xmin, xmax, num_slices) # number of slices
A1, A2 = np.meshgrid(A, A) # grid on which the contour is plotted
def goursat(x, y, z):
a, b, c = 0.0, -5.0, 11.8
return x**4+y**4+z**4+a*(x**2+y**2+z**2)**2+b*(x**2+y**2+z**2)+c
_verts = []
fn = goursat
scale = max(scale, 1)
def add_slices(X, Y, Z, axis_pos, zdir):
for xyz in zip(X, Y, Z):
f = np.vstack(xyz).T
for v in f:
vec = v.tolist()
idx = {'z': 2, 'y': 1, 'x': 0}[zdir]
# vec[idx] = vec[idx]/scale
if fabs(vec[idx] - axis_pos) < 0.08:
_verts.append(vec)
for z in B: # plot contours in the XY plane
X, Y = A1, A2
Z = fn(X, Y, z)
add_slices(X, Y, (Z+z), axis_pos=z, zdir='z')
for y in B: # plot contours in the XZ plane
X, Z = A1, A2
Y = fn(X, y, Z)
add_slices(X, (Y+y), Z, axis_pos=y, zdir='y')
for x in B: # plot contours in the YZ plane
Y, Z = A1, A2
X = fn(x, Y, Z)
add_slices((X+x), Y, Z, axis_pos=x, zdir='x')
return _verts
verts.append(sv_main(contour_res, num_slices, scale))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment