Skip to content

Instantly share code, notes, and snippets.

@pgtwitter
pgtwitter / AppDelegate.h
Last active November 29, 2024 06:04
Find the distance between any point and a Bézier curve (find the parameter t that is the closest point on the Bézier curve). reference: https://shikitenkai.blogspot.com/2024/11/bezier.html
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end
@pgtwitter
pgtwitter / .py
Created November 4, 2024 05:24
ポアンカレの円板(参考 https://qiita.com/hibit/items/5a49bedaa826fddf0a33 を 縦横比を1にしたもの)
# %%
# reference https://qiita.com/hibit/items/5a49bedaa826fddf0a33
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set(aspect=1)
theta = np.linspace(0, 2*np.pi, 100)
colorlist = ["r", "g", "b", "c", "m", "y"]
@pgtwitter
pgtwitter / .py
Last active October 14, 2024 02:45
greatest common divisor
# %%
def gcd(a, b):
a, b = (a, b % a) if a < b else (b, a % b)
return (a, b) if b == 0 else gcd(a, b)
gcd(3525, 4794)
@pgtwitter
pgtwitter / MyView.m
Created October 9, 2024 20:09
Circumscribed Circle
#import <Cocoa/Cocoa.h>
@interface MyView : NSView
@end
@implementation MyView
double len(NSPoint p){return sqrt(p.x*p.x+p.y*p.y);}
NSRect bboxOfCircumscribedCircle(NSPoint p0, NSPoint p1, NSPoint p2) {
double a= len(NSMakePoint(p2.x-p1.x, p2.y-p1.y));
double b= len(NSMakePoint(p2.x-p0.x, p2.y-p0.y));
double c= len(NSMakePoint(p1.x-p0.x, p1.y-p0.y));
double Ca=a*a*(b*b+c*c-a*a);
@pgtwitter
pgtwitter / a.sh
Last active September 23, 2024 04:01
"%b %d, %Y" to "%Y-%m-%d" using awk
#! /bin/sh
# reference: https://stackoverflow.com/questions/38262829/awk-command-to-convert-date-format-in-a-file#answer-38271260
/usr/bin/awk -F'\t' '{
split($1,a," ");
printf "%04d-%02d-%02d", a[3], (match("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC",toupper(a[1]))+2)/3, a[2];
for(i=2;i<=NF;i++)printf("\t%s",$i);
printf("\n")
}' << EOF
Sep 9, 2024 142.1234 143.1234 142.1234 142.1234 142.1234
Aug 8, 2024 146.1234 147.1234 145.1234 146.1234 146.1234
@pgtwitter
pgtwitter / a.ipynb
Created August 25, 2024 11:44
円周率1万桁の中に1から数えていって入っていない最初数は何か?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pgtwitter
pgtwitter / a.sh
Last active August 24, 2024 14:23
360mp4: Blender, Camera/Panoramic/Equirectangular, Stereoscopy/Multi-View. Views Format/Indivisual
#! /bin/sh -x
DIR=`pwd`
FPS=24
S_NUMBER=83
LOOP=10
STEREO="left-right" #"top-bottom"
DIST_PREFIX="dist"
SRC_DIR="360"
DIST_DIR=${DIR}
@pgtwitter
pgtwitter / a.ipynb
Created August 7, 2024 14:11
rendering network with networkx (extends Maze)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pgtwitter
pgtwitter / a.ipynb
Created August 7, 2024 01:48
rendering network with networkx
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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.