Skip to content

Instantly share code, notes, and snippets.

@gagern
gagern / computation.sage
Created June 27, 2013 15:27
Formula to compute the locus of parabolas through three given points (ax,ay), (bx,by) and (cx,cy). See http://math.stackexchange.com/a/429858/35416
TO = TermOrder('wdeglex',(100, 10, 10, 1, 1, 1, 1, 1, 1))
PR1.<t, xx, yy, ax, ay, bx, by, cx, cy> = PolynomialRing(QQ, order=TO)
var('mu tau')
A = vector(PR1, [ax, ay, 1])
B = vector(PR1, [bx, by, 1])
C = vector(PR1, [cx, cy, 1])
D = vector(PR1, [1, t, 0])
E1 = A.cross_product(B).column() * C.cross_product(D).row()
E2 = A.cross_product(C).column() * B.cross_product(D).row()
F1 = E1 + E1.transpose()
@gagern
gagern / MX455687a.java
Created July 31, 2013 10:05
Find largest convex area within a given shape
/*
* Proof of concept for
* http://stackoverflow.com/a/17967201/1468366
* http://math.stackexchange.com/a/456233/35416
*
* Note: This code was written ONLY to get this single example image.
* It makes a number of implicit assumptions, and therefore won't be
* fit for general applications without some modifications.
* Furthermore, speedy coding was considered more important than
* performance at run time.
@gagern
gagern / MX461033.txt
Created August 7, 2013 02:22
Details on how the number in http://math.stackexchange.com/a/461338/35416 was obtained
sage: def angle_bisectors(g, h, p = None):
... if p is None:
... p = g.cross_product(h)
... a = (g[0]*h[1] + g[1]*h[0])
... b = 2*(g[0]*h[0] - g[1]*h[1])
... c = -a
... d = sqrt(b^2 - 4*a*c)
... r = [b + d, b - d]
... r = [vector(SR, [i, 2*a, 0]) for i in r]
... r = [i.cross_product(p) for i in r]
<?php
// This map would show Germany:
$south = deg2rad(50.6);
$north = deg2rad(50.8);
$west = deg2rad(7);
$east = deg2rad(7.25);
// This also controls the aspect ratio of the projection
$width = 100;
<?php
// This map would show Germany:
$south = deg2rad(47.2);
$north = deg2rad(55.2);
$west = deg2rad(5.8);
$east = deg2rad(15.2);
// This also controls the aspect ratio of the projection
$width = 1000;
failrun: fixrun
@echo ""
./a
FINDLIBPTHREAD=ldd c.so | awk '/libpthread.so/{print $$3}' | head -n1
fixrun: suceedrun
@echo ""
LD_PRELOAD='$(shell $(FINDLIBPTHREAD))' ./a
[[-268976423, -1041068828],
[287927556, -823085024],
[582279163, -505571674],
[819462839, -173345367],
[1052940007, 159999717],
[905221059, 588231118],
[594051833, 782699842],
[405217384, 822595358],
[94700867, 805634136],
[-175966121, 643525529],
@gagern
gagern / gist:8256742
Created January 4, 2014 15:55
Dump GPG packet data, public key in particular
import sys
import subprocess
import io
class PacketReader(object):
packetTagNames = {
0: 'Reserved - a packet tag MUST NOT have this value',
1: 'Public-Key Encrypted Session Key Packet',
2: 'Signature Packet',
@gagern
gagern / code.sage
Created February 21, 2014 14:47
Area of intersection between two circles in the hyperbolic plane
# See http://math.stackexchange.com/q/684834/35416 for details
var('a b x y r d')
var('R1', latex_name='R')
var('R2', latex_name="R'")
# The following two antiderivatives were found by Wolfram Alpha
upperArc(x) = -(b*arctan((b*x)/(sqrt(b^2-r^2)*sqrt(r^2-x^2))))/sqrt(b^2-r^2)+(b*arctan(x/sqrt(b^2-r^2)))/sqrt(b^2-r^2)+arctan(x/sqrt(r^2-x^2))
lowerArc(x) = (-sqrt(b^2-r^2)*arctan(x/sqrt(r^2-x^2))+b*arctan((b*x)/(sqrt(b^2-r^2)*sqrt(r^2-x^2)))+b*arctan(x/sqrt(b^2-r^2)))/sqrt(b^2-r^2)
y1 = cosh(R1)
r1 = sinh(R1)
y2 = (cosh(d)+sinh(d))*cosh(R2)
@gagern
gagern / Computation.sage
Last active August 29, 2015 13:56
Sage trouble related to a MSE question about ellipses
# This is an attempt to obtain numeric results for
# http://math.stackexchange.com/q/688861/35416
# but the computation is smbolic since I'll want a derivative later on
a = var('a', latex_name='\\alpha', domain='positive')
b = var('b', latex_name='\\beta', domain='positive')
a0 = RDF(0.14778)
b0 = RDF(0.77656)
SRmu.<mu> = SR[]
farpoint1 = vector([1, b, 0])