Skip to content

Instantly share code, notes, and snippets.

@detrin
Created April 11, 2020 20:25
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 detrin/d0bcf8a8b1024052ebd3e2e999358a3d to your computer and use it in GitHub Desktop.
Save detrin/d0bcf8a8b1024052ebd3e2e999358a3d to your computer and use it in GitHub Desktop.
import numpy as np
import math
from mayavi import mlab
mlab.clf()
x, y, z = np.mgrid[-3:3:50j, -3:3:50j, -3:3:50j]
# Plot a sphere of radius 1
values = x * x + y * y + z * z - np.sqrt(3)
mlab.contour3d(x, y, z, values, contours=20, colormap="jet", opacity=0.5)
mlab.axes()
# Plot a torus
R = 2
r = 1
values = (R - np.sqrt(x ** 2 + y ** 2)) ** 2 + z ** 2 - r ** 2
mlab.figure()
mlab.contour3d(x, y, z, values, contours=[0, 1], colormap="jet", opacity=0.5)
mlab.axes()
# Plot a Scherk's second surface
x, y, z = np.mgrid[-4:4:100j, -4:4:100j, -8:8:100j]
values = np.sin(z) - np.sinh(x) * np.sinh(y)
mlab.figure()
mlab.contour3d(x, y, z, values, contours=[0])
mlab.axes()
# Plot a Kuba-surface
x, y, z = np.mgrid[-2:2:100j, -2:2:100j, -2:2:100j]
A, B, C, E = 1, 1, 1, 1
def sqrt_mine(c):
if c < 0:
return -80 # solídne nekonečno
return np.sqrt(c)
values = np.zeros_like(x)
for i in range(x.shape[0]):
for j in range(x.shape[1]):
for k in range(x.shape[2]):
D = x[i, j, k] ** 2 + y[i, j, k] ** 2 + z[i, j, k] ** 2
value = (
A * D
+ B
* (
(y[i, j, k] ** 2 + z[i, j, k] ** 2) * (2 - D)
+ (x[i, j, k] * y[i, j, k]) ** 2
)
+ C * z[i, j, k] * sqrt_mine(2 - D)
- E
)
values[i, j, k] = value
mlab.figure()
mlab.contour3d(x, y, z, values, contours=[0], opacity=0.2)
mlab.axes()
mlab.show()
# see https://imgur.com/xAQBHA5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment