Skip to content

Instantly share code, notes, and snippets.

@pgtwitter
pgtwitter / a.ipynb
Last active July 21, 2024 06:39
半径0.5の外接円を持つ正n角形の周の長さ
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pgtwitter
pgtwitter / py.ipynb
Created July 20, 2024 06:45
Monte Carlo method
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# %%
import stanza
import graphviz as gv
# %%
# https://qiita.com/ytaki0801/items/b8d7d4c778fe98966ce5
def p_lex(p):
for s in '()[]{}",':
@pgtwitter
pgtwitter / py.ipynb
Last active June 10, 2024 02:24
モンテカルロ法的な積分 ( 参考 https://x.com/nichimath/status/1799033564094230546 )
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pgtwitter
pgtwitter / .py
Created June 5, 2024 09:12
Convex hull division using Fiedler vectors
# %%
import bpy
import networkx as nx # /path/to/blender's/python -m pip install scipy networkx
import numpy as np
from scipy.spatial import ConvexHull
def obj2GraphAndXyzAndNormFiedler(obj):
edges = [(e.vertices[0], e.vertices[1]) for e in obj.data.edges]
G = nx.Graph(edges)
@pgtwitter
pgtwitter / .py
Created June 2, 2024 06:48
Grayscale Using Fieldler Vector
# %%
import bpy
from sklearn.cluster import KMeans # /path/to/blender's/python -m pip install scikit-learn
import networkx as nx # /path/to/blender's/python -m pip install scipy networkx
obj = bpy.data.objects['Armadillo']
mesh = obj.data
edges = [(e.vertices[0], e.vertices[1]) for e in mesh.edges]
G = nx.Graph(edges)
S = [G.subgraph(c).copy() for c in nx.connected_components(G)]
G = S[0]
@pgtwitter
pgtwitter / .py
Created June 2, 2024 04:43
Grayscale Using Fieldler Vector
# %%
import bpy
import networkx as nx # /path/to/blender's/python -m pip install scipy networkx
obj = bpy.data.objects['Armadillo']
mesh = obj.data
edges = [(e.vertices[0], e.vertices[1]) for e in mesh.edges]
G = nx.Graph(edges)
S = [G.subgraph(c).copy() for c in nx.connected_components(G)]
fiedler_vector = nx.fiedler_vector(S[0])
minV = min(fiedler_vector)
@pgtwitter
pgtwitter / .py
Last active June 3, 2024 14:24
フィードラーベクトルの応用 ( bun_zipper.ply は https://graphics.stanford.edu/data/3Dscanrep/ から)
# %%
import open3d as o3d
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# %%
mesh = o3d.io.read_triangle_mesh("bun_zipper.ply")
coordinates = mesh.vertices
edges = []
@pgtwitter
pgtwitter / .py
Created May 29, 2024 14:31
matplotlibの画像を貼ったnodeを用いたgraphviz
# %%
import tempfile
import scipy.interpolate as scipl
import networkx as nx
import graphviz
import numpy as np
import matplotlib.pyplot as plt
es0 = [
[1, 4],
@pgtwitter
pgtwitter / a.java
Created May 28, 2024 02:43
Stream, Collectors
import java.util.List;
import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.Collections;
class a {
public static void main(String[] args) {
Integer[] array= new Integer[] {1, 2, 3, 4, 5};
List<Integer> list= Arrays.asList(array);
System.err.println("sum:"+list.stream().mapToInt(Integer::intValue).sum());