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
def get_jacobian(func, X, h = 1e-7): | |
J = [] | |
for i in range(X.shape[0]): | |
Xp = X.astype(complex) | |
Xp[i] += h * 1j | |
J.append([numpy.imag(func(Xp))]) | |
J = numpy.concatenate(J, axis = 0) | |
J = numpy.transpose(J) | |
J /= h |
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
module bevel_rectangle(size, bevel) { | |
s = (size[0] + size[1] - 2 * bevel) / sqrt(2); | |
intersection() { | |
square(size, center = true); | |
rotate(45) | |
square([s, s], center = true); | |
} | |
} |
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 | |
def reverse_euclidean_distance_transform(F): | |
ret = numpy.empty_like(F, dtype = int) | |
def get_parabola_matrix(N): | |
X = numpy.arange(N, dtype = int) | |
G = numpy.empty((N, N), dtype = int) |
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 | |
def euclidean_distance_transform(F): | |
ret = numpy.empty_like(F, dtype = int) | |
def get_parabola_matrix(N): | |
X = numpy.arange(N, dtype = int) | |
G = numpy.empty((N, N), dtype = int) | |
G[:] = X | |
G -= X[:, None] |
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
10 FOR I=1 TO 27 | |
20 POKE #BB80+I*40,16 | |
30 POKE #BB81+I*40,I AND 7 | |
40 FOR J=0 TO 38 | |
50 POKE #BB82+I*40+J,126 | |
60 NEXT J | |
70 POKE #BB80+I*40+20,23 | |
80 NEXT 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
import numpy | |
def rot180_fft_2d(X, N): | |
I = numpy.repeat([numpy.arange(N)], N, axis = 0) | |
K = numpy.exp((2 * numpy.pi / N) * (I + I.T) * 1j) | |
return K * numpy.conj(X) | |
def rot180_rfft_2d(X, N): | |
I = numpy.repeat([numpy.arange(N)], N, axis = 0) | |
K = numpy.exp((2 * numpy.pi / N) * (I + I.T) * 1j)[:,:N // 2 + 1] |
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 | |
def axis_angle_to_rotation_matrix(U, theta): | |
cos_theta, sin_theta = numpy.cos(theta, dtype = U.dtype), numpy.sin(theta, dtype = U.dtype) | |
U_x = numpy.array([[0, -U[2], U[1]], [U[2], 0, -U[0]], [-U[1], U[0], 0]], dtype = U.dtype) | |
return cos_theta * numpy.identity(3, dtype = U.dtype) + sin_theta * U_x + (1 - cos_theta) * numpy.outer(U, U) |
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 itertools | |
from sympy.combinatorics import Permutation | |
def get_hexacosichoron_vertices(): | |
phi = (1 + 5 ** .5) / 2 | |
U = [.5 * phi, .5, .5 / phi] | |
permutation_list = [P for P in itertools.permutations(range(4)) if Permutation(P).is_even] | |
for i in range(16): |
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 | |
def sample_annulus(r1, r2, k): | |
theta = numpy.random.rand(k) | |
theta *= 2 * numpy.pi | |
R = numpy.sqrt(numpy.random.rand(k)) | |
R *= r2 - r1 | |
R += r1 | |
S = numpy.array([numpy.cos(theta), numpy.sin(theta)]).T | |
S *= R[:,None] |
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 | |
def quickhull_2d(S): | |
def process(P, a, b): | |
signed_dist = numpy.cross(S[P] - S[a], S[b] - S[a]) | |
K = [i for s, i in zip(signed_dist, P) if s > 0 and i != a and i != b] | |
if len(K) == 0: |