Skip to content

Instantly share code, notes, and snippets.

View jkulhanek's full-sized avatar

Jonáš Kulhánek jkulhanek

View GitHub Profile
@jkulhanek
jkulhanek / rotate_spherical_harmonics.py
Created January 15, 2025 23:04
Rotate spherical harmonics
def rotation_matrix_to_quaternion(R):
"""Convert input 3x3 rotation matrix to unit quaternion.
Assuming an orthogonal 3x3 matrix ℛ rotates a vector v such that
v' = ℛ * v,
we can also express this rotation in terms of a unit quaternion R such that
import*as e from"three";import{Ray as t,Plane as n,MathUtils as s,EventDispatcher as r,Vector3 as i,MOUSE as o,TOUCH as a,Quaternion as l,Spherical as c,Vector2 as h}from"three";class d{static idGen=0;constructor(e,t){let n,s;this.promise=new Promise(((e,t)=>{n=e,s=t}));const r=n.bind(this),i=s.bind(this);e(((...e)=>{r(...e)}).bind(this),(e=>{i(e)}).bind(this)),this.abortHandler=t,this.id=d.idGen++}then(e){return new d(((t,n)=>{this.promise=this.promise.then(((...n)=>{const s=e(...n);s instanceof Promise||s instanceof d?s.then(((...e)=>{t(...e)})):t(s)})).catch((e=>{n(e)}))}),this.abortHandler)}catch(e){return new d((t=>{this.promise=this.promise.then(((...e)=>{t(...e)})).catch(e)}),this.abortHandler)}abort(e){this.abortHandler&&this.abortHandler(e)}}class p extends Error{constructor(e){super(e)}}!function(){const e=new Float32Array(1),t=new Int32Array(e.buffer)}();const u=function(){const e=new Float32Array(1),t=new Int32Array(e.buffer);return function(n){return e[0]=n,t[0]}}(),m=function(e,t,n=!0){const s=n
@jkulhanek
jkulhanek / jupyter-run.py
Created November 3, 2023 14:33
jupyter-run
#!/usr/bin/env python
import os
import sys
import nbformat
import nbformat.sign
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert.preprocessors.execute import CellExecutionError
import warnings
STDIO_CODE = u'''
@jkulhanek
jkulhanek / export-latex.py
Last active October 31, 2024 12:49
Simplify LaTeX project by removing unused files and comment and downscale and crop images.
#!/usr/bin/env python
"""
This tool simplifies a LaTeX project by removing unused files and removing comments.
It also merges tex files into a single file and optionally crops and downscales images
to reduce the size of the output. It is useful when you want to prepare an ArXiv submission.
Usage:
export-latex.py <path> <output> [options]
Arguments:
@jkulhanek
jkulhanek / polygon2sdf.py
Created August 3, 2022 17:02
Numpy computing 2D SDF function of a polygon
import numpy as np
def compute_sdf_polygon(vertices, points):
vertices = vertices[:, None, ...]
points = points[None, :, ...]
d = np.sum((points[0] - vertices[0]) * (points[0] - vertices[0]), -1)
vert_offset = np.concatenate([vertices[-1:], vertices[:-1]], 0)
e = vert_offset - vertices
w = points - vertices
b = w - e * np.clip(np.sum(w * e, -1) / np.sum(e * e, -1), 0., 1.)[..., None]