Skip to content

Instantly share code, notes, and snippets.

@gorayni
gorayni / project.py
Created September 27, 2021 22:24
Isometric projection of images
#!/usr/bin/env python
from argparse import ArgumentParser
from pathlib import Path
import cv2
import numpy as np
from PIL import Image
def project(angle, mirror, img):
@gorayni
gorayni / bin_packing_first_fit_decreasing_algorithm.py
Created March 8, 2019 20:42
Bin packing problem - First Fit Decreasing Algorithm
import numpy as np
from __future__ import division
from collections import namedtuple
class ObjectWrapper(object):
def __init__(self, obj, weight_call):
self.obj = obj
self.weight_call = weight_call
@property
@gorayni
gorayni / largest_inscribed_isothetic_rectangle.py
Created August 9, 2017 19:56
Example of computing the largest inscribed isothetic rectangle. Originally presented by H. Alt, D. Hsu, and J. Snoeyink. Computing the largest inscribed isothetic rectangle. In Proc. 7th Canadian Conf. Comput. Geom., Universit'e Laval, Qu'ebec, August 1995, pp. 67--72. Based on the code by Daniel Sud.
from __future__ import division
import numpy as np
class Edge(object):
def __init__(self, p, q):
self.xmin = np.min((p[0], q[0]))
self.xmax = np.max((p[0], q[0]))
self.ymin = np.min((p[1], q[1]))
@gorayni
gorayni / Twiddle.py
Last active March 14, 2021 22:09
Twiddle algorithm by Phillip J Chase, `Algorithm 382: Combinations of M out of N Objects [G6]', Communications of the Association for Computing Machinery 13:6:368 (1970). Code based on Matthew Belmonte [http://www.netlib.no/netlib/toms/382].
import numpy as np
def twiddle(p, x=None, y=None, z=None):
j = np.argmax(p[1:]>0)+1
if p[j-1] == 0:
i = j-1
while i != 1:
p[i] = -1